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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c172988c1e35afbb0b9c3a5e9ab01715d7a608fb
4
- data.tar.gz: 955de0972fa726dfa9e4b6114a7ee26909c5dadb
3
+ metadata.gz: 2fddd1332e7154c5d5eda95b5bc712175097bb8f
4
+ data.tar.gz: af6e98be9abdb10d3d5b4eb515a262a0face63ee
5
5
  SHA512:
6
- metadata.gz: 2e88b7cc5a3df935288d8b88e663fecb34df9241dac2d016999a805d157ef5789c9fb7f6569cb5f15d4136fe7dc1c10a6689726fff82b56ff4b5466af048104e
7
- data.tar.gz: 789ac67f13d85e979894cbb1e9489af65bfd62d031f3e5d23fc1a770ed5bbbe4a12c081e1e4ab3cd9eea3961c98172d761340c2d116ed95c12d71784daad5833
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
- Openweather2.weather('london')
53
-
54
- ```
57
+ #Search by city
58
+ Openweather2.get_weather(city: 'london')
55
59
 
56
- Also you can provide a second parameter for the units to convert the temperature to 'metric' or 'imperial'
57
-
58
- ```ruby
60
+ #Search by coordinates
61
+ Openweather2.get_weather(lat: 35, lon: 139)
59
62
 
60
- Openweather2.weather('london', 'metric')
61
- Openweather2.weather('london', 'imperial')
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
- ## Development
70
+ ```ruby
67
71
 
68
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
72
+ Openweather2.get_weather(city: 'london', units: 'metric')
73
+ Openweather2.get_weather(city: 'london', units: 'imperial')
69
74
 
70
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
75
+ ```
71
76
 
72
77
  ## Contributing
73
78
 
74
- Be free to report and send your pull request.
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
- Bug reports and pull requests are welcome on GitHub at https://github.com/lucasocon/openweather.
85
+ Be free to report and send your pull request.
77
86
 
78
87
  Contributors:
79
88
  * Lucas Ocon (lucasocon)
@@ -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 weather(city, units = nil)
26
+ def get_weather(options={})
28
27
  check_configuration!
29
- uri = set_request_params(city, units)
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 set_request_params(city, units)
60
+ def set_params(options)
54
61
  uri = URI(Openweather2.configuration.endpoint)
55
- uri.query = URI.encode_www_form(default_params.merge(q: city, units: units))
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
@@ -1,3 +1,3 @@
1
1
  module Openweather2
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
@@ -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, :sunrise, :sunset
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.7
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-16 00:00:00.000000000 Z
11
+ date: 2015-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest