Class: Square::Merchants::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Square::Merchants::Client



7
8
9
# File 'lib/square/merchants/client.rb', line 7

def initialize(client:)
  @client = client
end

Instance Method Details

#custom_attribute_definitionsSquare::CustomAttributeDefinitions::Client

Returns:

  • (Square::CustomAttributeDefinitions::Client)


75
76
77
# File 'lib/square/merchants/client.rb', line 75

def custom_attribute_definitions
  @custom_attribute_definitions ||= Square::Merchants::CustomAttributeDefinitions::Client.new(client: @client)
end

#custom_attributesSquare::CustomAttributes::Client

Returns:

  • (Square::CustomAttributes::Client)


80
81
82
# File 'lib/square/merchants/client.rb', line 80

def custom_attributes
  @custom_attributes ||= Square::Merchants::CustomAttributes::Client.new(client: @client)
end

#get(request_options: {}, **params) ⇒ Square::Types::GetMerchantResponse

Retrieves the ‘Merchant` object for the given `merchant_id`.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/square/merchants/client.rb', line 54

def get(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "GET",
    path: "v2/merchants/#{params[:merchant_id]}"
  )
  begin
    _response = @client.send(_request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = _response.code.to_i
  if code.between?(200, 299)
    Square::Types::GetMerchantResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end

#list(request_options: {}, **params) ⇒ Square::Types::ListMerchantsResponse

Provides details about the merchant associated with a given access token.

The access token used to connect your application to a Square seller is associated with a single merchant. That means that ‘ListMerchants` returns a list with a single `Merchant` object. You can specify your personal access token to get your own merchant information or specify an OAuth token to get the information for the merchant that granted your application access.

If you know the merchant ID, you can also use the [RetrieveMerchant](api-endpoint:Merchants-RetrieveMerchant) endpoint to retrieve the merchant information.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/square/merchants/client.rb', line 23

def list(request_options: {}, **params)
  _query_param_names = [
    ["cursor"],
    %i[cursor]
  ].flatten
  _query = params.slice(*_query_param_names)
  params.except(*_query_param_names)

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "GET",
    path: "v2/merchants",
    query: _query
  )
  begin
    _response = @client.send(_request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = _response.code.to_i
  if code.between?(200, 299)
    Square::Types::ListMerchantsResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end