Skip to content

Commit

Permalink
feat: Always use POST to normalize request serialization (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x authored Oct 30, 2023
1 parent c0a68ae commit 86728d0
Show file tree
Hide file tree
Showing 22 changed files with 109 additions and 132 deletions.
4 changes: 2 additions & 2 deletions lib/seam/clients/access_codes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ module Clients
class AccessCodes < BaseClient
def get(access_code_id)
request_seam_object(
:get,
:post,
"/access_codes/get",
Seam::AccessCode,
"access_code",
params: {access_code_id: access_code_id}
body: {access_code_id: access_code_id}
)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/seam/clients/action_attempts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ module Clients
class ActionAttempts < BaseClient
def get(action_attempt_id)
request_seam_object(
:get,
:post,
"/action_attempts/get",
Seam::ActionAttempt,
"action_attempt",
params: {action_attempt_id: action_attempt_id}
body: {action_attempt_id: action_attempt_id}
)
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/seam/clients/connect_webviews.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ module Clients
class ConnectWebviews < BaseClient
def get(connect_webview_id = nil)
request_seam_object(
:get,
:post,
"/connect_webviews/get",
Seam::ConnectWebview,
"connect_webview",
params: {connect_webview_id: connect_webview_id}
body: {connect_webview_id: connect_webview_id}
)
end

def list
request_seam_object(
:get,
:post,
"/connect_webviews/list",
Seam::ConnectWebview,
"connect_webviews",
params: {}
body: {}
)
end

Expand Down
18 changes: 9 additions & 9 deletions lib/seam/clients/connected_accounts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
module Seam
module Clients
class ConnectedAccounts < BaseClient
def get(connected_account_id_or_params)
params = if connected_account_id_or_params.is_a?(String)
{connected_account_id: connected_account_id_or_params}
def get(connected_account_id_or_body)
body = if connected_account_id_or_body.is_a?(String)
{connected_account_id: connected_account_id_or_body}
else
connected_account_id_or_params
connected_account_id_or_body
end

request_seam_object(
:get,
:post,
"/connected_accounts/get",
Seam::ConnectedAccount,
"connected_account",
params: params
body: body
)
end

def list(params = {})
def list(body = {})
request_seam_object(
:get,
:post,
"/connected_accounts/list",
Seam::ConnectedAccount,
"connected_accounts",
params: params
body: body
)
end
end
Expand Down
18 changes: 9 additions & 9 deletions lib/seam/clients/devices.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
module Seam
module Clients
class Devices < BaseClient
def list(params = {})
def list(body = {})
request_seam_object(
:get,
:post,
"/devices/list",
Seam::Device,
"devices",
params: params
body: body
)
end

def get(device_id = nil, name: nil)
request_seam_object(
:get,
:post,
"/devices/get",
Seam::Device,
"device",
params: {device_id: device_id, name: name}.compact
body: {device_id: device_id, name: name}.compact
)
end

def update(device_id: nil, is_managed: nil, name: nil, properties: nil)
request_seam(
:patch,
:post,
"/devices/update",
body: {
device_id: device_id,
Expand All @@ -36,13 +36,13 @@ def update(device_id: nil, is_managed: nil, name: nil, properties: nil)
)
end

def list_device_providers(params = {})
def list_device_providers(body = {})
request_seam_object(
:get,
:post,
"/devices/list_device_providers",
Seam::DeviceProvider,
"device_providers",
params: params
body: body
)
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/seam/clients/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ module Clients
class Events < BaseClient
def get(event_id: nil, event_type: nil, device_id: nil)
request_seam_object(
:get,
:post,
"/events/get",
Seam::Event,
"event",
params: {event_id: event_id, event_type: event_type, device_id: device_id}.compact
body: {event_id: event_id, event_type: event_type, device_id: device_id}.compact
)
end

def list(since: str, event_type: nil, event_types: nil, device_id: nil, device_ids: nil)
request_seam_object(
:get,
:post,
"/events/list",
Seam::Event,
"events",
params: {event_type: event_type, event_types: event_types, device_id: device_id,
device_ids: device_ids, since: since}.compact
body: {event_type: event_type, event_types: event_types, device_id: device_id,
device_ids: device_ids, since: since}.compact
)
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/seam/clients/locks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,23 @@ def lock_door(device_or_id)
)
end

def list(params = {})
def list(body = {})
request_seam_object(
:get,
:post,
"/locks/list",
Seam::Device,
"locks",
params: params
body: body
)
end

def get(device_or_id)
request_seam_object(
:get,
:post,
"/locks/get",
Seam::Device,
"lock",
params: {
body: {
device_id: device_id(device_or_id)
}
)
Expand Down
8 changes: 4 additions & 4 deletions lib/seam/clients/unmanaged_access_codes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ module Clients
class UnmanagedAccessCodes < BaseClient
def get(access_code_id = nil, device_id: nil, code: nil)
request_seam_object(
:get,
:post,
"/access_codes/unmanaged/get",
Seam::UnmanagedAccessCode,
"access_code",
params: {
body: {
device_id: device_id,
access_code_id: access_code_id,
code: code
Expand All @@ -19,11 +19,11 @@ def get(access_code_id = nil, device_id: nil, code: nil)

def list(device_id)
request_seam_object(
:get,
:post,
"/access_codes/unmanaged/list",
Seam::UnmanagedAccessCode,
"access_codes",
params: {device_id: device_id}
body: {device_id: device_id}
)
end

Expand Down
12 changes: 6 additions & 6 deletions lib/seam/clients/unmanaged_devices.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@ module Clients
class UnmanagedDevices < BaseClient
def get(device_id = nil, name: nil)
request_seam_object(
:get,
:post,
"/devices/unmanaged/get",
Seam::UnmanagedDevice,
"device",
params: {
body: {
device_id: device_id,
name: name
}.compact
)
end

def list(params = {})
def list(body = {})
request_seam_object(
:get,
:post,
"/devices/unmanaged/list",
Seam::UnmanagedDevice,
"devices",
params: params
body: body
)
end

def update(device_id: nil, is_managed: nil)
request_seam(
:patch,
:post,
"/devices/unmanaged/update",
body: {
device_id: device_id,
Expand Down
10 changes: 5 additions & 5 deletions lib/seam/clients/workspaces.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ module Clients
class Workspaces < BaseClient
def get(workspace_id = nil)
request_seam_object(
:get,
:post,
"/workspaces/get",
Seam::Workspace,
"workspace",
params: {workspace_id: workspace_id}
body: {workspace_id: workspace_id}
)
end

def list
request_seam_object(
:get,
:post,
"/workspaces/list",
Seam::Workspace,
"workspaces",
params: {}
body: {}
)
end

def reset_sandbox(workspace_id)
request_seam(
:post,
"/workspaces/reset_sandbox",
params: {workspace_id: workspace_id}
body: {workspace_id: workspace_id}
)
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/seam/resources/action_attempt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def wait_until_finished

def update!
response = @client.request_seam(
:get,
:post,
"/action_attempts/get",
params: {
body: {
action_attempt_id: action_attempt_id
}
)
Expand Down
20 changes: 9 additions & 11 deletions spec/clients/access_codes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,11 @@

before do
stub_seam_request(
:get, "/access_codes/get", {access_code: access_code_hash.merge(
:post, "/access_codes/get", {access_code: access_code_hash.merge(
errors: [failed_to_set_error],
warnings: [delay_in_setting_warning]
)}
).with(
query: {access_code_id: access_code_id}
)
).with { |req| req.body.source == {access_code_id: access_code_id}.to_json }
end

let(:result) { client.access_codes.get(access_code_id) }
Expand Down Expand Up @@ -86,9 +84,9 @@
)

stub_seam_request(
:get, "/action_attempts/get", {action_attempt: {result: {access_code: access_code_hash},
status: "success"}}
).with(query: {action_attempt_id: action_attempt_hash[:action_attempt_id]})
:post, "/action_attempts/get", {action_attempt: {result: {access_code: access_code_hash},
status: "success"}}
).with { |req| req.body.source == {action_attempt_id: action_attempt_hash[:action_attempt_id]}.to_json }
end

let(:result) { client.access_codes.create(**access_code_hash) }
Expand All @@ -110,14 +108,14 @@
end

stub_seam_request(
:get,
:post,
"/action_attempts/get",
{
action_attempt: {
status: "success"
}
}
).with(query: {action_attempt_id: action_attempt_hash[:action_attempt_id]})
).with { |req| req.body.source == {action_attempt_id: action_attempt_hash[:action_attempt_id]}.to_json }
end

let(:result) { client.access_codes.delete(access_code_id) }
Expand All @@ -139,14 +137,14 @@
end

stub_seam_request(
:get,
:post,
"/action_attempts/get",
{
action_attempt: {
status: "success"
}
}
).with(query: {action_attempt_id: action_attempt_hash[:action_attempt_id]})
).with { |req| req.body.source == {action_attempt_id: action_attempt_hash[:action_attempt_id]}.to_json }
end

let(:result) { client.access_codes.update(access_code_id: access_code_id, type: "ongoing") }
Expand Down
6 changes: 2 additions & 4 deletions spec/clients/action_attempts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@

before do
stub_seam_request(
:get, "/action_attempts/get", {action_attempt: action_attempt_hash}
).with(
query: {action_attempt_id: action_attempt_id}
)
:post, "/action_attempts/get", {action_attempt: action_attempt_hash}
).with { |req| req.body.source == {action_attempt_id: action_attempt_id}.to_json }
end

let(:result) { client.action_attempts.get(action_attempt_id) }
Expand Down
Loading

0 comments on commit 86728d0

Please sign in to comment.