open-weather-api 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/Gemfile +3 -0
- data/README.md +1 -1
- data/lib/open-weather-api/resources/base.rb +9 -7
- data/lib/open-weather-api/resources/current.rb +6 -6
- data/lib/open-weather-api/resources/handlers/base.rb +3 -2
- data/lib/open-weather-api/resources/handlers/current.rb +1 -1
- data/lib/open-weather-api/version.rb +2 -2
- data/open-weather-api.gemspec +4 -1
- data/rakefile +28 -0
- data/spec/current_weather_spec.rb +43 -0
- data/spec/spec_helper.rb +10 -0
- metadata +37 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82b4f646f8ec4c9b78170ef8ae612323828e46a4
|
4
|
+
data.tar.gz: 63205323ef368b5682d0222c1827bb7d308e3422
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c7cfb721767d05e059e40282982579f637829e7d78607b577a630f28889fd91551ba89933f52b9cf49b824354807f43a9681f56ee2eb9c4e17066610a941e5f
|
7
|
+
data.tar.gz: fa98ab5bd8d849332a1e0b6f3c0b831fdb52ac5ee5b8f6118624ff10567026d0c52e3503293d80124e0b7023882ebdc705456a8aa31bbbacdcea26b8b4e5b972
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/README.md
CHANGED
@@ -52,7 +52,7 @@ Rails.configuration.open_weather_api
|
|
52
52
|
### Other
|
53
53
|
|
54
54
|
```ruby
|
55
|
-
open_weather_api = OpenWeatherAPI::API.new api_key:
|
55
|
+
open_weather_api = OpenWeatherAPI::API.new api_key: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", default_language: 'es', default_units: 'metric', default_country_code: 'es'
|
56
56
|
# ...
|
57
57
|
```
|
58
58
|
|
@@ -12,21 +12,23 @@ module OpenWeatherAPI
|
|
12
12
|
@parameters = hash
|
13
13
|
setup_indifferent_access(@parameters)
|
14
14
|
|
15
|
-
|
15
|
+
# Let's use json
|
16
|
+
execute_json **hash, &block
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def execute_json(**hash, &block)
|
22
|
+
response = RestClient.send :get, base_url, params: build_params(@parameters), accept: :json
|
16
23
|
raise "Invalid response." unless response.code == 200
|
17
24
|
|
18
25
|
json = JSON.parse(response.body)
|
26
|
+
setup_indifferent_access(json)
|
19
27
|
|
20
28
|
return block.call(json) if block_given?
|
21
29
|
json
|
22
30
|
end
|
23
31
|
|
24
|
-
private
|
25
|
-
|
26
|
-
def request(type = :get)
|
27
|
-
RestClient.send type, base_url, params: build_params(@parameters), accept: :json
|
28
|
-
end
|
29
|
-
|
30
32
|
def base_url
|
31
33
|
'http://api.openweathermap.org/data/2.5/'
|
32
34
|
end
|
@@ -15,29 +15,29 @@ module OpenWeatherAPI
|
|
15
15
|
|
16
16
|
# Simple handlers
|
17
17
|
def city
|
18
|
-
City.new @parameters
|
18
|
+
City.new @api_obj, @parameters
|
19
19
|
end
|
20
20
|
|
21
21
|
def city_id
|
22
|
-
CityID.new @parameters
|
22
|
+
CityID.new @api_obj, @parameters
|
23
23
|
end
|
24
24
|
|
25
25
|
def geolocation
|
26
|
-
Geolocation.new @parameters
|
26
|
+
Geolocation.new @api_obj, @parameters
|
27
27
|
end
|
28
28
|
|
29
29
|
def zipcode
|
30
|
-
Zipcode.new @parameters
|
30
|
+
Zipcode.new @api_obj, @parameters
|
31
31
|
end
|
32
32
|
|
33
33
|
# Other handlers
|
34
34
|
# ------------------
|
35
35
|
def bbox
|
36
|
-
BoundingBox.new @parameters
|
36
|
+
BoundingBox.new @api_obj, @parameters
|
37
37
|
end
|
38
38
|
|
39
39
|
def circle
|
40
|
-
Circle.new @parameters
|
40
|
+
Circle.new @api_obj, @parameters
|
41
41
|
end
|
42
42
|
|
43
43
|
end
|
@@ -2,7 +2,8 @@ module OpenWeatherAPI
|
|
2
2
|
module Resources
|
3
3
|
|
4
4
|
class QueryHandler
|
5
|
-
def initialize(parameters = {})
|
5
|
+
def initialize(api_obj, parameters = {})
|
6
|
+
@api_obj = api_obj
|
6
7
|
@parameters = parameters
|
7
8
|
end
|
8
9
|
|
@@ -25,7 +26,7 @@ module OpenWeatherAPI
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def country_code
|
28
|
-
@parameters[:country_code] || @api_obj.default_country_code
|
29
|
+
@parameters[:country_code] || @parameters[:cc] || @api_obj.default_country_code
|
29
30
|
end
|
30
31
|
|
31
32
|
def cities_count
|
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = '0.0.
|
1
|
+
module OpenWeatherAPI
|
2
|
+
VERSION = '0.0.4'
|
3
3
|
end
|
data/open-weather-api.gemspec
CHANGED
@@ -5,7 +5,7 @@ require 'open-weather-api/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "open-weather-api"
|
8
|
-
spec.version =
|
8
|
+
spec.version = OpenWeatherAPI::VERSION
|
9
9
|
spec.authors = ["Wikiti"]
|
10
10
|
spec.email = ["wikiti.doghound@gmail.com"]
|
11
11
|
spec.summary = %q{Simple wrapper for Open Weather Map API}
|
@@ -19,4 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_runtime_dependency "rest-client", "~> 1.8"
|
22
|
+
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "fuubar"
|
22
25
|
end
|
data/rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Gemspec
|
2
|
+
load 'open-weather-api.gemspec'
|
3
|
+
|
4
|
+
# Dependencies
|
5
|
+
require 'open-weather-api'
|
6
|
+
require 'fileutils'
|
7
|
+
|
8
|
+
|
9
|
+
# Build
|
10
|
+
|
11
|
+
built_gem_file = "open-weather-api-#{OpenWeatherAPI::VERSION}.gem"
|
12
|
+
|
13
|
+
task :build do
|
14
|
+
# Build the gem
|
15
|
+
sh 'gem build open-weather-api.gemspec'
|
16
|
+
|
17
|
+
# Move it to /build
|
18
|
+
FileUtils.mv "#{built_gem_file}", "build/#{built_gem_file}", force: true
|
19
|
+
end
|
20
|
+
|
21
|
+
task publish: [:build] do
|
22
|
+
sh "gem push build/#{built_gem_file}"
|
23
|
+
end
|
24
|
+
|
25
|
+
# Test
|
26
|
+
task :test do
|
27
|
+
sh 'bundle exec rspec spec'
|
28
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OpenWeatherAPI::API do
|
4
|
+
describe 'When fetching current weather' do
|
5
|
+
let(:api) { OpenWeatherAPI::API.new( api_key: ENV['OPEN_WEATHER_API_KEY'], default_language: 'es', default_country_code: 'es' ) }
|
6
|
+
|
7
|
+
it 'should retrieve data by city name' do
|
8
|
+
expect(api.current(city: 'Santa Cruz de Tenerife')[:cod].to_i).to eq(200)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should retrieve data by city id' do
|
12
|
+
expect(api.current(id: 6360638)[:cod].to_i).to eq(200)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should retrieve data by cities ids' do
|
16
|
+
response = api.current(id: [6360638, 2511401])
|
17
|
+
expect(response[:cod].to_i).not_to be >= 400
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should retrieve data by geolocation' do
|
21
|
+
expect(api.current(lon: -16.20302, lat: 28.53924)[:cod].to_i).to eq(200)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should retrieve data by zipcode' do
|
25
|
+
expect(api.current(zipcode: 38190)[:cod].to_i).to eq(200)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should retrieve data by bounding box' do
|
29
|
+
expect(api.current(rectangle: { topleft: { lat: -16.3319, lon: 28.5046 }, bottomright: { lat: -16.1972, lon: 28.4400}, zoom: 10 })[:cod].to_i).to eq(200)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should retrieve data by circle' do
|
33
|
+
expect(api.current(circle: { lat: -16.3319, lon: 28.5046 }, cities_count: 2)[:cod].to_i).to eq(200)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'works with a given block' do
|
37
|
+
json1, json2 = nil
|
38
|
+
json1 = api.current(city: 'Santa Cruz de Tenerife') { |json| json2 = json }
|
39
|
+
|
40
|
+
expect(json1).to eq(json2)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: open-weather-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wikiti
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: fuubar
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
27
55
|
description: 'Simple wrapper for Open Weather Map API. The API description may be
|
28
56
|
found here: http://openweathermap.org/api'
|
29
57
|
email:
|
@@ -33,6 +61,8 @@ extensions: []
|
|
33
61
|
extra_rdoc_files: []
|
34
62
|
files:
|
35
63
|
- .gitignore
|
64
|
+
- .rspec
|
65
|
+
- Gemfile
|
36
66
|
- LICENSE.txt
|
37
67
|
- README.md
|
38
68
|
- doc/icon.png
|
@@ -45,6 +75,9 @@ files:
|
|
45
75
|
- lib/open-weather-api/resources/handlers/current.rb
|
46
76
|
- lib/open-weather-api/version.rb
|
47
77
|
- open-weather-api.gemspec
|
78
|
+
- rakefile
|
79
|
+
- spec/current_weather_spec.rb
|
80
|
+
- spec/spec_helper.rb
|
48
81
|
homepage: https://gitlab.com/wikiti-random-stuff/open-weather-api
|
49
82
|
licenses:
|
50
83
|
- MIT
|
@@ -69,5 +102,7 @@ rubygems_version: 2.0.14
|
|
69
102
|
signing_key:
|
70
103
|
specification_version: 4
|
71
104
|
summary: Simple wrapper for Open Weather Map API
|
72
|
-
test_files:
|
105
|
+
test_files:
|
106
|
+
- spec/current_weather_spec.rb
|
107
|
+
- spec/spec_helper.rb
|
73
108
|
has_rdoc:
|