Class: Leal::Stores::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



9
10
11
# File 'lib/leal/stores/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#get(request_options: {}, **params) ⇒ Leal::Stores::Types::GetStoresResponse

Returns detailed information for a single store, including summary counts for its associated resources.

Examples:

client.stores.get(id: 1)

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :id (Integer)

Returns:



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/leal/stores/client.rb', line 62

def get(request_options: {}, **params)
  params = Leal::Internal::Types::Utils.normalize_keys(params)
  request = Leal::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "api/v1/accounts/#{URI.encode_uri_component(params[:id].to_s)}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Leal::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Leal::Stores::Types::GetStoresResponse.load(response.body)
  else
    error_class = Leal::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#list(request_options: {}, **_params) ⇒ Array[Leal::Stores::Types::ListStoresResponseItem]

Returns every store the authenticated user has access to, including summary counts for locations, cards, customers, and posters.

Examples:

client.stores.list

Parameters:

  • request_options (Hash) (defaults to: {})
  • _params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:

Raises:

  • (error_class)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/leal/stores/client.rb', line 28

def list(request_options: {}, **_params)
  request = Leal::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "api/v1/accounts",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Leal::Errors::TimeoutError
  end
  code = response.code.to_i
  return if code.between?(200, 299)

  error_class = Leal::Errors::ResponseError.subclass_for_code(code)
  raise error_class.new(response.body, code: code)
end

#update(request_options: {}, **params) ⇒ Leal::Stores::Types::UpdateStoresResponse

Updates the store's name or store_name. Use store_name for the public-facing name displayed to customers.

Examples:

client.stores.update(
  id: 1,
  account: {}
)

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :id (Integer)

Returns:



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/leal/stores/client.rb', line 102

def update(request_options: {}, **params)
  params = Leal::Internal::Types::Utils.normalize_keys(params)
  request_data = Leal::Stores::Types::UpdateStoresRequest.new(params).to_h
  non_body_param_names = %w[id]
  body = request_data.except(*non_body_param_names)

  request = Leal::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "PATCH",
    path: "api/v1/accounts/#{URI.encode_uri_component(params[:id].to_s)}",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Leal::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Leal::Stores::Types::UpdateStoresResponse.load(response.body)
  else
    error_class = Leal::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end