api_access 0.3.2 → 0.3.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: 16ff83c89827e32ca73952f8693b0a22c4920e0f
4
- data.tar.gz: f8101a4a1f6fe4057582b83510a7636e182b9815
3
+ metadata.gz: 2c7aa722fc5e11133ea371a0224ea0bd93cdb943
4
+ data.tar.gz: 2b4fa49d9bd3e260cbded2c6d9cb49c8daba2b62
5
5
  SHA512:
6
- metadata.gz: 4edbd6fb62145e66271b81d7f7cd2013b7b2211d78c185bcaaff003118763aeae6ef284a30a78350976273b87165515cee1168933eb64b8cd51c0adb533a1fac
7
- data.tar.gz: 515ec70aabbb78c3297993557d52721f5b8129d2841cb14390db13f4a3f606d642f2390bd6114925257d6dd5f1ea929976b5f5e65e3d21f657504a4f5307a4a1
6
+ metadata.gz: 205d40e513f54204567fb6a0aa39c4d222b6cf76456d7f78f292471a6796e925d0af87c94d4a853e7ec1c9fdbc672f7c89a2f1508a59e3d31fc7518f30ca99cf
7
+ data.tar.gz: 8d01a91d98f91a50c41c4c29bda39568d1fc7586d8edb01fdf131dced17b8cc71b617ad475eb40f8000da8f2092b078f3fa8045efbfaa4490f5822f80a139c16
@@ -13,18 +13,34 @@ class ApiAccess
13
13
  request(url,params, method, format)
14
14
  end
15
15
 
16
- define_method "batch_#{method}_#{format}", ->(url, key_params, cocurrence = 10) do
16
+ define_method "batch_#{method}_#{format}", ->(urls, key_params, cocurrence = 10) do
17
17
  values = {}
18
- key_params.each_slice(cocurrence){ |group|
19
- threads = {}
20
- group.each do |key, params| # [key] array or key=> params hash
21
- params = {} if params.nil?
22
- threads[key] = Thread.new(params) do |param|
23
- request(url, param, method, format)
18
+ # two kind of batching: one url with many params
19
+ if urls.is_a? String
20
+ url = urls
21
+ key_params.each_slice(cocurrence){ |group|
22
+ threads = {}
23
+ group.each do |key, params| # [key] array or key=> params hash
24
+ params = {} if params.nil?
25
+ threads[key] = Thread.new(params) do |param|
26
+ request(url, param, method, format)
27
+ end
28
+ threads.each_pair{|k, thread| values[k] = thread.value}
24
29
  end
25
- threads.each_pair{|k, thread| values[k] = thread.value}
26
- end
27
- }
30
+ }
31
+ # and, many urls with one param
32
+ else
33
+ params = key_params || {}
34
+ urls.each_slice(cocurrence){|group|
35
+ threads = {}
36
+ group.each do |key, url|
37
+ threads[key] = Thread.new(params) do |param|
38
+ request(url, param, method, format)
39
+ end
40
+ threads.each_pair{|k, thread| values[k] = thread.value}
41
+ end
42
+ }
43
+ end
28
44
  values
29
45
  end
30
46
  end
@@ -1,3 +1,3 @@
1
1
  class ApiAccess
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_access
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - binz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-21 00:00:00.000000000 Z
11
+ date: 2014-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler