Class: Alula::RpcResource
- Inherits:
-
Object
- Object
- Alula::RpcResource
- Defined in:
- lib/alula/rpc_resource.rb
Direct Known Subclasses
CameraGetChimeInfoProc, CameraGetFirmwareVersionProc, CameraGetInfoProc, CameraGetRecordingConfigProc, CameraGetSdStatusProc, CameraGetServerConfigProc, CameraGetStatsProc, CameraGetWifiProc, CameraSetRecordingConfigProc, CameraSetServerConfigProc, DealerDeviceStatsProc, DealerRestoreProc, DealerSuspendProc, DeviceAssignProc, DeviceCellularHistoryProc, DeviceProgramsRenewProc, DeviceRatePlanGetProc, DeviceRegisterProc, DeviceSignalAddProc, DeviceSignalDeliveredProc, DeviceSignalUpdateProc, DeviceUnassignProc, DeviceUnregisterProc, FeaturePlanCloneProc, UploadTouchpadBrandingProc, UserGetLockedProc, UserPasswordResetProc, UserPlansVideoPriceGetProc, UserTransferAccept, UserTransferAuthorize, UserTransferCancel, UserTransferDeny, UserTransferReject, UserTransferRequest, UserUnlockProc, VideoUnregisterProc
Class Method Summary collapse
-
.ok?(response) ⇒ Boolean
RPC endpoints tend to return a 200 OK even if the response failed.
- .request(http_method:, path:, payload:, handler:, wrap: true, opts: {}) ⇒ Object
- .wrap_payload(payload) ⇒ Object
Class Method Details
.ok?(response) ⇒ Boolean
RPC endpoints tend to return a 200 OK even if the response failed. Examine the response body to determine if there was an error.
27 28 29 30 31 32 |
# File 'lib/alula/rpc_resource.rb', line 27 def self.ok?(response) error = response.data['error'] && !response.data['error'].empty? errors = response.data['errors'] && !response.data['errors'].empty? !(error || errors) end |
.request(http_method:, path:, payload:, handler:, wrap: true, opts: {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/alula/rpc_resource.rb', line 5 def self.request(http_method:, path:, payload:, handler:, wrap: true, opts: {}) response = Alula::Client.request(http_method, path, wrap ? wrap_payload(payload) : payload, opts) unless response.ok? && ok?(response) error = Alula::AlulaError.for_response(response) # # Some error classifications are critical and should be raised for visibility # These errors do not contain meaningful data that an end-user can use to correct # the error. raise error if [Alula::RateLimitError, Alula::BadRequestError, Alula::ForbiddenError, Alula::UnknownError, Alula::InsufficientScopeError].include?(error.class) return error end handler.new(response) end |
.wrap_payload(payload) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/alula/rpc_resource.rb', line 34 def self.wrap_payload(payload) { id: SecureRandom.uuid, jsonrpc: '2.0', params: payload } end |