open-weather-api 0.0.2 → 0.0.3

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: 65b0e18d84c87ea5d6bc9709a9a816e8d3255f95
4
- data.tar.gz: e875db9ab10e3106fdebfc71c167e5c59e9fb783
3
+ metadata.gz: c205d1489bacdd708f89abdb8ab9dcd5aa028b81
4
+ data.tar.gz: ffb9d41f9c4cf01aceef87625b88c95570b9e565
5
5
  SHA512:
6
- metadata.gz: 3a4b690505ec259f619696b0bbe217fcab3acb5972c9683fb101154aa248a5a75912b5be20828aff24c2d9f33cfd6fea12cf458597793235973dbcb84ad5d4eb
7
- data.tar.gz: c60e78f5eddd4aae49efe20392035c728de3731cb9d56f27d36982c08cc6caaafa9afbf1fab55fa3c3b0f1d15d48b716358a86949ca9dfa33be89edad287fa1b
6
+ metadata.gz: 79e8f94c2eff7064a2bbcea6958a313c6e9c652622782b0511ce4570894c1e5a236176aaeb7d5dc2dc42601f1cbcccf62681641110bc1151d803bac4e5f88983
7
+ data.tar.gz: 28475feb664172eee48796822d784879f822387df0c93fdda30933ea27f5516a8c81e8606ca6dfe51a4050bbc87cb3b6457a9b065eb634f793d78f8751a662cc
data/README.md CHANGED
@@ -31,15 +31,28 @@ First, you need to init the API:
31
31
  ```ruby
32
32
  # config/initializers/open-weather-api.rb
33
33
 
34
- Rails.configuration.open_weather_api = OpenWeatherAPI::API.new api_key: ENV['OPEN_WEATHER_API_KEY'], language: 'es', units: 'metric'
34
+ # Note that 'config' is an instance of `OpenWeatherAPI::API` (just name it as you like).
35
+ OpenWeatherAPI.configure do |config|
36
+ # API key
37
+ config.api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
38
+
39
+ # Optionals
40
+ config.default_language = 'es' # 'en' by default
41
+ config.default_country_code = 'es' # nil by default (ISO 3166-1 alfa2)
42
+ config.default_units = 'metric' # 'metric' by default
43
+ end
35
44
  ```
36
45
 
37
- `language`, `default_country_code` and `metrics` are optional values, with defaults `'en'`, `nil` and `'metric'`.
46
+ Outside of the configuration file, you can access the `api` object as follows:
47
+
48
+ ````ruby
49
+ Rails.configuration.open_weather_api
50
+ ````
38
51
 
39
52
  ### Other
40
53
 
41
54
  ```ruby
42
- open_weather_api = OpenWeatherAPI::API.new api_key: ENV['OPEN_WEATHER_API_KEY'], language: 'es', units: 'metric'
55
+ open_weather_api = OpenWeatherAPI::API.new api_key: ENV['OPEN_WEATHER_API_KEY'], default_language: 'es', default_units: 'metric', default_country_code: 'es'
43
56
  # ...
44
57
  ```
45
58
 
@@ -47,7 +60,7 @@ open_weather_api = OpenWeatherAPI::API.new api_key: ENV['OPEN_WEATHER_API_KEY'],
47
60
 
48
61
  Finally, you can use the different resources of the API:
49
62
 
50
- **NOTE**: You can add manually any parameter you need for each request.
63
+ **NOTE**: You can add manually any parameter you need for each request, and they will override the computed parameters.
51
64
 
52
65
  ### Current Weather
53
66
 
@@ -112,7 +125,7 @@ TODO.
112
125
  Retrieve icon url:
113
126
 
114
127
  ````ruby
115
- api.current city: 'Santa Cruz de Tenerife', country_code: 'es' do |json|
128
+ open_weather_api.current city: 'Santa Cruz de Tenerife', country_code: 'es' do |json|
116
129
  puts "Icon url: #{api.icon_url json['weather'].first['icon']}"
117
130
  end
118
131
  ````
@@ -10,4 +10,5 @@ require 'open-weather-api/resources/base'
10
10
  require 'open-weather-api/resources/current'
11
11
  require 'open-weather-api/resources/handlers/base'
12
12
  require 'open-weather-api/resources/handlers/current'
13
+ require 'open-weather-api/config'
13
14
  require 'open-weather-api/api'
@@ -1,15 +1,13 @@
1
1
  module OpenWeatherAPI
2
2
  class API
3
3
 
4
- attr_reader :api_key, :options
5
- attr_accessor :default_language, :default_country_code, :default_units
4
+ attr_accessor :api_key, :default_language, :default_country_code, :default_units
6
5
 
7
6
  def initialize(options = {})
8
- @options = options
9
7
  @api_key = options[:api_key] || options['api_key']
10
- @default_language = options[:language] || options['language'] || 'en'
8
+ @default_language = options[:default_language] || options['default_language'] || 'en'
11
9
  @default_country_code = options[:default_country_code] || options['default_country_code']
12
- @default_units = options[:units] || options['units'] || 'metric'
10
+ @default_units = options[:default_units] || options['default_units'] || 'metric'
13
11
  end
14
12
 
15
13
  def current(**args, &block)
@@ -0,0 +1,9 @@
1
+ module OpenWeatherAPI
2
+ def self.configure(&block)
3
+ raise ArgumentError, 'No block was given.' unless block
4
+
5
+ api = Rails.configuration.open_weather_api = OpenWeatherAPI::API.new
6
+ block.call(api)
7
+ api
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module OpenWeatherApi
2
- VERSION = "0.0.2"
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open-weather-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wikiti
@@ -38,6 +38,7 @@ files:
38
38
  - doc/icon.png
39
39
  - lib/open-weather-api.rb
40
40
  - lib/open-weather-api/api.rb
41
+ - lib/open-weather-api/config.rb
41
42
  - lib/open-weather-api/resources/base.rb
42
43
  - lib/open-weather-api/resources/current.rb
43
44
  - lib/open-weather-api/resources/handlers/base.rb