Class: Lurker::EndpointScaffold
- Defined in:
- lib/lurker/endpoint_scaffold.rb
Overview
EndpointScaffolds aggregate input to guess at the structure of an API endpoint. The #consume_* methods can modify the structure of the in-memory endpoint, to save the results to the file system, call #persist!
Instance Attribute Summary
Attributes inherited from Endpoint
#current_scaffold, #endpoint_path, #errors, #extensions, #schema, #service
Instance Method Summary collapse
- #consume_request(params, successful = true) ⇒ Object
- #consume_response(params, status_code, successful = true) ⇒ Object
-
#initialize(endpoint_path, extensions = {}, service = Lurker::Service.default_service) ⇒ EndpointScaffold
constructor
A new instance of EndpointScaffold.
- #persist! ⇒ Object
Methods inherited from Endpoint
#consume!, #deprecated?, #description, #indexed?, #path, #prefix, #query_params, #request_parameters, #response_codes, #response_parameters, #url_params, #verb
Constructor Details
#initialize(endpoint_path, extensions = {}, service = Lurker::Service.default_service) ⇒ EndpointScaffold
Returns a new instance of EndpointScaffold.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/lurker/endpoint_scaffold.rb', line 5 def initialize(endpoint_path, extensions={}, service=Lurker::Service.default_service) if File.exist?(endpoint_path) super else @endpoint_path = endpoint_path @schema = Lurker::Schema.new( { "prefix" => "", "description" => "", "responseCodes" => [] }, stringify_keys(extensions) ) @service = service @errors = [] @extensions = extensions end end |
Instance Method Details
#consume_request(params, successful = true) ⇒ Object
28 29 30 31 32 |
# File 'lib/lurker/endpoint_scaffold.rb', line 28 def consume_request(params, successful = true) scaffold_schema(request_parameters, stringify_keys(params), { :root_object => true }) end |
#consume_response(params, status_code, successful = true) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/lurker/endpoint_scaffold.rb', line 34 def consume_response(params, status_code, successful=true) if successful scaffold_schema(response_parameters, stringify_keys(params), { :root_object => true }) end response_code = response_codes.find do |rc| rc["status"] == status_code && rc["successful"] == successful end if !response_code response_codes << { "status" => status_code, "successful" => successful, "description" => "" } end end |
#persist! ⇒ Object
24 25 26 |
# File 'lib/lurker/endpoint_scaffold.rb', line 24 def persist! schema.ordered!.write_to(endpoint_path) end |