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 +4 -4
 - data/.travis.yml +8 -0
 - data/README.md +11 -1
 - data/lib/openweather2/client.rb +25 -18
 - data/lib/openweather2/version.rb +1 -1
 - metadata +2 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 159c652dc6409423e69f8f03349370ba4c57f7ac
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: e6ce5a96df0a6f8f90ceded6694b313eb41ae245
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 385f88c0ff9ad4f7481f15446e32aade179ebca69528f7132f6ec327aaa9735688743cce583d3dfebb1be916d8b2b33e0065e69c8c8f8f67f9425ec9d404a3ee
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 728e4f82522b0be04a013ee8cbd543b89666f17490d57b784c8296c24b2a6bd58f2e473df526c783b229ee761c5975e87c7c0f55393ed2c26f9d3f45d7526abc
         
     | 
    
        data/.travis.yml
    ADDED
    
    
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # Openweather2
         
     | 
| 
      
 1 
     | 
    
         
            +
            # Openweather2 [](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.
         
     | 
    
        data/lib/openweather2/client.rb
    CHANGED
    
    | 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require  
     | 
| 
       2 
     | 
    
         
            -
            require  
     | 
| 
       3 
     | 
    
         
            -
            require  
     | 
| 
      
 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 
     | 
    
         
            -
                 
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
                 
     | 
| 
       31 
     | 
    
         
            -
                 
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
      
 28 
     | 
    
         
            +
                check_configuration!
         
     | 
| 
      
 29 
     | 
    
         
            +
                uri      = set_request_params(city, units)
         
     | 
| 
      
 30 
     | 
    
         
            +
                response = send_request(uri)
         
     | 
| 
      
 31 
     | 
    
         
            +
                parse_json(response)
         
     | 
| 
      
 32 
     | 
    
         
            +
              end
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                res = Net::HTTP.start(*http_params) do |http|
         
     | 
| 
       36 
     | 
    
         
            -
                  http.request(req)
         
     | 
| 
       37 
     | 
    
         
            -
                end
         
     | 
| 
      
 34 
     | 
    
         
            +
              private
         
     | 
| 
       38 
35 
     | 
    
         | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
      
 36 
     | 
    
         
            +
              def parse_json(response)
         
     | 
| 
      
 37 
     | 
    
         
            +
                case response
         
     | 
| 
       40 
38 
     | 
    
         
             
                when Net::HTTPSuccess
         
     | 
| 
       41 
     | 
    
         
            -
                  json = JSON.parse( 
     | 
| 
      
 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 
     | 
    
         
            -
               
     | 
| 
      
 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  
     | 
| 
      
 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 
     | 
    
         
            -
                { 
     | 
| 
      
 67 
     | 
    
         
            +
                {APPID: Openweather2.configuration.apikey}
         
     | 
| 
       61 
68 
     | 
    
         
             
              end
         
     | 
| 
       62 
69 
     | 
    
         | 
| 
       63 
70 
     | 
    
         
             
            end
         
     | 
    
        data/lib/openweather2/version.rb
    CHANGED
    
    
    
        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. 
     | 
| 
      
 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
         
     |