Basic demonstration of how to access Weather Company Data and Netatmo API data using Ruby.
NOTE: This application requires that the following steps be performed on a Mac.
Clone the repo:
$ git clone https://github.com/tmarkiewicz/weather-ruby
$ cd weather-ruby
If not already installed, you'll need the bundler gem for this project.
- Install the Bundler Ruby gem.
Once bundler is installed, you can install the gems listed in the Gemfile
by running bundle install
$ gem install bundler
$ bundle install
The next step is to sign up for an account on IBM Cloud. Next, add the Weather Company Data as a new service, selecting the free plan.
Open the Weather Company Data service from the IBM Cloud dashboard. The credentials for the service can be found by selecting the Service Credentials
tab.
If no credentials exist, select the New Credential
button to create a new set of credentials.
In the .env
file, add the username
value to the WEATHER_COMPANY_USERNAME
key and password
value to the WEATHER_COMPANY_PASSWORD
.
WEATHER_COMPANY_USERNAME=your_username
WEATHER_COMPANY_PASSWORD=your_password
In the example file weather-company.rb
, you'll need to replace the latitude and longitude variables with your own.
A quick way to find the latitude and longitude from a location is LatLong.net
Once you have your latitude/longitude, enter them as follows in weather-company.rb
:
latitude = "40.014984"
longitude = "-105.270546"
Run the weather-company.rb
file from the command line:
$ ruby weather-company.rb
The output will look like this:
Forecast for Friday, February 22, 2019:
Periods of snow. Lows overnight in the upper teens.
1 to 3 inches of snow expected.
Snow this evening will give way to lingering snow showers late. Low 19F. Winds light and variable. Chance of snow 80%. Snow accumulating 1 to 3 inches.
The next step is to sign up for an account on IBM Cloud. Next, add the Weather Company Data as a new service, selecting the free plan.
From the Netatmo Connect developer portal, sign in with your regular Netatmo account credentials. Once signed in, click on the Create an App
button. After filling out the required info, click on save. Now that you have an app, click on its icon from the dashboard. Under the Technical Parameters section, you'll see your app's credentials.
In the .env
file, add the username
value to the USERNAME
key and password
value to the PASSWORD
. In addition, you'll need to add your CLIENT_ID
and CLIENT_SECRET
, all from Netatmo's developer site.
USERNAME=your_email
PASSWORD=your_password
CLIENT_ID=your_client_id
CLIENT_SECRET=your_client_secret
Run the netatmo.rb
file from the command line:
$ ruby netatmo.rb
The output will look like this:
Time: 2019-03-12 14:19:50 -0600
Temperature: 50 deg F
Humidity: 45%