Class: Glassfrog::REST::Request
- Inherits:
-
Object
- Object
- Glassfrog::REST::Request
show all
- Includes:
- Utils
- Defined in:
- lib/glassfrog/rest/request.rb
Overview
Encapsulates an HTTP Request.
Constant Summary
collapse
- ROOT_URL =
'https://glassfrog.holacracy.org/api/v3'
- REQUEST_ASSOCIATIONS =
{
get: :params,
post: :json,
patch: :json,
delete: :form
}
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Utils
#extract_id, #parameterize, #symbolize_keys
Constructor Details
#initialize(client, request_method, path, options) ⇒ Glassfrog::Request
Initializes a new Request object.
38
39
40
41
42
43
44
|
# File 'lib/glassfrog/rest/request.rb', line 38
def initialize(client, request_method, path, options)
@client = client
@headers = client.
@request_method = request_method
@uri = Addressable::URI.parse(path.start_with?('http') ? path : ROOT_URL + path)
@options = options
end
|
Instance Attribute Details
14
15
16
|
# File 'lib/glassfrog/rest/request.rb', line 14
def client
@client
end
|
16
17
18
|
# File 'lib/glassfrog/rest/request.rb', line 16
def
@headers
end
|
#options ⇒ Hash
16
17
18
|
# File 'lib/glassfrog/rest/request.rb', line 16
def options
@options
end
|
#request_method ⇒ Symbol
18
19
20
|
# File 'lib/glassfrog/rest/request.rb', line 18
def request_method
@request_method
end
|
#uri ⇒ Addressable::URI
20
21
22
|
# File 'lib/glassfrog/rest/request.rb', line 20
def uri
@uri
end
|
Instance Method Details
50
51
52
53
54
|
# File 'lib/glassfrog/rest/request.rb', line 50
def perform
options_key = REQUEST_ASSOCIATIONS[@request_method]
response = @client.http.(@headers).public_send(@request_method, @uri.to_s, options_key => @options)
fail_or_return_response_body(response.code, response, response.)
end
|