open-weather-api 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,99 +1,99 @@
1
- module OpenWeatherAPI
2
- module Resources
3
- module Handlers
4
-
5
- class QueryHandler
6
- def initialize(api_obj, parameters = {})
7
- @api_obj = api_obj
8
- @parameters = parameters
9
- end
10
-
11
- def handle
12
- build if can?
13
- end
14
-
15
- def can?
16
- value != nil
17
- end
18
-
19
- private
20
-
21
- def value
22
- true
23
- end
24
-
25
- def build
26
- @parameters
27
- end
28
-
29
- def country_code
30
- @parameters[:country_code] || @parameters[:cc] || @api_obj.default_country_code
31
- end
32
-
33
- def cities_count
34
- @parameters[:count] || @parameters[:cnt] || @parameters[:cities_count]
35
- end
36
-
37
- def cluster
38
- @parameters[:cluster] if @parameters[:cluster].to_s == 'yes' || @parameters[:cluster].to_s == 'no'
39
- end
40
-
41
- def fill(hash)
42
- hash[:cnt] = cities_count if cities_count
43
- hash[:cluster] = cluster if cluster
44
-
45
- hash
46
- end
47
- end
48
-
49
- class City < QueryHandler
50
- private
51
-
52
- def build
53
- { q: [value, country_code].compact.flatten.join(',') }
54
- end
55
-
56
- def value
57
- @parameters[:city]
58
- end
59
- end
60
-
61
- class CityID < QueryHandler
62
- def multiple?
63
- value.is_a? Array
64
- end
65
-
66
- private
67
-
68
- def build
69
- { id: [value].flatten.compact.join(',') }
70
- end
71
-
72
- def value
73
- @parameters[:id] || @parameters[:city_id]
74
- end
75
- end
76
-
77
- class Geolocation < QueryHandler
78
- def can?
79
- latitude != nil && longitude != nil
80
- end
81
-
82
- private
83
-
84
- def build
85
- { lat: latitude, lon: longitude }
86
- end
87
-
88
- def latitude
89
- @parameters[:latitude] || @parameters[:lat]
90
- end
91
-
92
- def longitude
93
- @parameters[:longitude] || @parameters[:lon]
94
- end
95
- end
96
-
97
- end
98
- end
1
+ module OpenWeatherAPI
2
+ module Resources
3
+ module Handlers
4
+
5
+ class QueryHandler
6
+ def initialize(api_obj, parameters = {})
7
+ @api_obj = api_obj
8
+ @parameters = parameters
9
+ end
10
+
11
+ def handle
12
+ build if can?
13
+ end
14
+
15
+ def can?
16
+ value != nil
17
+ end
18
+
19
+ private
20
+
21
+ def value
22
+ true
23
+ end
24
+
25
+ def build
26
+ @parameters
27
+ end
28
+
29
+ def country_code
30
+ @parameters[:country_code] || @parameters[:cc] || @api_obj.default_country_code
31
+ end
32
+
33
+ def cities_count
34
+ @parameters[:count] || @parameters[:cnt] || @parameters[:cities_count]
35
+ end
36
+
37
+ def cluster
38
+ @parameters[:cluster] if @parameters[:cluster].to_s == 'yes' || @parameters[:cluster].to_s == 'no'
39
+ end
40
+
41
+ def fill(hash)
42
+ hash[:cnt] = cities_count if cities_count
43
+ hash[:cluster] = cluster if cluster
44
+
45
+ hash
46
+ end
47
+ end
48
+
49
+ class City < QueryHandler
50
+ private
51
+
52
+ def build
53
+ { q: [value, country_code].compact.flatten.join(',') }
54
+ end
55
+
56
+ def value
57
+ @parameters[:city]
58
+ end
59
+ end
60
+
61
+ class CityID < QueryHandler
62
+ def multiple?
63
+ value.is_a? Array
64
+ end
65
+
66
+ private
67
+
68
+ def build
69
+ { id: [value].flatten.compact.join(',') }
70
+ end
71
+
72
+ def value
73
+ @parameters[:id] || @parameters[:city_id]
74
+ end
75
+ end
76
+
77
+ class Geolocation < QueryHandler
78
+ def can?
79
+ latitude != nil && longitude != nil
80
+ end
81
+
82
+ private
83
+
84
+ def build
85
+ { lat: latitude, lon: longitude }
86
+ end
87
+
88
+ def latitude
89
+ @parameters[:latitude] || @parameters[:lat]
90
+ end
91
+
92
+ def longitude
93
+ @parameters[:longitude] || @parameters[:lon]
94
+ end
95
+ end
96
+
97
+ end
98
+ end
99
99
  end
