Class: Square::BaseApi

Inherits:
Object
  • Object
show all
Includes:
CoreLibrary
Defined in:
lib/square/api/base_api.rb

Overview

BaseApi.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(global_configuration) ⇒ BaseApi

Initialization constructor.

Parameters:

  • global_configuration (GlobalConfiguration)

    The instance of GlobalConfiguration.



21
22
23
24
25
26
# File 'lib/square/api/base_api.rb', line 21

def initialize(global_configuration)
  @global_configuration = global_configuration
  @config = @global_configuration.client_configuration
  @http_call_back = @config.http_callback
  @api_call = ApiCall.new(@global_configuration)
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



5
6
7
# File 'lib/square/api/base_api.rb', line 5

def config
  @config
end

#http_call_backObject

Returns the value of attribute http_call_back.



5
6
7
# File 'lib/square/api/base_api.rb', line 5

def http_call_back
  @http_call_back
end

Class Method Details

.user_agentObject



7
8
9
# File 'lib/square/api/base_api.rb', line 7

def self.user_agent
  'Square-Ruby-SDK/37.0.0.20240417 ({api-version}) {engine}/{engine-version} ({os-info}) {detail}'
end

.user_agent_parametersObject



11
12
13
14
15
16
17
# File 'lib/square/api/base_api.rb', line 11

def self.user_agent_parameters
  {
    '{engine}' => { 'value' => RUBY_ENGINE, 'encode' => false },
    '{engine-version}' => { 'value' => RUBY_ENGINE_VERSION, 'encode' => false },
    '{os-info}' => { 'value' => RUBY_PLATFORM, 'encode' => false }
  }
end

Instance Method Details

#new_api_call_builderApiCall

Creates a new builder for the Api Call instance.

Returns:

  • (ApiCall)

    The instance of ApiCall.



30
31
32
# File 'lib/square/api/base_api.rb', line 30

def new_api_call_builder
  @api_call.new_builder
end

#new_parameter(value, key: nil) ⇒ Parameter

Creates a new instance of the parameter.

Parameters:

  • key (String|optional) (defaults to: nil)

    The key of the parameter.

  • value (Object)

    The value of the parameter.

Returns:

  • (Parameter)

    The instance of Parameter.



56
57
58
59
60
# File 'lib/square/api/base_api.rb', line 56

def new_parameter(value, key: nil)
  Parameter.new
           .key(key)
           .value(value)
end

#new_request_builder(http_method, path, server) ⇒ RequestBuilder

Creates a new instance of the request builder.

Parameters:

  • http_method (String)

    The HTTP method to use in the request.

  • path (String)

    The endpoint path to use in the request.

  • server (String)

    The server to extract the base uri for the request.

Returns:

  • (RequestBuilder)

    The instance of RequestBuilder.



39
40
41
42
43
44
# File 'lib/square/api/base_api.rb', line 39

def new_request_builder(http_method, path, server)
  RequestBuilder.new
                .http_method(http_method)
                .path(path)
                .server(server)
end

#new_response_handlerResponseHandler

Creates a new instance of the response handler.

Returns:

  • (ResponseHandler)

    The instance of ResponseHandler.



48
49
50
# File 'lib/square/api/base_api.rb', line 48

def new_response_handler
  ResponseHandler.new
end