Class: DaFace::Api::Adapters::ExconAdapter
- Inherits:
-
Base
- Object
- Base
- DaFace::Api::Adapters::ExconAdapter
show all
- Defined in:
- lib/da_face/api/adapters/excon_adapter.rb
Instance Attribute Summary
Attributes inherited from Base
#api_key, #host, #path_prefix, #user
Instance Method Summary
collapse
Methods inherited from Base
#api_auth_header, #api_path, #default_headers, #encode_form, #get_headers, #initialize, #post_headers, #set_rate_limit_status, #url_params
Instance Method Details
#connection ⇒ Object
5
6
7
|
# File 'lib/da_face/api/adapters/excon_adapter.rb', line 5
def connection
Excon.new self.api_path
end
|
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/da_face/api/adapters/excon_adapter.rb', line 38
def
if .select{|| [0] == 'x'}.any?
{
:limit => ['x-ratelimit-limit'],
:remaining => ['x-ratelimit-remaining']
}
elsif .select{|| [0] == 'X'}.any?
{
:limit => ['X-RateLimit-Limit'],
:remaining => ['X-RateLimit-Remaining']
}
else
{
:limit => nil,
:remaining => nil
}
end
end
|
#get(path, params = {}) ⇒ Object
9
10
11
12
|
# File 'lib/da_face/api/adapters/excon_adapter.rb', line 9
def get path, params={}
response = connection.get :path => "#{path}#{url_params(params)}", :headers =>
handle_response(response)
end
|
#handle_response(response) ⇒ Object
32
33
34
35
36
|
# File 'lib/da_face/api/adapters/excon_adapter.rb', line 32
def handle_response response
rate_limit_info = (response.)
set_rate_limit_status(rate_limit_info[:limit], rate_limit_info[:remaining])
return parse_body(response.body)
end
|
#parse_body(body) ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/da_face/api/adapters/excon_adapter.rb', line 24
def parse_body body
if body.empty?
{}
else
JSON.parse(body)
end
end
|
#post(path, payload) ⇒ Object
14
15
16
17
|
# File 'lib/da_face/api/adapters/excon_adapter.rb', line 14
def post path, payload
response = connection.post :path => path, :body => encode_form(payload), :headers =>
handle_response(response)
end
|
#put(path, payload) ⇒ Object
19
20
21
22
|
# File 'lib/da_face/api/adapters/excon_adapter.rb', line 19
def put path, payload
response = connection.put :path => "#{path}", :body => encode_form(payload), :headers =>
handle_response(response)
end
|