api_access 0.2.0 → 0.3.0
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 +3 -3
- data/lib/api_access/version.rb +1 -1
- data/lib/api_access.rb +20 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 349a56b15fd8a60f0c903439ab55a937f7687f8e
|
4
|
+
data.tar.gz: b31593c374661ba44f638005e4aca43b9b6b4796
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e02e408d1bb1f083b79a7440a8a16963003e442b48220c533b534006dbc313ff986e27e4f137eacc9b6827456e8707b51d27826bbc0da634195530aacf6bf1d0
|
7
|
+
data.tar.gz: bfc80b85e47b0895f9908f1f21ad5e8bcc8d2ec168e7367ee706f19a467e0e4e4526c96c33876c311be58b84596f37d868a258b7559d201a5a4bd6c95570876e
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# ApiAccess
|
2
2
|
|
3
|
-
|
3
|
+
A Ruby gem and a simple wrapper for HTTP GET and POST
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,11 +18,11 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
`ApiAccess.getJSON('http://example.com/url', {q: 1})`, `ApiAccess.get` is an alias method of `ApiAccess.getJSON`
|
22
22
|
|
23
23
|
## Contributing
|
24
24
|
|
25
|
-
1. Fork it ( https://github.com/
|
25
|
+
1. Fork it ( https://github.com/Slacken/api_access/fork )
|
26
26
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
27
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
28
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/api_access/version.rb
CHANGED
data/lib/api_access.rb
CHANGED
@@ -8,14 +8,30 @@ require 'json'
|
|
8
8
|
class ApiAccess
|
9
9
|
class << self
|
10
10
|
%w{get post}.each do |method|
|
11
|
-
%w{
|
12
|
-
define_method "#{method}#{format}", ->(url, params={}) do
|
11
|
+
%w{json xml}.each do |format|
|
12
|
+
define_method "#{method}_#{format}", ->(url, params={}) do
|
13
13
|
request(url,params, method, format)
|
14
14
|
end
|
15
|
+
|
16
|
+
define_method "batch_#{method}_#{format}", ->(url, key_params, cocurrence = 10) do
|
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)
|
24
|
+
end
|
25
|
+
threads.each_pair{|k, thread| values[k] = thread.value}
|
26
|
+
end
|
27
|
+
}
|
28
|
+
values
|
29
|
+
end
|
15
30
|
end
|
16
|
-
alias_method method, "#{method}JSON"
|
17
|
-
end
|
18
31
|
|
32
|
+
alias_method method, "#{method}_json"
|
33
|
+
alias_method "batch_#{method}", "batch_#{method}_json"
|
34
|
+
end
|
19
35
|
|
20
36
|
private
|
21
37
|
def request(url,request_params,method = 'get', format = nil)
|
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.
|
4
|
+
version: 0.3.0
|
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-
|
11
|
+
date: 2014-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|