Class: SbrfMerchant::Api::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_name:, password:, host:, response_body_postprocessor: SbrfMerchant::Api::Response::BodyPostProcessor.new, request_body_preprocessor: SbrfMerchant::Api::Request::BodyPreProcessor.new, http_client: SbrfMerchant::Utils::Http::Client.new, uri_builder: SbrfMerchant::Api::Request::UriBuilder.new) ⇒ Client

Returns a new instance of Client.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/sbrf_merchant/api/client.rb', line 19

def initialize(
  user_name:,
  password:,
  host:,
  response_body_postprocessor: SbrfMerchant::Api::Response::BodyPostProcessor.new,
  request_body_preprocessor: SbrfMerchant::Api::Request::BodyPreProcessor.new,
  http_client: SbrfMerchant::Utils::Http::Client.new,
  uri_builder: SbrfMerchant::Api::Request::UriBuilder.new
)
  @user_name = user_name
  @password = password
  @host = host
  @response_body_postprocessor = response_body_postprocessor
  @http_client = http_client
  @uri_builder = uri_builder
  @request_body_preprocessor = request_body_preprocessor
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



11
12
13
# File 'lib/sbrf_merchant/api/client.rb', line 11

def host
  @host
end

#http_clientObject (readonly)

Returns the value of attribute http_client.



11
12
13
# File 'lib/sbrf_merchant/api/client.rb', line 11

def http_client
  @http_client
end

#passwordObject (readonly)

Returns the value of attribute password.



11
12
13
# File 'lib/sbrf_merchant/api/client.rb', line 11

def password
  @password
end

#request_body_preprocessorObject (readonly)

Returns the value of attribute request_body_preprocessor.



11
12
13
# File 'lib/sbrf_merchant/api/client.rb', line 11

def request_body_preprocessor
  @request_body_preprocessor
end

#response_body_postprocessorObject (readonly)

Returns the value of attribute response_body_postprocessor.



11
12
13
# File 'lib/sbrf_merchant/api/client.rb', line 11

def response_body_postprocessor
  @response_body_postprocessor
end

#uri_builderObject (readonly)

Returns the value of attribute uri_builder.



11
12
13
# File 'lib/sbrf_merchant/api/client.rb', line 11

def uri_builder
  @uri_builder
end

#user_nameObject (readonly)

Returns the value of attribute user_name.



11
12
13
# File 'lib/sbrf_merchant/api/client.rb', line 11

def user_name
  @user_name
end

Instance Method Details

#call(method_name, **params) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/sbrf_merchant/api/client.rb', line 37

def call(method_name, **params)
  prepared_params = request_body_preprocessor.call(auth_params.merge(params))
  uri = uri_builder.call(host, method_name)

  response = http_client.call(uri, prepared_params)
  response_body_postprocessor.call(response.body)
end