darksky_ruby_client 0.0.2 → 0.0.4

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: f50f7c621b6b8bf0ba6ff2dbd55bc3e1cc4d0df6
4
- data.tar.gz: 1d29c79687153daafca6a546d6b14c8e75ee17a7
3
+ metadata.gz: bcaae1546f66eed78cfd11f2e92e2f2b2f624e78
4
+ data.tar.gz: 0c86237cb7c95f186beb61f1cbca4c9cd1371272
5
5
  SHA512:
6
- metadata.gz: a5a4d5ce1039eaca500bc06ce5093b97bf35ee79e24227f3ef7dc83cafa5e5d2684650e76b12052273e53c68ab3d9bd8ed0f744947c911bda8042edfbfafecae
7
- data.tar.gz: 3bdd10f63e4527afb8cf383c4e3ffab991b93f7a97ce87331f4bd85b88935a4f7439f6bcf73eb7b9457badecd4c8ceb1a2dc227a64f06377c139a7e38864c97e
6
+ metadata.gz: 6fefae976ece55e79d17be76ca2831a9170789e863ba601d1bddb8a01b35d73a076c7ab26565ab8883ae9c5ea713bcd8f102c6d0db5779bd22ff1292b68498a8
7
+ data.tar.gz: c8ca7bb9d72b62c9dff542134255d13e0b3b363778ca80e84b858aa6072ddfd9c59a8383b29091226b818a4af6bb3358619fa70b9661c10d05d8e11bc714da01
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  # DarkskyRubyClient
2
+ [![Gem Version](https://badge.fury.io/rb/darksky_ruby_client.svg)](https://badge.fury.io/rb/darksky_ruby_client)
3
+
2
4
  This Client for more convenient use of the DarkSky API.
3
5
 
4
6
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/darksky_ruby_client`. To experiment with that code, run `bin/console` for an interactive prompt.
@@ -22,14 +24,28 @@ Or install it yourself as:
22
24
  $ gem install darksky_ruby_client
23
25
 
24
26
  ## Usage
27
+ Simplest use.
28
+ ```ruby
29
+ require 'darksky_ruby_client'
30
+ client = DarkskyRubyClient::Client.new('your Dark Sky secret key')
31
+ client.weather_forecast('latitude', 'longitude')
32
+ ```
25
33
 
34
+ Parallel requests.
26
35
  ```ruby
27
36
  require 'darksky_ruby_client'
28
- options = {
29
- :extend => "hourly"
37
+ locations = {
38
+ :sanfrancisco => {
39
+ :latitude => "37.77493",
40
+ :longitude => "-122.419416"
41
+ },
42
+ :losangeles => {
43
+ :latitude => "34.052234",
44
+ :longitude => "-118.243684"
45
+ }
30
46
  }
31
47
  client = DarkskyRubyClient::Client.new('your Dark Sky secret key')
32
- client.weather_forecast('latitude', 'longitude', options).run
48
+ client.some_weather_forecast(locations)
33
49
  ```
34
50
 
35
51
  ## Development
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["appcot.2013@gmail.com"]
11
11
 
12
12
  spec.summary = %q{DarkSky Ruby Client}
13
- spec.description = %q{Ruby client for the DarkSky.}
13
+ spec.description = %q{This Client for more convenient use of the DarkSky API.}
14
14
  spec.homepage = "https://github.com/appcot/darksky_ruby_client"
15
15
  spec.license = "MIT"
16
16
 
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
+ spec.add_dependency "activesupport", "~> 5.1"
24
25
  spec.add_dependency "typhoeus", "~> 1.3"
25
26
 
26
27
  spec.add_development_dependency "bundler", "~> 1.16"
@@ -1,3 +1,5 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext'
1
3
  require 'json'
2
4
  require 'logger'
3
5
  require 'typhoeus'
@@ -23,9 +25,8 @@ module DarkskyRubyClient
23
25
  # @param [String] key Secret key of the api.
24
26
  def initialize(key)
25
27
  @secret_key = key
26
- @client = Typhoeus::Request.new(@@base_url)
27
- @options = {}
28
- @params = {:params => {}}
28
+ @parallel_requests = false
29
+ @responses = {}
29
30
  end
30
31
 
31
32
  # A single request for forecast request
@@ -34,7 +35,7 @@ module DarkskyRubyClient
34
35
  # @param [Hash] options Use if you want to specify "explicit, extend, lang, units".
35
36
  # Please check https://darksky.net/dev/docs#forecast-request for details.
36
37
  # @option options [String] :exclude
37
- # exlude=[blocks] e.g. currently, flags
38
+ # exlude=[blocks] e.g. exclude: "currently,flags"
38
39
  # Exclude some number of data blocks from the API response.
39
40
  # This is useful for reducing latency and saving cache space.
40
41
  # The value blocks should be a comma-delimeted list (without spaces) of any of the following:
@@ -45,17 +46,17 @@ module DarkskyRubyClient
45
46
  # * alerts
46
47
  # * flags
47
48
  # @option options [String] :extend
48
- # extend=[hourly] e.g. 24
49
+ # extend=[hourly] e.g. hourly: "24"
49
50
  # When present, return hour-by-hour data for the next 168 hours, instead of the next 48.
50
51
  # When using this option, we strongly recommend enabling HTTP compression.
51
52
  # @option options [String] :lang
52
- # e.g. en
53
+ # e.g. lang: "en"
53
54
  # Return summary properties in the desired language.
54
55
  # (Note that units in the summary will be set according to the units parameter,
55
56
  # so be sure to set both parameters appropriately.)
56
57
  # Please check with https://darksky.net/dev/docs#forecast-request for available languages.
57
58
  # @option options [String] :units
58
- # units=[units] e.g. auto
59
+ # units=[units] e.g. units: "auto"
59
60
  # Return weather conditions in the requested units.
60
61
  # [units] should be one of the following:
61
62
  # * auto: automatically select units based on geographic location
@@ -65,7 +66,7 @@ module DarkskyRubyClient
65
66
  # * us: Imperial units (the default)
66
67
  # * si: SI units
67
68
  # Please check with https://darksky.net/dev/docs#forecast-request for available SI units.
68
- def weather_forecast(lat, long, options = {})
69
+ def weather_forecast(lat, long, **options)
69
70
  @request_url = @@base_url + @secret_key + '/' + lat + ',' + long + '/'
70
71
  unless options.empty? then
71
72
  options.each {|key, value|
@@ -82,11 +83,26 @@ module DarkskyRubyClient
82
83
  }
83
84
  end
84
85
  init_client
86
+ run unless @parallel_requests
85
87
  end
86
88
 
87
89
  # TODO Parallel requests
88
- def some_weather_forecast(options = {}, locations:)
89
-
90
+ def some_weather_forecast(locations, **options)
91
+ @parallel_requests = true
92
+ hydra = Typhoeus::Hydra.new
93
+ locations.with_indifferent_access
94
+ locations.each {|place_name, location|
95
+ latitude = location[:latitude] if location.include?(:latitude)
96
+ longitude = location[:longitude] if location.include?(:longitude)
97
+ weather_forecast(latitude, longitude, options)
98
+ @client.on_complete do |response|
99
+ @responses[place_name] = response
100
+ end
101
+ hydra.queue @client
102
+ @client
103
+ }
104
+ hydra.run
105
+ return @responses
90
106
  end
91
107
 
92
108
  # Init client for typhoeus
@@ -1,3 +1,3 @@
1
1
  module DarkskyRubyClient
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: darksky_ruby_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - appcot
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-23 00:00:00.000000000 Z
11
+ date: 2017-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.1'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: typhoeus
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +80,7 @@ dependencies:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
82
  version: '3.0'
69
- description: Ruby client for the DarkSky.
83
+ description: This Client for more convenient use of the DarkSky API.
70
84
  email:
71
85
  - appcot.2013@gmail.com
72
86
  executables: