Class: PCO::API::Endpoint
- Inherits:
-
Object
- Object
- PCO::API::Endpoint
show all
- Defined in:
- lib/pco/api/endpoint.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(url: URL, oauth_access_token: nil, basic_auth_token: nil, basic_auth_secret: nil, connection: nil) ⇒ Endpoint
Returns a new instance of Endpoint.
15
16
17
18
19
20
21
22
|
# File 'lib/pco/api/endpoint.rb', line 15
def initialize(url: URL, oauth_access_token: nil, basic_auth_token: nil, basic_auth_secret: nil, connection: nil)
@url = url
@oauth_access_token = oauth_access_token
@basic_auth_token = basic_auth_token
@basic_auth_secret = basic_auth_secret
@connection = connection || _build_connection
@cache = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *_args) ⇒ Object
24
25
26
|
# File 'lib/pco/api/endpoint.rb', line 24
def method_missing(method_name, *_args)
_build_endpoint(method_name.to_s)
end
|
Instance Attribute Details
#last_result ⇒ Object
Returns the value of attribute last_result.
13
14
15
|
# File 'lib/pco/api/endpoint.rb', line 13
def last_result
@last_result
end
|
#url ⇒ Object
Returns the value of attribute url.
13
14
15
|
# File 'lib/pco/api/endpoint.rb', line 13
def url
@url
end
|
Instance Method Details
#[](id) ⇒ Object
28
29
30
|
# File 'lib/pco/api/endpoint.rb', line 28
def [](id)
_build_endpoint(id.to_s)
end
|
#delete ⇒ Object
62
63
64
65
66
67
68
69
|
# File 'lib/pco/api/endpoint.rb', line 62
def delete
@last_result = @connection.delete(@url)
if @last_result.status == 204
true
else
_build_response(@last_result)
end
end
|
#get(params = {}) ⇒ Object
43
44
45
46
|
# File 'lib/pco/api/endpoint.rb', line 43
def get(params = {})
@last_result = @connection.get(@url, params)
_build_response(@last_result)
end
|
#patch(body = {}) ⇒ Object
55
56
57
58
59
60
|
# File 'lib/pco/api/endpoint.rb', line 55
def patch(body = {})
@last_result = @connection.patch(@url) do |req|
req.body = _build_body(body)
end
_build_response(@last_result)
end
|
#post(body = {}) ⇒ Object
48
49
50
51
52
53
|
# File 'lib/pco/api/endpoint.rb', line 48
def post(body = {})
@last_result = @connection.post(@url) do |req|
req.body = _build_body(body)
end
_build_response(@last_result)
end
|
#respond_to?(method_name) ⇒ Boolean
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/pco/api/endpoint.rb', line 32
def respond_to?(method_name)
endpoint = _build_endpoint(method_name.to_s)
begin
endpoint.get
rescue Errors::NotFound
false
else
true
end
end
|