File tree Expand file tree Collapse file tree
samples/truffle/interop/weather Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ```
2+ $ git clone https://github.com/lucasocon/openweather.git
3+ RUBYOPT='-I samples/truffle/interop/weather/openweather/lib -I samples/truffle/interop/weather' graalvm/bin/js samples/truffle/interop/weather/weather.js
4+ ```
5+
6+ The demo hangs after printing the temperature, as some Ruby service threads
7+ get stuck and aren't shutting down properly.
8+
9+ The Ruby ` temperature_in_city ` method has a ` this ` parameter which it wouldn't
10+ normally have, because JS passes ` this ` as the first argument.
Original file line number Diff line number Diff line change 1+ Interop . eval ( 'application/x-ruby' , 'require "weather"' ) ;
2+
3+ temperature_in_city = Interop . import ( 'temperature_in_city' )
4+
5+ console . log ( 'Temperature in New York now: ' + temperature_in_city ( 'New York' ) + '℃' ) ;
Original file line number Diff line number Diff line change 1+ require 'openweather2'
2+
3+ Openweather2 . configure do |config |
4+ # This is the endpoint and API key from the tests in the Openweather2 gem
5+ config . endpoint = 'http://api.openweathermap.org/data/2.5/weather'
6+ config . apikey = 'dd7073d18e3085d0300b6678615d904d'
7+ end
8+
9+ def temperature_in_city ( this , name )
10+ name = Truffle ::Interop . from_java_string ( name )
11+ weather = Openweather2 . get_weather ( city : name , units : 'metric' )
12+ weather . temperature
13+ end
14+
15+ Truffle ::Interop . export_method :temperature_in_city
You can’t perform that action at this time.
0 commit comments