-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d56f9e
commit 79ee36f
Showing
14 changed files
with
170 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
|
||
require_relative 'endpoints/current' | ||
require_relative 'endpoints/one_call' | ||
require_relative 'endpoints/stations' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
module OpenWeather | ||
module Endpoints | ||
module Stations | ||
def register_station(options = {}) | ||
OpenWeather::Models::Station.new(post('stations', options)) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module OpenWeather | ||
module Models | ||
class Station < Model | ||
property 'id', from: 'ID' # internal identifier for the station | ||
property 'external_id' # external identifier for the station | ||
property 'name' # name of the station | ||
property 'latitude' # geographical coordinates of the location (latitude) | ||
property 'longitude' # geographical coordinates of the location (longitude) | ||
property 'altitude' # height of station above sea level | ||
property 'created_at' # timestamp when station was created | ||
property 'updated_at' # timestamp when station was updated | ||
property 'rank' # rank of station | ||
|
||
def register! | ||
data = OpenWeather::Client.new.register_station(to_h) | ||
update_attributes!(data) | ||
|
||
self | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe OpenWeather::Models::Station do | ||
include_context 'API client', endpoint: 'https://api.openweathermap.org/data/3.0' | ||
|
||
describe '.register!' do | ||
let(:create_attributes) do | ||
{ | ||
external_id: 'SF_TEST001', | ||
name: 'San Francisco Test Station', | ||
latitude: 37.76, | ||
longitude: -122.43, | ||
altitude: 150 | ||
} | ||
end | ||
|
||
before do | ||
allow(OpenWeather::Client).to receive(:new).and_return(client) | ||
end | ||
|
||
it 'registers a station via the Client', vcr: { cassette_name: 'stations/register_success' } do | ||
model = described_class.new(create_attributes) | ||
result = model.register! | ||
expect(result.object_id).to eq(model.object_id) | ||
expect(result).to have_attributes(create_attributes.merge(id: '5ed21a12cca8ce0001f1aef1')) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe 'stations' do | ||
include_context 'API client', endpoint: 'https://api.openweathermap.org/data/3.0' | ||
|
||
it 'registers a station', vcr: { cassette_name: 'stations/register_success' } do | ||
data = client.register_station( | ||
external_id: 'SF_TEST001', | ||
name: 'San Francisco Test Station', | ||
latitude: 37.76, | ||
longitude: -122.43, | ||
altitude: 150 | ||
) | ||
expect(data).to be_a(OpenWeather::Models::Station) | ||
expect(data).to have_attributes( | ||
id: '5ed21a12cca8ce0001f1aef1', | ||
external_id: 'SF_TEST001', | ||
name: 'San Francisco Test Station', | ||
latitude: 37.76, | ||
longitude: -122.43, | ||
altitude: 150 | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.shared_context 'API client', shared_context: :metadata do | ||
RSpec.shared_context 'API client', shared_context: :metadata do |params| | ||
before do | ||
OpenWeather::Config.reset | ||
OpenWeather::Config.endpoint = params[:endpoint] if params&.key?(:endpoint) | ||
end | ||
let(:client) { OpenWeather::Client.new(api_key: ENV['OPEN_WEATHER_API_KEY'] || 'api-key') } | ||
end |