Class: ApiBlueprint::Blueprint
- Defined in:
- lib/api-blueprint/blueprint.rb
Instance Method Summary collapse
- #all_request_options(options = {}) ⇒ Object
- #connection ⇒ Object
- #run(options = {}, runner = nil) ⇒ Object
Methods inherited from Struct
Instance Method Details
#all_request_options(options = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/api-blueprint/blueprint.rb', line 16 def ( = {}) { http_method: http_method, url: url, headers: headers.merge(.fetch(:headers, {})), params: params.merge(.fetch(:params, {})), body: body.merge(.fetch(:body, {})) } end |
#connection ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/api-blueprint/blueprint.rb', line 47 def connection Faraday.new do |conn| conn.use ApiBlueprint::ResponseMiddleware conn.response :json, content_type: /\bjson$/ conn.use :instrumentation, name: "api-blueprint.request" if enable_response_logging? conn.response :detailed_logger, ApiBlueprint.config.logger, "API-BLUEPRINT" end conn.adapter Faraday.default_adapter conn.headers = { "User-Agent": "ApiBlueprint" } end end |
#run(options = {}, runner = nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/api-blueprint/blueprint.rb', line 26 def run( = {}, runner = nil) if .delete :validate result = build from: [:body] return result.errors if result.invalid? end response = call_api () if creates.present? created = build from: response.body, headers: response.headers, status: response.status else created = response end after_build.present? ? after_build.call(runner, created) : created rescue Faraday::ConnectionFailed raise ApiBlueprint::ConnectionFailed rescue Faraday::TimeoutError raise ApiBlueprint::TimeoutError end |