Class: Panoptes::Endpoints::BaseEndpoint
- Inherits:
-
Object
- Object
- Panoptes::Endpoints::BaseEndpoint
show all
- Defined in:
- lib/panoptes/endpoints/base_endpoint.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#connection ⇒ Object
-
#delete(path, query = {}, etag: nil) ⇒ Object
-
#etag_header(etag) ⇒ Object
-
#get(path, query = {}) ⇒ Object
-
#handle_response(response) ⇒ Object
-
#initialize(auth: {}, url: nil, prefix: nil, params: nil) {|faraday| ... } ⇒ BaseEndpoint
constructor
A new instance of BaseEndpoint.
-
#patch(path, body = {}, etag: nil) ⇒ Object
-
#post(path, body = {}) ⇒ Object
-
#put(path, body = {}, etag: nil) ⇒ Object
-
#request(method, path, *args) ⇒ Object
Constructor Details
#initialize(auth: {}, url: nil, prefix: nil, params: nil) {|faraday| ... } ⇒ BaseEndpoint
Returns a new instance of BaseEndpoint.
19
20
21
22
23
24
25
|
# File 'lib/panoptes/endpoints/base_endpoint.rb', line 19
def initialize(auth: {}, url: nil, prefix: nil, params: nil, &config)
@auth = auth
@url = url
@prefix = prefix
@config = config
@params = params
end
|
Instance Attribute Details
#auth ⇒ Object
Returns the value of attribute auth.
8
9
10
|
# File 'lib/panoptes/endpoints/base_endpoint.rb', line 8
def auth
@auth
end
|
#params ⇒ Object
Returns the value of attribute params.
8
9
10
|
# File 'lib/panoptes/endpoints/base_endpoint.rb', line 8
def params
@params
end
|
#prefix ⇒ Object
Returns the value of attribute prefix.
8
9
10
|
# File 'lib/panoptes/endpoints/base_endpoint.rb', line 8
def prefix
@prefix
end
|
#url ⇒ Object
Returns the value of attribute url.
8
9
10
|
# File 'lib/panoptes/endpoints/base_endpoint.rb', line 8
def url
@url
end
|
Instance Method Details
#connection ⇒ Object
27
28
29
30
31
32
|
# File 'lib/panoptes/endpoints/base_endpoint.rb', line 27
def connection
@connection ||= Faraday.new(url) do |faraday|
auth_request faraday, auth
configure faraday
end
end
|
#delete(path, query = {}, etag: nil) ⇒ Object
50
51
52
|
# File 'lib/panoptes/endpoints/base_endpoint.rb', line 50
def delete(path, query = {}, etag: nil)
request :delete, path, query, (etag)
end
|
54
55
56
57
58
|
# File 'lib/panoptes/endpoints/base_endpoint.rb', line 54
def (etag)
{}.tap do ||
['If-Match'] = etag if etag
end
end
|
#get(path, query = {}) ⇒ Object
34
35
36
|
# File 'lib/panoptes/endpoints/base_endpoint.rb', line 34
def get(path, query = {})
request :get, path, query
end
|
#handle_response(response) ⇒ Object
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/panoptes/endpoints/base_endpoint.rb', line 65
def handle_response(response)
case response.status
when 404
raise Panoptes::Client::ResourceNotFound, status: response.status, body: response.body
when 400..600
raise Panoptes::Client::ServerError.new, response.body
else
response.body
end
end
|
#patch(path, body = {}, etag: nil) ⇒ Object
46
47
48
|
# File 'lib/panoptes/endpoints/base_endpoint.rb', line 46
def patch(path, body = {}, etag: nil)
request :patch, path, body, (etag)
end
|
#post(path, body = {}) ⇒ Object
38
39
40
|
# File 'lib/panoptes/endpoints/base_endpoint.rb', line 38
def post(path, body = {})
request :post, path, body
end
|
#put(path, body = {}, etag: nil) ⇒ Object
42
43
44
|
# File 'lib/panoptes/endpoints/base_endpoint.rb', line 42
def put(path, body = {}, etag: nil)
request :put, path, body, (etag)
end
|
#request(method, path, *args) ⇒ Object
60
61
62
63
|
# File 'lib/panoptes/endpoints/base_endpoint.rb', line 60
def request(method, path, *args)
path = "#{prefix}/#{path}" if prefix
handle_response connection.send(method, path, *args)
end
|