Class: Restspec::Endpoints::Endpoint
- Inherits:
-
Struct
- Object
- Struct
- Restspec::Endpoints::Endpoint
- Defined in:
- lib/restspec/endpoints/endpoint.rb
Constant Summary collapse
- PARAM_INTERPOLATION_REGEX =
/:([\w]+)/
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.
-
#schema_extensions ⇒ Object
Returns the value of attribute schema_extensions.
- #schema_name ⇒ Object
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
- #schema ⇒ Object
- #url_params ⇒ Object
Instance Attribute Details
#last_request ⇒ Object
Returns the value of attribute last_request.
8 9 10 |
# File 'lib/restspec/endpoints/endpoint.rb', line 8 def last_request @last_request end |
#last_response ⇒ Object
Returns the value of attribute last_response.
8 9 10 |
# File 'lib/restspec/endpoints/endpoint.rb', line 8 def last_response @last_response end |
#method ⇒ Object
Returns the value of attribute method.
6 7 8 |
# File 'lib/restspec/endpoints/endpoint.rb', line 6 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.
6 7 8 |
# File 'lib/restspec/endpoints/endpoint.rb', line 6 def namespace @namespace end |
#path ⇒ Object
Returns the value of attribute path.
6 7 8 |
# File 'lib/restspec/endpoints/endpoint.rb', line 6 def path @path end |
#raw_url_params=(value) ⇒ Object
Sets the attribute raw_url_params
6 7 8 |
# File 'lib/restspec/endpoints/endpoint.rb', line 6 def raw_url_params=(value) @raw_url_params = value end |
#schema_extensions ⇒ Object
Returns the value of attribute schema_extensions.
6 7 8 |
# File 'lib/restspec/endpoints/endpoint.rb', line 6 def schema_extensions @schema_extensions end |
#schema_name ⇒ Object
33 34 35 |
# File 'lib/restspec/endpoints/endpoint.rb', line 33 def schema_name @schema_name || namespace.try(:schema_name) end |
Instance Method Details
#add_url_param_block(param, &block) ⇒ Object
64 65 66 |
# File 'lib/restspec/endpoints/endpoint.rb', line 64 def add_url_param_block(param, &block) raw_url_params[param] = Proc.new(&block) end |
#execute(body: {}, url_params: {}, query_params: {}) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/restspec/endpoints/endpoint.rb', line 12 def execute(body: {}, url_params: {}, query_params: {}) full_url = build_full_url(url_params, query_params) request = Request.new(method, full_url, full_headers, body) 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
22 23 24 25 26 27 |
# File 'lib/restspec/endpoints/endpoint.rb', line 22 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
68 69 70 |
# File 'lib/restspec/endpoints/endpoint.rb', line 68 def executed_url last_request.url end |
#full_name ⇒ Object
29 30 31 |
# File 'lib/restspec/endpoints/endpoint.rb', line 29 def full_name [namespace.try(:name), name].compact.join("/") end |
#full_path ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/restspec/endpoints/endpoint.rb', line 48 def full_path if namespace && in_member_or_collection? "#{namespace.full_base_path}#{path}" else path end end |
#headers ⇒ Object
56 57 58 |
# File 'lib/restspec/endpoints/endpoint.rb', line 56 def headers @headers ||= {} end |
#schema ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/restspec/endpoints/endpoint.rb', line 37 def schema @schema ||= begin found_schema = schema_from_store if found_schema.present? found_schema.clone.extend_with(schema_extensions || {}) else nil end end end |