openweather2 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -13
- data/lib/openweather2/client.rb +16 -17
- data/lib/openweather2/version.rb +1 -1
- data/lib/openweather2/weather.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fddd1332e7154c5d5eda95b5bc712175097bb8f
|
4
|
+
data.tar.gz: af6e98be9abdb10d3d5b4eb515a262a0face63ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a49c9b561ddf976f44e84a3242c9b026fd6764116a0a4e771de7316c1e92fc494973ddbfb3809b98bbb4f515e865a6f7429147eec81d17913fe031420332fa1
|
7
|
+
data.tar.gz: e000004b3301cb9d93fc876e6f8c5db7db1ea387186de9bae43ad50970790b459b135c076573518df0a6467a21de4c67048576f1f519f9d86fb1ff2b0eca9fc0
|
data/README.md
CHANGED
@@ -41,6 +41,11 @@ Or install it yourself as:
|
|
41
41
|
|
42
42
|
Usage:
|
43
43
|
|
44
|
+
You can search the current weather on a location providing a hash with the following parameters:
|
45
|
+
* city
|
46
|
+
* lat, lon
|
47
|
+
* zip
|
48
|
+
|
44
49
|
```ruby
|
45
50
|
require "openweather2"
|
46
51
|
|
@@ -49,31 +54,35 @@ Openweather2.configure do |config|
|
|
49
54
|
config.apikey = YOUR APP ID
|
50
55
|
end
|
51
56
|
|
52
|
-
|
53
|
-
|
54
|
-
```
|
57
|
+
#Search by city
|
58
|
+
Openweather2.get_weather(city: 'london')
|
55
59
|
|
56
|
-
|
57
|
-
|
58
|
-
```ruby
|
60
|
+
#Search by coordinates
|
61
|
+
Openweather2.get_weather(lat: 35, lon: 139)
|
59
62
|
|
60
|
-
|
61
|
-
Openweather2.
|
63
|
+
#Search by ZIP code
|
64
|
+
Openweather2.get_weather(zip: 94040)
|
62
65
|
|
63
66
|
```
|
64
67
|
|
68
|
+
Also you can provide a parameter for the units to convert the temperature to 'metric' or 'imperial'
|
65
69
|
|
66
|
-
|
70
|
+
```ruby
|
67
71
|
|
68
|
-
|
72
|
+
Openweather2.get_weather(city: 'london', units: 'metric')
|
73
|
+
Openweather2.get_weather(city: 'london', units: 'imperial')
|
69
74
|
|
70
|
-
|
75
|
+
```
|
71
76
|
|
72
77
|
## Contributing
|
73
78
|
|
74
|
-
|
79
|
+
1. Fork it ( https://github.com/lucasocon/openweather )
|
80
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
81
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
82
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
83
|
+
5. Create a new Pull Request
|
75
84
|
|
76
|
-
|
85
|
+
Be free to report and send your pull request.
|
77
86
|
|
78
87
|
Contributors:
|
79
88
|
* Lucas Ocon (lucasocon)
|
data/lib/openweather2/client.rb
CHANGED
@@ -9,8 +9,7 @@ module Openweather2
|
|
9
9
|
end
|
10
10
|
|
11
11
|
class Configuration
|
12
|
-
attr_accessor :endpoint
|
13
|
-
attr_accessor :apikey
|
12
|
+
attr_accessor :endpoint, :apikey
|
14
13
|
end
|
15
14
|
|
16
15
|
class UnprocessableError < RuntimeError; end
|
@@ -24,15 +23,14 @@ module Openweather2
|
|
24
23
|
yield(configuration)
|
25
24
|
end
|
26
25
|
|
27
|
-
def
|
26
|
+
def get_weather(options={})
|
28
27
|
check_configuration!
|
29
|
-
uri
|
28
|
+
uri = set_params(options)
|
30
29
|
response = send_request(uri)
|
31
30
|
parse_json(response)
|
32
31
|
end
|
33
32
|
|
34
33
|
private
|
35
|
-
|
36
34
|
def parse_json(response)
|
37
35
|
case response
|
38
36
|
when Net::HTTPSuccess
|
@@ -44,15 +42,26 @@ module Openweather2
|
|
44
42
|
end
|
45
43
|
end
|
46
44
|
|
45
|
+
def check_response(response)
|
46
|
+
json = JSON.parse(response.body)
|
47
|
+
if json['cod'] == 200
|
48
|
+
Openweather2::Weather.new(json)
|
49
|
+
else
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
47
54
|
def send_request(uri)
|
48
55
|
req = Net::HTTP::Get.new(uri.request_uri)
|
49
56
|
http_params = [uri.hostname, uri.port, use_ssl: uri.scheme == 'https']
|
50
57
|
Net::HTTP.start(*http_params) {|http| http.request(req)}
|
51
58
|
end
|
52
59
|
|
53
|
-
def
|
60
|
+
def set_params(options)
|
54
61
|
uri = URI(Openweather2.configuration.endpoint)
|
55
|
-
uri.query = URI.encode_www_form(default_params.merge(
|
62
|
+
uri.query = URI.encode_www_form(default_params.merge(lat: options[:lat], lon: options[:lon], units: options[:units])) if options[:lat] && options[:lon]
|
63
|
+
uri.query = URI.encode_www_form(default_params.merge(zip: options[:zip], units: options[:units])) if options[:zip]
|
64
|
+
uri.query = URI.encode_www_form(default_params.merge(q: options[:city], units: options[:units])) if options[:city]
|
56
65
|
uri
|
57
66
|
end
|
58
67
|
|
@@ -62,17 +71,7 @@ module Openweather2
|
|
62
71
|
end
|
63
72
|
end
|
64
73
|
|
65
|
-
def check_response(response)
|
66
|
-
json = JSON.parse(response.body)
|
67
|
-
if json['cod'] == 200
|
68
|
-
Openweather2::Weather.new(json)
|
69
|
-
else
|
70
|
-
nil
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
74
|
def default_params
|
75
75
|
{APPID: Openweather2.configuration.apikey}
|
76
76
|
end
|
77
|
-
|
78
77
|
end
|
data/lib/openweather2/version.rb
CHANGED
data/lib/openweather2/weather.rb
CHANGED
@@ -2,7 +2,7 @@ module Openweather2
|
|
2
2
|
class Weather
|
3
3
|
|
4
4
|
attr_reader :city, :longitude, :latitude, :pressure, :humidity, :clouds,
|
5
|
-
:temperature, :min_temperature, :max_temperature, :wind_speed, :wind_angle
|
5
|
+
:temperature, :min_temperature, :max_temperature, :wind_speed, :wind_angle
|
6
6
|
|
7
7
|
def initialize(json)
|
8
8
|
@city = json['name']
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openweather2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Ocon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|