openweather2 0.1.5 → 0.1.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 31795559ddff60a2dfc0755965c1449ce32342d8
4
- data.tar.gz: 8b7316544bf04460f8f61dfee9113f78165e130f
3
+ metadata.gz: 159c652dc6409423e69f8f03349370ba4c57f7ac
4
+ data.tar.gz: e6ce5a96df0a6f8f90ceded6694b313eb41ae245
5
5
  SHA512:
6
- metadata.gz: fd00fe93e63130132aa6d725b89d42e563445810ef49e242ef1c905ec0e2f1ead6b50129ab4e948f2856963f2d32206dcf0cb2d66289511aa096c2bc3a70a90b
7
- data.tar.gz: 0a5d198bf91a3bd9eb4744e5dda30f58a10815421f86092d4653b265b0fd3cf7b5c9ec6972ce52b9082c9d8516c8c61364fa35fa3c745ca28a79d2baec74d5c2
6
+ metadata.gz: 385f88c0ff9ad4f7481f15446e32aade179ebca69528f7132f6ec327aaa9735688743cce583d3dfebb1be916d8b2b33e0065e69c8c8f8f67f9425ec9d404a3ee
7
+ data.tar.gz: 728e4f82522b0be04a013ee8cbd543b89666f17490d57b784c8296c24b2a6bd58f2e473df526c783b229ee761c5975e87c7c0f55393ed2c26f9d3f45d7526abc
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.5
6
+ - 2.2.1
7
+
8
+ script: bundle exec rake test
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Openweather2
1
+ # Openweather2 [![Gem Version](https://badge.fury.io/rb/openweather2.svg)](http://badge.fury.io/rb/openweather2)
2
2
 
3
3
  This gem is an abstraction to the OpenWeatherMap API.
4
4
 
@@ -53,6 +53,16 @@ Openweather2.weather('london')
53
53
 
54
54
  ```
55
55
 
56
+ Also you can provide a second parameter for the units to convert the temperature to 'metric' or 'imperial'
57
+
58
+ ```ruby
59
+
60
+ Openweather2.weather('london', 'metric')
61
+ Openweather2.weather('london', 'imperial')
62
+
63
+ ```
64
+
65
+
56
66
  ## Development
57
67
 
58
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.
@@ -1,6 +1,6 @@
1
- require "uri"
2
- require "net/http"
3
- require "json"
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'json'
4
4
 
5
5
  module Openweather2
6
6
 
@@ -25,22 +25,19 @@ module Openweather2
25
25
  end
26
26
 
27
27
  def weather(city, units = nil)
28
- configure_required!
29
-
30
- uri = URI(Openweather2.configuration.endpoint)
31
- uri.query = URI.encode_www_form(default_params.merge(:q => city, :units => units))
32
- req = Net::HTTP::Get.new(uri.request_uri)
28
+ check_configuration!
29
+ uri = set_request_params(city, units)
30
+ response = send_request(uri)
31
+ parse_json(response)
32
+ end
33
33
 
34
- http_params = [uri.hostname, uri.port, use_ssl: uri.scheme == 'https']
35
- res = Net::HTTP.start(*http_params) do |http|
36
- http.request(req)
37
- end
34
+ private
38
35
 
39
- case res
36
+ def parse_json(response)
37
+ case response
40
38
  when Net::HTTPSuccess
41
- json = JSON.parse(res.body)
39
+ json = JSON.parse(response.body)
42
40
  Openweather2::Weather.new(json)
43
-
44
41
  when Net::HTTPUnprocessableEntity
45
42
  raise UnprocessableError, 'Bad URI param!'
46
43
  else
@@ -48,16 +45,26 @@ module Openweather2
48
45
  end
49
46
  end
50
47
 
51
- private
48
+ def send_request(uri)
49
+ req = Net::HTTP::Get.new(uri.request_uri)
50
+ http_params = [uri.hostname, uri.port, use_ssl: uri.scheme == 'https']
51
+ Net::HTTP.start(*http_params) {|http| http.request(req)}
52
+ end
53
+
54
+ def set_request_params(city, units)
55
+ uri = URI(Openweather2.configuration.endpoint)
56
+ uri.query = URI.encode_www_form(default_params.merge(q: city, units: units))
57
+ uri
58
+ end
52
59
 
53
- def configure_required!
60
+ def check_configuration!
54
61
  if Openweather2.configuration.instance_variables.size < 2
55
62
  raise ArgumentError, 'You must configure Openweather2'
56
63
  end
57
64
  end
58
65
 
59
66
  def default_params
60
- { APPID: Openweather2.configuration.apikey }
67
+ {APPID: Openweather2.configuration.apikey}
61
68
  end
62
69
 
63
70
  end
@@ -1,3 +1,3 @@
1
1
  module Openweather2
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openweather2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Ocon
@@ -74,6 +74,7 @@ extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
76
  - ".gitignore"
77
+ - ".travis.yml"
77
78
  - Gemfile
78
79
  - LICENSE.txt
79
80
  - README.md