Class: HttpApiBuilder::BaseClient

Inherits:
Object
  • Object
show all
Extended by:
Dsl
Includes:
Helpers
Defined in:
lib/http_api_builder.rb

Overview

A basic HTTP client. Meant to be extended from.

Constant Summary

Constants included from Dsl

Dsl::VERBS

Instance Method Summary collapse

Methods included from Dsl

base_url

Constructor Details

#initializeBaseClient

Returns a new instance of BaseClient.



11
# File 'lib/http_api_builder.rb', line 11

def initialize(); end

Instance Method Details

#perform(method, path, form: nil, query: nil, body: nil, json: nil, &_block) ⇒ Object

Perform the request, post processors, and return the result



14
15
16
17
18
19
# File 'lib/http_api_builder.rb', line 14

def perform(method, path, form: nil, query: nil, body: nil, json: nil, &_block) # rubocop:disable Metrics/ParameterLists
  response = request(method, path, form: form, query: query, body: body, json: json)
  status = response.status
  resource = response.body
  block_given? ? yield(resource, status, response) : resource
end

#requestObject

Placeholder for your request method. Accepts these params, for you to do whatever you like with. See the HTTPrb_client implementation

Parameters:

  • method (Symbol)

    The HTTP VERB to use

  • path (String, URI)

    The path, excluding base_url, which should be prepended inside your implementation

  • form: (Hash)

    nil Form data, for encoding into HTTP form encoding

  • query: (Hash)

    nil Query key/value pairs

  • body: (String)

    nil A raw body

  • json: (Hash, Array)

    nil Hash/Array data to be encoded as JSON.



30
31
32
# File 'lib/http_api_builder.rb', line 30

def request(*)
  raise 'HttpApiBuilder::BaseClient#request must be implemented, see documentation'
end