Class: Restspec::Endpoints::Endpoint
- Inherits:
-
Struct
- Object
- Struct
- Restspec::Endpoints::Endpoint
- Includes:
- HasSchemas
- Defined in:
- lib/restspec/endpoints/endpoint.rb
Constant Summary
Constants included from HasSchemas
HasSchemas::DEFAULT_ROLES, HasSchemas::ROLES
Instance Attribute Summary collapse
-
#last_request ⇒ Object
readonly
Returns the value of attribute last_request.
-
#last_response ⇒ Object
readonly
Returns the value of attribute last_response.
-
#method ⇒ Object
Returns the value of attribute method.
-
#name ⇒ Object
Returns the value of attribute name.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#path ⇒ Object
Returns the value of attribute path.
-
#raw_url_params ⇒ Object
writeonly
Sets the attribute raw_url_params.
Instance Method Summary collapse
- #add_url_param_block(param, &block) ⇒ Object
- #execute(body: {}, url_params: {}, query_params: {}) ⇒ Object
- #execute_once(body: {}, url_params: {}, query_params: {}, before: ->{ }) ⇒ Object
- #executed_url ⇒ Object
- #full_name ⇒ Object
- #full_path ⇒ Object
- #headers ⇒ Object
- #payload ⇒ Object
- #url_params ⇒ Object
Methods included from HasSchemas
#add_schema, #all_schemas, #remove_schemas, #schema_for, #schema_roles
Instance Attribute Details
#last_request ⇒ Object
Returns the value of attribute last_request.
9 10 11 |
# File 'lib/restspec/endpoints/endpoint.rb', line 9 def last_request @last_request end |
#last_response ⇒ Object
Returns the value of attribute last_response.
9 10 11 |
# File 'lib/restspec/endpoints/endpoint.rb', line 9 def last_response @last_response end |
#method ⇒ Object
Returns the value of attribute method.
8 9 10 |
# File 'lib/restspec/endpoints/endpoint.rb', line 8 def method @method end |
#name ⇒ Object
Returns the value of attribute name
5 6 7 |
# File 'lib/restspec/endpoints/endpoint.rb', line 5 def name @name end |
#namespace ⇒ Object
Returns the value of attribute namespace.
8 9 10 |
# File 'lib/restspec/endpoints/endpoint.rb', line 8 def namespace @namespace end |
#path ⇒ Object
Returns the value of attribute path.
8 9 10 |
# File 'lib/restspec/endpoints/endpoint.rb', line 8 def path @path end |
#raw_url_params=(value) ⇒ Object
Sets the attribute raw_url_params
8 9 10 |
# File 'lib/restspec/endpoints/endpoint.rb', line 8 def raw_url_params=(value) @raw_url_params = value end |
Instance Method Details
#add_url_param_block(param, &block) ⇒ Object
52 53 54 |
# File 'lib/restspec/endpoints/endpoint.rb', line 52 def add_url_param_block(param, &block) raw_url_params[param] = Proc.new(&block) end |
#execute(body: {}, url_params: {}, query_params: {}) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/restspec/endpoints/endpoint.rb', line 11 def execute(body: {}, url_params: {}, query_params: {}) url = URLBuilder.new(full_path, self.url_params.merge(url_params), query_params).full_url request = Request.new(method, url, full_headers, body || payload) Network.request(request).tap do |response| self.last_request = inject_self_into(response, :endpoint) self.last_request = inject_self_into(request, :endpoint) end end |
#execute_once(body: {}, url_params: {}, query_params: {}, before: ->{ }) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/restspec/endpoints/endpoint.rb', line 21 def execute_once(body: {}, url_params: {}, query_params: {}, before: ->{ }) @executed_response ||= begin before.call execute(body: body, url_params: url_params, query_params: query_params) end end |
#executed_url ⇒ Object
56 57 58 |
# File 'lib/restspec/endpoints/endpoint.rb', line 56 def executed_url last_request.url end |
#full_name ⇒ Object
28 29 30 |
# File 'lib/restspec/endpoints/endpoint.rb', line 28 def full_name [namespace.try(:name), name].compact.join("/") end |
#full_path ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/restspec/endpoints/endpoint.rb', line 32 def full_path if namespace && in_member_or_collection? "#{namespace.full_base_path}#{path}" else path end end |
#headers ⇒ Object
40 41 42 |
# File 'lib/restspec/endpoints/endpoint.rb', line 40 def headers @headers ||= {} end |
#payload ⇒ Object
44 45 46 |
# File 'lib/restspec/endpoints/endpoint.rb', line 44 def payload @payload ||= internal_payload end |
#url_params ⇒ Object
48 49 50 |
# File 'lib/restspec/endpoints/endpoint.rb', line 48 def url_params @url_params ||= URLBuilder.new(full_path, raw_url_params).url_params end |