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 +4 -4
- data/README.md +18 -5
- data/lib/open-weather-api.rb +1 -0
- data/lib/open-weather-api/api.rb +3 -5
- data/lib/open-weather-api/config.rb +9 -0
- data/lib/open-weather-api/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: c205d1489bacdd708f89abdb8ab9dcd5aa028b81
|
4
|
+
data.tar.gz: ffb9d41f9c4cf01aceef87625b88c95570b9e565
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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'],
|
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
|
-
|
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
|
````
|
data/lib/open-weather-api.rb
CHANGED
@@ -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'
|
data/lib/open-weather-api/api.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
module OpenWeatherAPI
|
2
2
|
class API
|
3
3
|
|
4
|
-
|
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[:
|
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[:
|
10
|
+
@default_units = options[:default_units] || options['default_units'] || 'metric'
|
13
11
|
end
|
14
12
|
|
15
13
|
def current(**args, &block)
|
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.
|
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
|