@@ -1,55 +1,55 @@
1
- module OpenWeatherAPI
2
- module Resources
3
- module Handlers
4
-
5
- class Zipcode < QueryHandler
6
- private
7
-
8
- def build
9
- { zip: [value, country_code].compact.flatten.join(',') }
10
- end
11
-
12
- def value
13
- @parameters[:zipcode] || @parameters[:zip]
14
- end
15
- end
16
-
17
- class BoundingBox < QueryHandler
18
- private
19
-
20
- def topleft
21
- [ value[:topleft][:lat], value[:topleft][:lon] ].join(',')
22
- end
23
-
24
- def bottomright
25
- [ value[:bottomright][:lat], value[:bottomright][:lon] ].join(',')
26
- end
27
-
28
- def zoom
29
- value[:zoom] || value[:map_zoom] || 10
30
- end
31
-
32
- def value
33
- @parameters[:box] || @parameters[:box] || @parameters[:rect] || @parameters[:rectangle]
34
- end
35
-
36
- def build
37
- fill bbox: [topleft, bottomright, zoom].join(',')
38
- end
39
- end
40
-
41
- class Circle < QueryHandler
42
- private
43
-
44
- def value
45
- @parameters[:circle]
46
- end
47
-
48
- def build
49
- fill lat: value[:lat], lon: value[:lon]
50
- end
51
- end
52
-
53
- end
54
- end
1
+ module OpenWeatherAPI
2
+ module Resources
3
+ module Handlers
4
+
5
+ class Zipcode < QueryHandler
6
+ private
7
+
8
+ def build
9
+ { zip: [value, country_code].compact.flatten.join(',') }
10
+ end
11
+
12
+ def value
13
+ @parameters[:zipcode] || @parameters[:zip]
14
+ end
15
+ end
16
+
17
+ class BoundingBox < QueryHandler
18
+ private
19
+
20
+ def topleft
21
+ [ value[:topleft][:lat], value[:topleft][:lon] ].join(',')
22
+ end
23
+
24
+ def bottomright
25
+ [ value[:bottomright][:lat], value[:bottomright][:lon] ].join(',')
26
+ end
27
+
28
+ def zoom
29
+ value[:zoom] || value[:map_zoom] || 10
30
+ end
31
+
32
+ def value
33
+ @parameters[:box] || @parameters[:box] || @parameters[:rect] || @parameters[:rectangle]
34
+ end
35
+
36
+ def build
37
+ fill bbox: [topleft, bottomright, zoom].join(',')
38
+ end
39
+ end
40
+
41
+ class Circle < QueryHandler
42
+ private
43
+
44
+ def value
45
+ @parameters[:circle]
46
+ end
47
+
48
+ def build
49
+ fill lat: value[:lat], lon: value[:lon]
50
+ end
51
+ end
52
+
53
+ end
54
+ end
55
55
  end
@@ -1,15 +1,15 @@
1
- module OpenWeatherAPI
2
- module Resources
3
- class Raw < Base
4
-
5
- def execute(resource = '/', **args, &block)
6
- @resource = resource
7
- super(**args, &block)
8
- end
9
-
10
- def base_url
11
- return super + @resource
12
- end
13
- end
14
- end
1
+ module OpenWeatherAPI
2
+ module Resources
3
+ class Raw < Base
4
+
5
+ def execute(resource = '/', **args, &block)
6
+ @resource = resource
7
+ super(**args, &block)
8
+ end
9
+
10
+ def base_url
11
+ return super + @resource
12
+ end
13
+ end
14
+ end
15
15
  end
@@ -1,3 +1,3 @@
1
1
  module OpenWeatherAPI
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_runtime_dependency "rest-client", "~> 1.8"
21
+ spec.add_runtime_dependency "rest-client", "~> 2.0"
22
22
 
23
23
  spec.add_development_dependency "rspec"
24
24
  spec.add_development_dependency "fuubar"
data/rakefile CHANGED
@@ -1,28 +1,29 @@
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
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.mkdir_p "build/"
19
+ FileUtils.mv "#{built_gem_file}", "build/#{built_gem_file}", force: true
20
+ end
21
+
22
+ task publish: [:build] do
23
+ sh "gem push build/#{built_gem_file}"
24
+ end
25
+
26
+ # Test
27
+ task :test do
28
+ sh 'bundle exec rspec spec'
29
+ end
@@ -1,51 +1,51 @@
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
-
43
- it 'works with xml format' do
44
- expect(api.current(city: 'Santa Cruz de Tenerife', mode: :xml)).not_to be_nil
45
- end
46
-
47
- it 'works with html format' do
48
- expect(api.current(city: 'Santa Cruz de Tenerife', mode: :html)).not_to be_nil
49
- end
50
- end
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
+
43
+ it 'works with xml format' do
44
+ expect(api.current(city: 'Santa Cruz de Tenerife', mode: :xml)).not_to be_nil
45
+ end
46
+
47
+ it 'works with html format' do
48
+ expect(api.current(city: 'Santa Cruz de Tenerife', mode: :html)).not_to be_nil
49
+ end
50
+ end
51
51
  end