Class: Square::MobileAuthorizationApi
- Defined in:
- lib/square/api/mobile_authorization_api.rb
Overview
MobileAuthorizationApi
Instance Attribute Summary
Attributes inherited from BaseApi
Instance Method Summary collapse
-
#create_mobile_authorization_code(body:) ⇒ CreateMobileAuthorizationCodeResponse Hash
Generates code to authorize a mobile application to connect to a Square card reader Authorization codes are one-time-use and expire __60 minutes__ after being issued.
-
#initialize(config, http_call_back: nil) ⇒ MobileAuthorizationApi
constructor
A new instance of MobileAuthorizationApi.
Methods inherited from BaseApi
#execute_request, #validate_parameters
Constructor Details
#initialize(config, http_call_back: nil) ⇒ MobileAuthorizationApi
Returns a new instance of MobileAuthorizationApi.
4 5 6 |
# File 'lib/square/api/mobile_authorization_api.rb', line 4 def initialize(config, http_call_back: nil) super(config, http_call_back: http_call_back) end |
Instance Method Details
#create_mobile_authorization_code(body:) ⇒ CreateMobileAuthorizationCodeResponse Hash
Generates code to authorize a mobile application to connect to a Square card reader Authorization codes are one-time-use and expire __60 minutes__ after being issued. Important: The `Authorization` header you provide to this endpoint must have the following format: “` Authorization: Bearer ACCESS_TOKEN “` Replace `ACCESS_TOKEN` with a [valid production authorization credential](developer.squareup.com/docs/build-basics/access-tokens ). object containing the fields to POST for the request. See the corresponding object definition for field details.
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 52 |
# File 'lib/square/api/mobile_authorization_api.rb', line 25 def (body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/mobile/authorization-code' _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'content-type' => 'application/json; charset=utf-8' } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers, parameters: body.to_json ) 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 |