Class: Payabli::Cloud::Client
- Inherits:
-
Object
- Object
- Payabli::Cloud::Client
- Defined in:
- lib/payabli/cloud/client.rb
Instance Method Summary collapse
-
#add_device(request_options: {}, **params) ⇒ Payabli::Types::AddDeviceResponse
Register a cloud device to an entrypoint.
-
#history_device(request_options: {}, **params) ⇒ Payabli::Types::CloudQueryApiResponse
Retrieve the registration history for a device.
- #initialize(client:) ⇒ void constructor
-
#list_device(request_options: {}, **params) ⇒ Payabli::Types::CloudQueryApiResponse
Use List devices by paypoint instead, which supports filters, sorting, and pagination.
-
#remove_device(request_options: {}, **params) ⇒ Payabli::Types::RemoveDeviceResponse
Remove a cloud device from an entrypoint.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/payabli/cloud/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#add_device(request_options: {}, **params) ⇒ Payabli::Types::AddDeviceResponse
Register a cloud device to an entrypoint. See Devices Quickstart for a complete guide.
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 |
# File 'lib/payabli/cloud/client.rb', line 34 def add_device(request_options: {}, **params) params = Payabli::Internal::Types::Utils.normalize_keys(params) request_data = Payabli::Cloud::Types::DeviceEntry.new(params).to_h non_body_param_names = %w[entry idempotencyKey] body = request_data.except(*non_body_param_names) headers = {} headers["idempotencyKey"] = params[:idempotency_key] if params[:idempotency_key] headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }]).merge(headers) request = Payabli::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "Cloud/register/#{URI.encode_uri_component(params[:entry].to_s)}", headers: headers, body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Payabli::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Payabli::Types::AddDeviceResponse.load(response.body) else error_class = Payabli::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#history_device(request_options: {}, **params) ⇒ Payabli::Types::CloudQueryApiResponse
Retrieve the registration history for a device.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/payabli/cloud/client.rb', line 128 def history_device(request_options: {}, **params) params = Payabli::Internal::Types::Utils.normalize_keys(params) headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }]) request = Payabli::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "Cloud/history/#{URI.encode_uri_component(params[:entry].to_s)}/#{URI.encode_uri_component(params[:device_id].to_s)}", headers: headers, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Payabli::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Payabli::Types::CloudQueryApiResponse.load(response.body) else error_class = Payabli::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#list_device(request_options: {}, **params) ⇒ Payabli::Types::CloudQueryApiResponse
Use List devices by paypoint instead, which supports filters, sorting, and pagination.
Get a list of cloud devices registered to an entrypoint.
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/payabli/cloud/client.rb', line 171 def list_device(request_options: {}, **params) params = Payabli::Internal::Types::Utils.normalize_keys(params) query_params = {} query_params["forceRefresh"] = params[:force_refresh] if params.key?(:force_refresh) headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }]) request = Payabli::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "Cloud/list/#{URI.encode_uri_component(params[:entry].to_s)}", headers: headers, query: query_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Payabli::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Payabli::Types::CloudQueryApiResponse.load(response.body) else error_class = Payabli::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#remove_device(request_options: {}, **params) ⇒ Payabli::Types::RemoveDeviceResponse
Remove a cloud device from an entrypoint.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/payabli/cloud/client.rb', line 85 def remove_device(request_options: {}, **params) params = Payabli::Internal::Types::Utils.normalize_keys(params) headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }, { "APIKeyAuth" => [] }]) request = Payabli::Internal::JSON::Request.new( base_url: [:base_url], method: "DELETE", path: "Cloud/register/#{URI.encode_uri_component(params[:entry].to_s)}/#{URI.encode_uri_component(params[:device_id].to_s)}", headers: headers, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Payabli::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Payabli::Types::RemoveDeviceResponse.load(response.body) else error_class = Payabli::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |