Class: Square::Devices::Client
- Inherits:
-
Object
- Object
- Square::Devices::Client
- Defined in:
- lib/square/devices/client.rb
Instance Method Summary collapse
- #codes ⇒ Square::Codes::Client
-
#get(request_options: {}, **params) ⇒ Square::Types::GetDeviceResponse
Retrieves Device with the associated ‘device_id`.
- #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Square::Types::ListDevicesResponse
List devices associated with the merchant.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/square/devices/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#codes ⇒ Square::Codes::Client
102 103 104 |
# File 'lib/square/devices/client.rb', line 102 def codes @codes ||= Square::Devices::Codes::Client.new(client: @client) end |
#get(request_options: {}, **params) ⇒ Square::Types::GetDeviceResponse
Retrieves Device with the associated ‘device_id`.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/square/devices/client.rb', line 79 def get(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/devices/#{params[:device_id]}", request_options: ) 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::GetDeviceResponse.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::ListDevicesResponse
List devices associated with the merchant. Currently, only Terminal API devices are supported.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/square/devices/client.rb', line 29 def list(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[cursor sort_order limit location_id] query_params = {} query_params["cursor"] = params[:cursor] if params.key?(:cursor) query_params["sort_order"] = params[:sort_order] if params.key?(:sort_order) query_params["limit"] = params[:limit] if params.key?(:limit) query_params["location_id"] = params[:location_id] if params.key?(:location_id) params.except(*query_param_names) Square::Internal::CursorItemIterator.new( cursor_field: :cursor, item_field: :devices, initial_cursor: query_params[:cursor] ) do |next_cursor| query_params[:cursor] = next_cursor request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/devices", query: query_params, request_options: ) 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::ListDevicesResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end end |