Class: Square::MerchantsApi
- Defined in:
- lib/square/api/merchants_api.rb
Overview
MerchantsApi
Instance Attribute Summary
Attributes inherited from BaseApi
Instance Method Summary collapse
-
#initialize(config, http_call_back: nil) ⇒ MerchantsApi
constructor
A new instance of MerchantsApi.
-
#list_merchants(cursor: nil) ⇒ ListMerchantsResponse Hash
Provides details about the merchant associated with a given access token.
-
#retrieve_merchant(merchant_id:) ⇒ RetrieveMerchantResponse Hash
Retrieves the `Merchant` object for the given `merchant_id`.
Methods inherited from BaseApi
#execute_request, #get_user_agent, #validate_parameters
Constructor Details
#initialize(config, http_call_back: nil) ⇒ MerchantsApi
Returns a new instance of MerchantsApi.
4 5 6 |
# File 'lib/square/api/merchants_api.rb', line 4 def initialize(config, http_call_back: nil) super(config, http_call_back: http_call_back) end |
Instance Method Details
#list_merchants(cursor: nil) ⇒ ListMerchantsResponse Hash
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]($e/Merchants/RetrieveMerchant) endpoint to retrieve the merchant information. previous response.
22 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 50 51 |
# File 'lib/square/api/merchants_api.rb', line 22 def list_merchants(cursor: nil) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/merchants' _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, 'cursor' => cursor ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.get( _query_url, headers: _headers ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#retrieve_merchant(merchant_id:) ⇒ RetrieveMerchantResponse Hash
Retrieves the `Merchant` object for the given `merchant_id`. retrieve. If the string “me” is supplied as the ID, then retrieve the merchant that is currently accessible to this call.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/square/api/merchants_api.rb', line 58 def retrieve_merchant(merchant_id:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/merchants/{merchant_id}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'merchant_id' => { 'value' => merchant_id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.get( _query_url, headers: _headers ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |