Class: Beze::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/beze/client.rb

Overview

Client that acts as a middleman to the API.

Defined Under Namespace

Classes: BezeErrorResult, BezeResult

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, payload, options) ⇒ Client

Returns a new instance of Client.



35
36
37
38
39
# File 'lib/beze/client.rb', line 35

def initialize(resource, payload, options)
  @resource = resource
  @payload  = payload
  @options  = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



29
30
31
# File 'lib/beze/client.rb', line 29

def options
  @options
end

#payloadObject (readonly)

Returns the value of attribute payload.



29
30
31
# File 'lib/beze/client.rb', line 29

def payload
  @payload
end

#resourceObject (readonly)

Returns the value of attribute resource.



29
30
31
# File 'lib/beze/client.rb', line 29

def resource
  @resource
end

Class Method Details

.call(resource:, payload:, options:) ⇒ Object



31
32
33
# File 'lib/beze/client.rb', line 31

def self.call(resource:, payload:, options:)
  new(resource, payload, options).call
end

Instance Method Details

#callObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/beze/client.rb', line 41

def call
  body    = payload
  headers = options[:headers]
  params  = options[:params]
  uri     = "#{Beze::BASE_URL}/#{Beze.configuration.api_version}/#{resource}/#{options[:uri]}"

  http_call = Beze::HttpClient.call(body: body, headers: headers, method: method, params: params, uri: uri)

  if http_call.successful?
    BezesResult.new(result: http_call, message: "Successful call to endpoint. #{http_call.result.message}")
  else
    BezeErrorResult.new(result: http_call, message: "Failure while calling endpoint. #{http_call.result.message}")
  end
end