seam 2.166.0 → 2.167.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +4 -4
  3. data/README.md +55 -2
  4. data/lib/seam/action_attempt_resolver.rb +77 -7
  5. data/lib/seam/auth.rb +2 -1
  6. data/lib/seam/base_resource.rb +50 -3
  7. data/lib/seam/deep_hash_accessor.rb +11 -15
  8. data/lib/seam/errors.rb +6 -0
  9. data/lib/seam/http.rb +11 -7
  10. data/lib/seam/http_single_workspace.rb +15 -3
  11. data/lib/seam/http_without_workspace.rb +17 -7
  12. data/lib/seam/invalid_response_error.rb +17 -0
  13. data/lib/seam/options.rb +2 -1
  14. data/lib/seam/paginator.rb +34 -29
  15. data/lib/seam/request_parameters.rb +11 -0
  16. data/lib/seam/resources/access_code.rb +46 -3
  17. data/lib/seam/resources/access_grant.rb +38 -4
  18. data/lib/seam/resources/access_method.rb +18 -1
  19. data/lib/seam/resources/acs_access_group.rb +0 -17
  20. data/lib/seam/resources/acs_credential.rb +18 -1
  21. data/lib/seam/resources/acs_entrance.rb +1 -1
  22. data/lib/seam/resources/acs_system.rb +17 -31
  23. data/lib/seam/resources/acs_user.rb +0 -3
  24. data/lib/seam/resources/action_attempt.rb +4 -216
  25. data/lib/seam/resources/batch.rb +1 -1
  26. data/lib/seam/resources/client_session.rb +0 -4
  27. data/lib/seam/resources/connect_webview.rb +1 -0
  28. data/lib/seam/resources/connected_account.rb +1 -21
  29. data/lib/seam/resources/device.rb +354 -311
  30. data/lib/seam/resources/device_provider.rb +11 -13
  31. data/lib/seam/resources/event.rb +372 -151
  32. data/lib/seam/resources/instant_key.rb +1 -1
  33. data/lib/seam/resources/phone.rb +90 -2
  34. data/lib/seam/resources/space.rb +21 -1
  35. data/lib/seam/resources/unmanaged_access_code.rb +44 -4
  36. data/lib/seam/resources/unmanaged_access_grant.rb +38 -4
  37. data/lib/seam/resources/unmanaged_access_method.rb +18 -1
  38. data/lib/seam/resources/unmanaged_device.rb +108 -38
  39. data/lib/seam/resources/workspace.rb +0 -4
  40. data/lib/seam/routes/access_codes.rb +19 -23
  41. data/lib/seam/routes/access_codes_simulate.rb +1 -1
  42. data/lib/seam/routes/access_codes_unmanaged.rb +7 -5
  43. data/lib/seam/routes/access_grants.rb +24 -24
  44. data/lib/seam/routes/access_grants_unmanaged.rb +5 -4
  45. data/lib/seam/routes/access_methods.rb +20 -14
  46. data/lib/seam/routes/access_methods_unmanaged.rb +2 -2
  47. data/lib/seam/routes/acs_access_groups.rb +4 -4
  48. data/lib/seam/routes/acs_credentials.rb +4 -4
  49. data/lib/seam/routes/acs_encoders.rb +5 -5
  50. data/lib/seam/routes/acs_entrances.rb +6 -8
  51. data/lib/seam/routes/acs_systems.rb +3 -3
  52. data/lib/seam/routes/acs_users.rb +44 -34
  53. data/lib/seam/routes/action_attempts.rb +2 -2
  54. data/lib/seam/routes/cameras_live_views.rb +5 -5
  55. data/lib/seam/routes/client_sessions.rb +20 -21
  56. data/lib/seam/routes/connect_webviews.rb +3 -3
  57. data/lib/seam/routes/connected_accounts.rb +7 -5
  58. data/lib/seam/routes/customers.rb +4 -5
  59. data/lib/seam/routes/devices.rb +10 -10
  60. data/lib/seam/routes/devices_unmanaged.rb +7 -5
  61. data/lib/seam/routes/events.rb +16 -12
  62. data/lib/seam/routes/instant_keys.rb +7 -5
  63. data/lib/seam/routes/locks.rb +10 -8
  64. data/lib/seam/routes/locks_simulate.rb +2 -2
  65. data/lib/seam/routes/media.rb +1 -1
  66. data/lib/seam/routes/noise_sensors.rb +1 -1
  67. data/lib/seam/routes/noise_sensors_noise_thresholds.rb +9 -3
  68. data/lib/seam/routes/phones.rb +2 -2
  69. data/lib/seam/routes/phones_simulate.rb +1 -1
  70. data/lib/seam/routes/spaces.rb +18 -13
  71. data/lib/seam/routes/thermostats.rb +14 -18
  72. data/lib/seam/routes/thermostats_daily_programs.rb +2 -2
  73. data/lib/seam/routes/thermostats_schedules.rb +3 -3
  74. data/lib/seam/routes/user_identities.rb +24 -18
  75. data/lib/seam/routes/user_identities_unmanaged.rb +2 -2
  76. data/lib/seam/routes/webhooks.rb +3 -3
  77. data/lib/seam/routes/workspaces.rb +6 -16
  78. data/lib/seam/url_search_params_serializer.rb +2 -1
  79. data/lib/seam/version.rb +1 -1
  80. data/lib/seam/wait_for_action_attempt.rb +3 -1
  81. data/lib/seam/webhook.rb +25 -5
  82. data/lib/seam.rb +12 -6
  83. metadata +5 -2
@@ -50,7 +50,7 @@ module Seam
50
50
  def create(name:, acs_entrance_ids: nil, connected_account_ids: nil, customer_data: nil, customer_key: nil, device_ids: nil, space_key: nil)
51
51
  res = @client.post("/spaces/create", {name: name, acs_entrance_ids: acs_entrance_ids, connected_account_ids: connected_account_ids, customer_data: customer_data, customer_key: customer_key, device_ids: device_ids, space_key: space_key}.compact)
52
52
 
53
- Seam::Resources::Space.load_from_response(res.body["space"])
53
+ Seam::Resources::Space.from_http_response(res, "space", "/spaces/create")
54
54
  end
55
55
 
56
56
  # Deletes a space.
@@ -67,13 +67,15 @@ module Seam
67
67
  # @param space_key [String, nil] Unique key of the space that you want to get.
68
68
  # @return [Seam::Resources::Space] OK
69
69
  def get(space_id: nil, space_key: nil)
70
- if space_id.nil? && space_key.nil?
71
- raise TypeError, "At least one parameter is required for /spaces/get"
72
- end
70
+ Seam::RequestParameters.require_at_least_one(
71
+ "/spaces/get",
72
+ {space_id: space_id, space_key: space_key},
73
+ [:space_id, :space_key]
74
+ )
73
75
 
74
76
  res = @client.get("/spaces/get", {space_id: space_id, space_key: space_key}.compact)
75
77
 
76
- Seam::Resources::Space.load_from_response(res.body["space"])
78
+ Seam::Resources::Space.from_http_response(res, "space", "/spaces/get")
77
79
  end
78
80
 
79
81
  # Gets all related resources for one or more Spaces.
@@ -83,13 +85,15 @@ module Seam
83
85
  # @param space_keys [Array<String>, nil] Keys of the spaces that you want to get along with their related resources.
84
86
  # @return [Seam::Resources::Batch] OK
85
87
  def get_related(exclude: nil, include: nil, space_ids: nil, space_keys: nil)
86
- if exclude.nil? && include.nil? && space_ids.nil? && space_keys.nil?
87
- raise TypeError, "At least one parameter is required for /spaces/get_related"
88
- end
88
+ Seam::RequestParameters.require_at_least_one(
89
+ "/spaces/get_related",
90
+ {exclude: exclude, include: include, space_ids: space_ids, space_keys: space_keys},
91
+ [:exclude, :include, :space_ids, :space_keys]
92
+ )
89
93
 
90
94
  res = @client.get("/spaces/get_related", {exclude: exclude, include: include, space_ids: space_ids, space_keys: space_keys}.compact)
91
95
 
92
- Seam::Resources::Batch.load_from_response(res.body["batch"])
96
+ Seam::Resources::Batch.from_http_response(res, "batch", "/spaces/get_related")
93
97
  end
94
98
 
95
99
  # Returns a list of all spaces.
@@ -102,7 +106,7 @@ module Seam
102
106
  def list(customer_key: nil, limit: nil, page_cursor: nil, search: nil, space_key: nil)
103
107
  res = @client.get("/spaces/list", {customer_key: customer_key, limit: limit, page_cursor: page_cursor, search: search, space_key: space_key}.compact)
104
108
 
105
- Seam::Resources::Space.load_from_response(res.body["spaces"])
109
+ Seam::Resources::Space.list_from_http_response(res, "spaces", "/spaces/list")
106
110
  end
107
111
 
108
112
  # Removes [entrances](https://www.seam.co/docs/low-level-apis/access-systems/retrieving-entrance-details) from a specific space.
@@ -139,14 +143,15 @@ module Seam
139
143
  # @param acs_entrance_ids [Array<String>, nil] IDs of the entrances that you want to set for the space. If specified, this will replace all existing entrances.
140
144
  # @param customer_data [Hash, nil] Reservation/stay-related defaults for the space. Only the keys you provide are updated; omit a key to leave it unchanged. Pass null on a key to clear it.
141
145
  # @param device_ids [Array<String>, nil] IDs of the devices that you want to set for the space. If specified, this will replace all existing devices.
146
+ # @param geolocation [Hash, Seam::Null, nil] Geographic coordinates of the space. Pass null to clear them. Seam keeps this value until the connected PMS reports different coordinates for the space.
142
147
  # @param name [String, nil] Name of the space.
143
148
  # @param space_id [String, nil] ID of the space that you want to update.
144
149
  # @param space_key [String, nil] Unique key of the space that you want to update.
145
150
  # @return [Seam::Resources::Space] OK
146
- def update(acs_entrance_ids: nil, customer_data: nil, device_ids: nil, name: nil, space_id: nil, space_key: nil)
147
- res = @client.patch("/spaces/update", {acs_entrance_ids: acs_entrance_ids, customer_data: customer_data, device_ids: device_ids, name: name, space_id: space_id, space_key: space_key}.compact)
151
+ def update(acs_entrance_ids: nil, customer_data: nil, device_ids: nil, geolocation: nil, name: nil, space_id: nil, space_key: nil)
152
+ res = @client.patch("/spaces/update", {acs_entrance_ids: acs_entrance_ids, customer_data: customer_data, device_ids: device_ids, geolocation: geolocation, name: name, space_id: space_id, space_key: space_key}.compact)
148
153
 
149
- Seam::Resources::Space.load_from_response(res.body["space"])
154
+ Seam::Resources::Space.from_http_response(res, "space", "/spaces/update")
150
155
  end
151
156
  end
152
157
  end
@@ -31,7 +31,7 @@ module Seam
31
31
 
32
32
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
33
33
 
34
- Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
34
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.from_http_response(res, "action_attempt", "/thermostats/activate_climate_preset"), @client, wait_for_action_attempt)
35
35
  end
36
36
 
37
37
  # Returns a specified [thermostat](https://www.seam.co/docs/capability-guides/thermostats) to its [weekly program](https://www.seam.co/docs/capability-guides/thermostats/creating-and-managing-thermostat-programs), the schedule that is configured on the device itself, releasing any hold that Seam has set. Seam stops managing the thermostat's climate until you [activate a climate preset](https://www.seam.co/docs/capability-guides/thermostats/configure-current-climate-settings), make a direct climate setting change, or one of the thermostat's [scheduled](https://www.seam.co/docs/capability-guides/thermostats/creating-and-managing-thermostat-schedules) presets reaches its activation time.
@@ -42,7 +42,7 @@ module Seam
42
42
 
43
43
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
44
44
 
45
- Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
45
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.from_http_response(res, "action_attempt", "/thermostats/activate_weekly_program"), @client, wait_for_action_attempt)
46
46
  end
47
47
 
48
48
  # Sets a specified [thermostat](https://www.seam.co/docs/capability-guides/thermostats) to [cool mode](https://www.seam.co/docs/capability-guides/thermostats/configure-current-climate-settings).
@@ -55,7 +55,7 @@ module Seam
55
55
 
56
56
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
57
57
 
58
- Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
58
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.from_http_response(res, "action_attempt", "/thermostats/cool"), @client, wait_for_action_attempt)
59
59
  end
60
60
 
61
61
  # Creates a [climate preset](https://www.seam.co/docs/capability-guides/thermostats/creating-and-managing-climate-presets) for a specified [thermostat](https://www.seam.co/docs/capability-guides/thermostats).
@@ -69,12 +69,10 @@ module Seam
69
69
  # @param heating_set_point_celsius [Float, nil] Temperature to which the thermostat should heat (in °C). See also [Set Points](https://www.seam.co/docs/capability-guides/thermostats/understanding-thermostat-concepts/set-points).
70
70
  # @param heating_set_point_fahrenheit [Float, nil] Temperature to which the thermostat should heat (in °F). See also [Set Points](https://www.seam.co/docs/capability-guides/thermostats/understanding-thermostat-concepts/set-points).
71
71
  # @param hvac_mode_setting [String, nil] Desired [HVAC mode](https://www.seam.co/docs/capability-guides/thermostats/understanding-thermostat-concepts/hvac-mode) setting, such as `heat`, `cool`, `heat_cool`, or `off`.
72
- # @param manual_override_allowed [Boolean, nil] Indicates whether a person at the thermostat or using the API can change the thermostat's settings.
73
- # @deprecated manual_override_allowed: Use 'thermostat_schedule.is_override_allowed'
74
72
  # @param name [String, Seam::Null, nil] User-friendly name to identify the [climate preset](https://www.seam.co/docs/capability-guides/thermostats/creating-and-managing-climate-presets).
75
73
  # @return [nil] OK
76
- def create_climate_preset(climate_preset_key:, device_id:, climate_preset_mode: nil, cooling_set_point_celsius: nil, cooling_set_point_fahrenheit: nil, ecobee_metadata: nil, fan_mode_setting: nil, heating_set_point_celsius: nil, heating_set_point_fahrenheit: nil, hvac_mode_setting: nil, manual_override_allowed: nil, name: nil)
77
- @client.post("/thermostats/create_climate_preset", {climate_preset_key: climate_preset_key, device_id: device_id, climate_preset_mode: climate_preset_mode, cooling_set_point_celsius: cooling_set_point_celsius, cooling_set_point_fahrenheit: cooling_set_point_fahrenheit, ecobee_metadata: ecobee_metadata, fan_mode_setting: fan_mode_setting, heating_set_point_celsius: heating_set_point_celsius, heating_set_point_fahrenheit: heating_set_point_fahrenheit, hvac_mode_setting: hvac_mode_setting, manual_override_allowed: manual_override_allowed, name: name}.compact)
74
+ def create_climate_preset(climate_preset_key:, device_id:, climate_preset_mode: nil, cooling_set_point_celsius: nil, cooling_set_point_fahrenheit: nil, ecobee_metadata: nil, fan_mode_setting: nil, heating_set_point_celsius: nil, heating_set_point_fahrenheit: nil, hvac_mode_setting: nil, name: nil)
75
+ @client.post("/thermostats/create_climate_preset", {climate_preset_key: climate_preset_key, device_id: device_id, climate_preset_mode: climate_preset_mode, cooling_set_point_celsius: cooling_set_point_celsius, cooling_set_point_fahrenheit: cooling_set_point_fahrenheit, ecobee_metadata: ecobee_metadata, fan_mode_setting: fan_mode_setting, heating_set_point_celsius: heating_set_point_celsius, heating_set_point_fahrenheit: heating_set_point_fahrenheit, hvac_mode_setting: hvac_mode_setting, name: name}.compact)
78
76
 
79
77
  nil
80
78
  end
@@ -99,7 +97,7 @@ module Seam
99
97
 
100
98
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
101
99
 
102
- Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
100
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.from_http_response(res, "action_attempt", "/thermostats/heat"), @client, wait_for_action_attempt)
103
101
  end
104
102
 
105
103
  # Sets a specified [thermostat](https://www.seam.co/docs/capability-guides/thermostats) to [heat-cool ("auto") mode](https://www.seam.co/docs/capability-guides/thermostats/configure-current-climate-settings).
@@ -114,7 +112,7 @@ module Seam
114
112
 
115
113
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
116
114
 
117
- Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
115
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.from_http_response(res, "action_attempt", "/thermostats/heat_cool"), @client, wait_for_action_attempt)
118
116
  end
119
117
 
120
118
  # Returns a list of all [thermostats](https://www.seam.co/docs/capability-guides/thermostats).
@@ -128,7 +126,7 @@ module Seam
128
126
  def list(connect_webview_id: nil, connected_account_id: nil, customer_key: nil, device_type: nil, device_types: nil, manufacturer: nil)
129
127
  res = @client.get("/thermostats/list", {connect_webview_id: connect_webview_id, connected_account_id: connected_account_id, customer_key: customer_key, device_type: device_type, device_types: device_types, manufacturer: manufacturer}.compact)
130
128
 
131
- Seam::Resources::Device.load_from_response(res.body["devices"])
129
+ Seam::Resources::Device.list_from_http_response(res, "devices", "/thermostats/list")
132
130
  end
133
131
 
134
132
  # Sets a specified [thermostat](https://www.seam.co/docs/capability-guides/thermostats) to ["off" mode](https://www.seam.co/docs/capability-guides/thermostats/configure-current-climate-settings).
@@ -139,7 +137,7 @@ module Seam
139
137
 
140
138
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
141
139
 
142
- Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
140
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.from_http_response(res, "action_attempt", "/thermostats/off"), @client, wait_for_action_attempt)
143
141
  end
144
142
 
145
143
  # Sets a specified [climate preset](https://www.seam.co/docs/capability-guides/thermostats/creating-and-managing-climate-presets) as the ["fallback"](https://www.seam.co/docs/capability-guides/thermostats/creating-and-managing-climate-presets/setting-the-fallback-climate-preset) preset for a specified [thermostat](https://www.seam.co/docs/capability-guides/thermostats).
@@ -163,7 +161,7 @@ module Seam
163
161
 
164
162
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
165
163
 
166
- Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
164
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.from_http_response(res, "action_attempt", "/thermostats/set_fan_mode"), @client, wait_for_action_attempt)
167
165
  end
168
166
 
169
167
  # Sets the [HVAC mode](https://www.seam.co/docs/capability-guides/thermostats/configure-current-climate-settings) for a specified [thermostat](https://www.seam.co/docs/capability-guides/thermostats).
@@ -179,7 +177,7 @@ module Seam
179
177
 
180
178
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
181
179
 
182
- Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
180
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.from_http_response(res, "action_attempt", "/thermostats/set_hvac_mode"), @client, wait_for_action_attempt)
183
181
  end
184
182
 
185
183
  # Sets a [temperature threshold](https://www.seam.co/docs/capability-guides/thermostats/setting-and-monitoring-temperature-thresholds) for a specified thermostat. Seam emits a `thermostat.temperature_threshold_exceeded` event and adds a warning on a thermostat if it reports a temperature outside the threshold range.
@@ -206,12 +204,10 @@ module Seam
206
204
  # @param heating_set_point_celsius [Float, nil] Temperature to which the thermostat should heat (in °C). See also [Set Points](https://www.seam.co/docs/capability-guides/thermostats/understanding-thermostat-concepts/set-points).
207
205
  # @param heating_set_point_fahrenheit [Float, nil] Temperature to which the thermostat should heat (in °F). See also [Set Points](https://www.seam.co/docs/capability-guides/thermostats/understanding-thermostat-concepts/set-points).
208
206
  # @param hvac_mode_setting [String, nil] Desired [HVAC mode](https://www.seam.co/docs/capability-guides/thermostats/understanding-thermostat-concepts/hvac-mode) setting, such as `heat`, `cool`, `heat_cool`, or `off`.
209
- # @param manual_override_allowed [Boolean, nil] Indicates whether a person at the thermostat can change the thermostat's settings. See [Specifying Manual Override Permissions](https://www.seam.co/docs/capability-guides/thermostats/creating-and-managing-thermostat-schedules#specifying-manual-override-permissions).
210
- # @deprecated manual_override_allowed: Use 'thermostat_schedule.is_override_allowed'
211
207
  # @param name [String, Seam::Null, nil] User-friendly name to identify the [climate preset](https://www.seam.co/docs/capability-guides/thermostats/creating-and-managing-climate-presets).
212
208
  # @return [nil] OK
213
- def update_climate_preset(climate_preset_key:, device_id:, climate_preset_mode: nil, cooling_set_point_celsius: nil, cooling_set_point_fahrenheit: nil, ecobee_metadata: nil, fan_mode_setting: nil, heating_set_point_celsius: nil, heating_set_point_fahrenheit: nil, hvac_mode_setting: nil, manual_override_allowed: nil, name: nil)
214
- @client.patch("/thermostats/update_climate_preset", {climate_preset_key: climate_preset_key, device_id: device_id, climate_preset_mode: climate_preset_mode, cooling_set_point_celsius: cooling_set_point_celsius, cooling_set_point_fahrenheit: cooling_set_point_fahrenheit, ecobee_metadata: ecobee_metadata, fan_mode_setting: fan_mode_setting, heating_set_point_celsius: heating_set_point_celsius, heating_set_point_fahrenheit: heating_set_point_fahrenheit, hvac_mode_setting: hvac_mode_setting, manual_override_allowed: manual_override_allowed, name: name}.compact)
209
+ def update_climate_preset(climate_preset_key:, device_id:, climate_preset_mode: nil, cooling_set_point_celsius: nil, cooling_set_point_fahrenheit: nil, ecobee_metadata: nil, fan_mode_setting: nil, heating_set_point_celsius: nil, heating_set_point_fahrenheit: nil, hvac_mode_setting: nil, name: nil)
210
+ @client.patch("/thermostats/update_climate_preset", {climate_preset_key: climate_preset_key, device_id: device_id, climate_preset_mode: climate_preset_mode, cooling_set_point_celsius: cooling_set_point_celsius, cooling_set_point_fahrenheit: cooling_set_point_fahrenheit, ecobee_metadata: ecobee_metadata, fan_mode_setting: fan_mode_setting, heating_set_point_celsius: heating_set_point_celsius, heating_set_point_fahrenheit: heating_set_point_fahrenheit, hvac_mode_setting: hvac_mode_setting, name: name}.compact)
215
211
 
216
212
  nil
217
213
  end
@@ -231,7 +227,7 @@ module Seam
231
227
 
232
228
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
233
229
 
234
- Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
230
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.from_http_response(res, "action_attempt", "/thermostats/update_weekly_program"), @client, wait_for_action_attempt)
235
231
  end
236
232
  end
237
233
  end
@@ -18,7 +18,7 @@ module Seam
18
18
  def create(device_id:, name:, periods:)
19
19
  res = @client.post("/thermostats/daily_programs/create", {device_id: device_id, name: name, periods: periods}.compact)
20
20
 
21
- Seam::Resources::ThermostatDailyProgram.load_from_response(res.body["thermostat_daily_program"])
21
+ Seam::Resources::ThermostatDailyProgram.from_http_response(res, "thermostat_daily_program", "/thermostats/daily_programs/create")
22
22
  end
23
23
 
24
24
  # Deletes a thermostat daily program.
@@ -40,7 +40,7 @@ module Seam
40
40
 
41
41
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
42
42
 
43
- Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
43
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.from_http_response(res, "action_attempt", "/thermostats/daily_programs/update"), @client, wait_for_action_attempt)
44
44
  end
45
45
  end
46
46
  end
@@ -20,7 +20,7 @@ module Seam
20
20
  def create(climate_preset_key:, device_id:, ends_at:, starts_at:, is_override_allowed: nil, max_override_period_minutes: nil, name: nil)
21
21
  res = @client.post("/thermostats/schedules/create", {climate_preset_key: climate_preset_key, device_id: device_id, ends_at: ends_at, starts_at: starts_at, is_override_allowed: is_override_allowed, max_override_period_minutes: max_override_period_minutes, name: name}.compact)
22
22
 
23
- Seam::Resources::ThermostatSchedule.load_from_response(res.body["thermostat_schedule"])
23
+ Seam::Resources::ThermostatSchedule.from_http_response(res, "thermostat_schedule", "/thermostats/schedules/create")
24
24
  end
25
25
 
26
26
  # Deletes a [thermostat schedule](https://www.seam.co/docs/capability-guides/thermostats/creating-and-managing-thermostat-schedules) for a specified [thermostat](https://www.seam.co/docs/capability-guides/thermostats).
@@ -38,7 +38,7 @@ module Seam
38
38
  def get(thermostat_schedule_id:)
39
39
  res = @client.get("/thermostats/schedules/get", {thermostat_schedule_id: thermostat_schedule_id}.compact)
40
40
 
41
- Seam::Resources::ThermostatSchedule.load_from_response(res.body["thermostat_schedule"])
41
+ Seam::Resources::ThermostatSchedule.from_http_response(res, "thermostat_schedule", "/thermostats/schedules/get")
42
42
  end
43
43
 
44
44
  # Returns a list of all [thermostat schedules](https://www.seam.co/docs/capability-guides/thermostats/creating-and-managing-thermostat-schedules) for a specified [thermostat](https://www.seam.co/docs/capability-guides/thermostats).
@@ -48,7 +48,7 @@ module Seam
48
48
  def list(device_id:, user_identifier_key: nil)
49
49
  res = @client.get("/thermostats/schedules/list", {device_id: device_id, user_identifier_key: user_identifier_key}.compact)
50
50
 
51
- Seam::Resources::ThermostatSchedule.load_from_response(res.body["thermostat_schedules"])
51
+ Seam::Resources::ThermostatSchedule.list_from_http_response(res, "thermostat_schedules", "/thermostats/schedules/list")
52
52
  end
53
53
 
54
54
  # Updates a specified [thermostat schedule](https://www.seam.co/docs/capability-guides/thermostats/creating-and-managing-thermostat-schedules).
@@ -29,15 +29,16 @@ module Seam
29
29
 
30
30
  # Creates a new [user identity](https://www.seam.co/docs/capability-guides/mobile-access/managing-mobile-app-user-accounts-with-user-identities#what-is-a-user-identity).
31
31
  # @param acs_system_ids [Array<String>, nil] List of access system IDs to associate with the new user identity through access system users. If there's no user with the same email address or phone number in the specified access systems, a new access system user is created. If there is an existing user with the same email or phone number in the specified access systems, the user is linked to the user identity.
32
+ # @param customer_key [String, nil] Customer key of the customer that owns the new user identity. Set it when the user identity will be used in access grants created through that customer's client session or Customer Portal.
32
33
  # @param email_address [String, Seam::Null, nil] Unique email address for the new user identity.
33
34
  # @param full_name [String, Seam::Null, nil] Full name of the user associated with the new user identity.
34
35
  # @param phone_number [String, Seam::Null, nil] Unique phone number for the new user identity in E.164 format (for example, +15555550100).
35
36
  # @param user_identity_key [String, Seam::Null, nil] Unique key for the new user identity.
36
37
  # @return [Seam::Resources::UserIdentity] OK
37
- def create(acs_system_ids: nil, email_address: nil, full_name: nil, phone_number: nil, user_identity_key: nil)
38
- res = @client.post("/user_identities/create", {acs_system_ids: acs_system_ids, email_address: email_address, full_name: full_name, phone_number: phone_number, user_identity_key: user_identity_key}.compact)
38
+ def create(acs_system_ids: nil, customer_key: nil, email_address: nil, full_name: nil, phone_number: nil, user_identity_key: nil)
39
+ res = @client.post("/user_identities/create", {acs_system_ids: acs_system_ids, customer_key: customer_key, email_address: email_address, full_name: full_name, phone_number: phone_number, user_identity_key: user_identity_key}.compact)
39
40
 
40
- Seam::Resources::UserIdentity.load_from_response(res.body["user_identity"])
41
+ Seam::Resources::UserIdentity.from_http_response(res, "user_identity", "/user_identities/create")
41
42
  end
42
43
 
43
44
  # Deletes a specified [user identity](https://www.seam.co/docs/capability-guides/mobile-access/managing-mobile-app-user-accounts-with-user-identities#what-is-a-user-identity). This deletes the user identity and all associated resources, including any [credentials](https://www.seam.co/docs/api/acs/credentials/object), [acs users](https://www.seam.co/docs/api/acs/users/object) and [client sessions](https://www.seam.co/docs/api/client_sessions/object).
@@ -57,7 +58,7 @@ module Seam
57
58
  def generate_instant_key(user_identity_id:, customization_profile_id: nil, max_use_count: nil)
58
59
  res = @client.post("/user_identities/generate_instant_key", {user_identity_id: user_identity_id, customization_profile_id: customization_profile_id, max_use_count: max_use_count}.compact)
59
60
 
60
- Seam::Resources::InstantKey.load_from_response(res.body["instant_key"])
61
+ Seam::Resources::InstantKey.from_http_response(res, "instant_key", "/user_identities/generate_instant_key")
61
62
  end
62
63
 
63
64
  # Returns a specified [user identity](https://www.seam.co/docs/capability-guides/mobile-access/managing-mobile-app-user-accounts-with-user-identities#what-is-a-user-identity).
@@ -65,13 +66,15 @@ module Seam
65
66
  # @param user_identity_key [String, nil]
66
67
  # @return [Seam::Resources::UserIdentity] OK
67
68
  def get(user_identity_id: nil, user_identity_key: nil)
68
- if user_identity_id.nil? && user_identity_key.nil?
69
- raise TypeError, "At least one parameter is required for /user_identities/get"
70
- end
69
+ Seam::RequestParameters.require_at_least_one(
70
+ "/user_identities/get",
71
+ {user_identity_id: user_identity_id, user_identity_key: user_identity_key},
72
+ [:user_identity_id, :user_identity_key]
73
+ )
71
74
 
72
75
  res = @client.get("/user_identities/get", {user_identity_id: user_identity_id, user_identity_key: user_identity_key}.compact)
73
76
 
74
- Seam::Resources::UserIdentity.load_from_response(res.body["user_identity"])
77
+ Seam::Resources::UserIdentity.from_http_response(res, "user_identity", "/user_identities/get")
75
78
  end
76
79
 
77
80
  # Grants a specified [user identity](https://www.seam.co/docs/capability-guides/mobile-access/managing-mobile-app-user-accounts-with-user-identities#what-is-a-user-identity) access to a specified [device](https://www.seam.co/docs/core-concepts/devices).
@@ -87,15 +90,16 @@ module Seam
87
90
  # Returns a list of all [user identities](https://www.seam.co/docs/capability-guides/mobile-access/managing-mobile-app-user-accounts-with-user-identities#what-is-a-user-identity).
88
91
  # @param created_before [Time, nil] Timestamp by which to limit returned user identities. Returns user identities created before this timestamp.
89
92
  # @param credential_manager_acs_system_id [String, nil] `acs_system_id` of the credential manager by which you want to filter the list of user identities.
93
+ # @param customer_key [String, nil] Customer key for which you want to list user identities.
90
94
  # @param limit [Integer, nil] Maximum number of records to return per page.
91
95
  # @param page_cursor [String, Seam::Null, nil] Identifies the specific page of results to return, obtained from the previous page's `next_page_cursor`.
92
96
  # @param search [String, nil] String for which to search. Filters returned user identities to include all records that satisfy a partial match using `full_name`, `phone_number`, `email_address` or `user_identity_id`.
93
97
  # @param user_identity_ids [Array<String>, nil] Array of user identity IDs by which to filter the list of user identities.
94
98
  # @return [Seam::Resources::UserIdentity] OK
95
- def list(created_before: nil, credential_manager_acs_system_id: nil, limit: nil, page_cursor: nil, search: nil, user_identity_ids: nil)
96
- res = @client.get("/user_identities/list", {created_before: created_before, credential_manager_acs_system_id: credential_manager_acs_system_id, limit: limit, page_cursor: page_cursor, search: search, user_identity_ids: user_identity_ids}.compact)
99
+ def list(created_before: nil, credential_manager_acs_system_id: nil, customer_key: nil, limit: nil, page_cursor: nil, search: nil, user_identity_ids: nil)
100
+ res = @client.get("/user_identities/list", {created_before: created_before, credential_manager_acs_system_id: credential_manager_acs_system_id, customer_key: customer_key, limit: limit, page_cursor: page_cursor, search: search, user_identity_ids: user_identity_ids}.compact)
97
101
 
98
- Seam::Resources::UserIdentity.load_from_response(res.body["user_identities"])
102
+ Seam::Resources::UserIdentity.list_from_http_response(res, "user_identities", "/user_identities/list")
99
103
  end
100
104
 
101
105
  # Returns a list of all [devices](https://www.seam.co/docs/core-concepts/devices) associated with a specified [user identity](https://www.seam.co/docs/capability-guides/mobile-access/managing-mobile-app-user-accounts-with-user-identities#what-is-a-user-identity). This includes devices derived from the access grants assigned to the user identity and devices directly linked to the user identity.
@@ -104,7 +108,7 @@ module Seam
104
108
  def list_accessible_devices(user_identity_id:)
105
109
  res = @client.get("/user_identities/list_accessible_devices", {user_identity_id: user_identity_id}.compact)
106
110
 
107
- Seam::Resources::Device.load_from_response(res.body["devices"])
111
+ Seam::Resources::Device.list_from_http_response(res, "devices", "/user_identities/list_accessible_devices")
108
112
  end
109
113
 
110
114
  # Returns a list of all [ACS entrances](https://www.seam.co/docs/api/acs/entrances/object) accessible to a specified [user identity](https://www.seam.co/docs/capability-guides/mobile-access/managing-mobile-app-user-accounts-with-user-identities#what-is-a-user-identity). This includes entrances derived from the access grants assigned to the user identity and entrances accessible through ACS users linked to the user identity.
@@ -113,7 +117,7 @@ module Seam
113
117
  def list_accessible_entrances(user_identity_id:)
114
118
  res = @client.get("/user_identities/list_accessible_entrances", {user_identity_id: user_identity_id}.compact)
115
119
 
116
- Seam::Resources::AcsEntrance.load_from_response(res.body["acs_entrances"])
120
+ Seam::Resources::AcsEntrance.list_from_http_response(res, "acs_entrances", "/user_identities/list_accessible_entrances")
117
121
  end
118
122
 
119
123
  # Returns a list of all [access systems](https://www.seam.co/docs/low-level-apis/access-systems) associated with a specified [user identity](https://www.seam.co/docs/capability-guides/mobile-access/managing-mobile-app-user-accounts-with-user-identities#what-is-a-user-identity).
@@ -122,7 +126,7 @@ module Seam
122
126
  def list_acs_systems(user_identity_id:)
123
127
  res = @client.get("/user_identities/list_acs_systems", {user_identity_id: user_identity_id}.compact)
124
128
 
125
- Seam::Resources::AcsSystem.load_from_response(res.body["acs_systems"])
129
+ Seam::Resources::AcsSystem.list_from_http_response(res, "acs_systems", "/user_identities/list_acs_systems")
126
130
  end
127
131
 
128
132
  # Returns a list of all [access system users](https://www.seam.co/docs/low-level-apis/access-systems/user-management) assigned to a specified [user identity](https://www.seam.co/docs/capability-guides/mobile-access/managing-mobile-app-user-accounts-with-user-identities#what-is-a-user-identity).
@@ -131,7 +135,7 @@ module Seam
131
135
  def list_acs_users(user_identity_id:)
132
136
  res = @client.get("/user_identities/list_acs_users", {user_identity_id: user_identity_id}.compact)
133
137
 
134
- Seam::Resources::AcsUser.load_from_response(res.body["acs_users"])
138
+ Seam::Resources::AcsUser.list_from_http_response(res, "acs_users", "/user_identities/list_acs_users")
135
139
  end
136
140
 
137
141
  # Merges one or more [user identities](https://www.seam.co/docs/capability-guides/mobile-access/managing-mobile-app-user-accounts-with-user-identities#what-is-a-user-identity) into a primary user identity, for when the same person ended up with more than one user identity.
@@ -147,9 +151,11 @@ module Seam
147
151
  # @param user_identity_key [String, nil] Key of the primary user identity to keep.
148
152
  # @return [nil] OK
149
153
  def merge(merged_user_identity_ids: nil, merged_user_identity_keys: nil, user_identity_id: nil, user_identity_key: nil)
150
- if merged_user_identity_ids.nil? && merged_user_identity_keys.nil? && user_identity_id.nil? && user_identity_key.nil?
151
- raise TypeError, "At least one parameter is required for /user_identities/merge"
152
- end
154
+ Seam::RequestParameters.require_at_least_one(
155
+ "/user_identities/merge",
156
+ {merged_user_identity_ids: merged_user_identity_ids, merged_user_identity_keys: merged_user_identity_keys, user_identity_id: user_identity_id, user_identity_key: user_identity_key},
157
+ [:merged_user_identity_ids, :merged_user_identity_keys, :user_identity_id, :user_identity_key]
158
+ )
153
159
 
154
160
  @client.post("/user_identities/merge", {merged_user_identity_ids: merged_user_identity_ids, merged_user_identity_keys: merged_user_identity_keys, user_identity_id: user_identity_id, user_identity_key: user_identity_key}.compact)
155
161
 
@@ -14,7 +14,7 @@ module Seam
14
14
  def get(user_identity_id:)
15
15
  res = @client.get("/user_identities/unmanaged/get", {user_identity_id: user_identity_id}.compact)
16
16
 
17
- Seam::Resources::UnmanagedUserIdentity.load_from_response(res.body["user_identity"])
17
+ Seam::Resources::UnmanagedUserIdentity.from_http_response(res, "user_identity", "/user_identities/unmanaged/get")
18
18
  end
19
19
 
20
20
  # Returns a list of all unmanaged [user identities](https://www.seam.co/docs/capability-guides/mobile-access/managing-mobile-app-user-accounts-with-user-identities#what-is-a-user-identity) (where is_managed = false).
@@ -26,7 +26,7 @@ module Seam
26
26
  def list(created_before: nil, limit: nil, page_cursor: nil, search: nil)
27
27
  res = @client.get("/user_identities/unmanaged/list", {created_before: created_before, limit: limit, page_cursor: page_cursor, search: search}.compact)
28
28
 
29
- Seam::Resources::UnmanagedUserIdentity.load_from_response(res.body["user_identities"])
29
+ Seam::Resources::UnmanagedUserIdentity.list_from_http_response(res, "user_identities", "/user_identities/unmanaged/list")
30
30
  end
31
31
 
32
32
  # Updates an unmanaged [user identity](https://www.seam.co/docs/capability-guides/mobile-access/managing-mobile-app-user-accounts-with-user-identities#what-is-a-user-identity) to make it managed.
@@ -15,7 +15,7 @@ module Seam
15
15
  def create(url:, event_types: nil)
16
16
  res = @client.post("/webhooks/create", {url: url, event_types: event_types}.compact)
17
17
 
18
- Seam::Resources::Webhook.load_from_response(res.body["webhook"])
18
+ Seam::Resources::Webhook.from_http_response(res, "webhook", "/webhooks/create")
19
19
  end
20
20
 
21
21
  # Deletes a specified [webhook](https://www.seam.co/docs/developer-tools/webhooks).
@@ -33,7 +33,7 @@ module Seam
33
33
  def get(webhook_id:)
34
34
  res = @client.get("/webhooks/get", {webhook_id: webhook_id}.compact)
35
35
 
36
- Seam::Resources::Webhook.load_from_response(res.body["webhook"])
36
+ Seam::Resources::Webhook.from_http_response(res, "webhook", "/webhooks/get")
37
37
  end
38
38
 
39
39
  # Returns a list of all [webhooks](https://www.seam.co/docs/developer-tools/webhooks).
@@ -41,7 +41,7 @@ module Seam
41
41
  def list
42
42
  res = @client.get("/webhooks/list")
43
43
 
44
- Seam::Resources::Webhook.load_from_response(res.body["webhooks"])
44
+ Seam::Resources::Webhook.list_from_http_response(res, "webhooks", "/webhooks/list")
45
45
  end
46
46
 
47
47
  # Updates a specified [webhook](https://www.seam.co/docs/developer-tools/webhooks).
@@ -12,25 +12,15 @@ module Seam
12
12
 
13
13
  # Creates a new [workspace](https://www.seam.co/docs/core-concepts/workspaces).
14
14
  # @param name [String] Name of the new workspace.
15
- # @param company_name [String, nil] Company name for the new workspace.
16
- # @deprecated company_name: Use `connect_partner_name` instead.
17
15
  # @param connect_partner_name [String, Seam::Null, nil] Connect partner name for the new workspace.
18
16
  # @param connect_webview_customization [Hash, nil] [Connect Webview](https://www.seam.co/docs/core-concepts/connect-webviews) customizations for the new workspace. See also [Customize the Look and Feel of Your Connect Webviews](https://www.seam.co/docs/core-concepts/connect-webviews/customizing-connect-webviews#customize-the-look-and-feel-of-your-connect-webviews).
19
17
  # @param is_sandbox [Boolean, nil] Indicates whether the new workspace is a [sandbox workspace](https://www.seam.co/docs/core-concepts/workspaces#sandbox-workspaces).
20
18
  # @param organization_id [String, nil] ID of the organization to associate with the new workspace. If omitted, the new workspace is associated with the organization that you administer, if you administer exactly one. If you administer no organization, Seam creates one for you and associates the new workspace with it.
21
- # @param webview_logo_shape [String, nil]
22
- # @deprecated webview_logo_shape: Use `connect_webview_customization.webview_logo_shape` instead.
23
- # @param webview_primary_button_color [String, nil]
24
- # @deprecated webview_primary_button_color: Use `connect_webview_customization.webview_primary_button_color` instead.
25
- # @param webview_primary_button_text_color [String, nil]
26
- # @deprecated webview_primary_button_text_color: Use `connect_webview_customization.webview_primary_button_text_color` instead.
27
- # @param webview_success_message [String, nil]
28
- # @deprecated webview_success_message: Use `connect_webview_customization.webview_success_message` instead.
29
19
  # @return [Seam::Resources::Workspace] OK
30
- def create(name:, company_name: nil, connect_partner_name: nil, connect_webview_customization: nil, is_sandbox: nil, organization_id: nil, webview_logo_shape: nil, webview_primary_button_color: nil, webview_primary_button_text_color: nil, webview_success_message: nil)
31
- res = @client.post("/workspaces/create", {name: name, company_name: company_name, connect_partner_name: connect_partner_name, connect_webview_customization: connect_webview_customization, is_sandbox: is_sandbox, organization_id: organization_id, webview_logo_shape: webview_logo_shape, webview_primary_button_color: webview_primary_button_color, webview_primary_button_text_color: webview_primary_button_text_color, webview_success_message: webview_success_message}.compact)
20
+ def create(name:, connect_partner_name: nil, connect_webview_customization: nil, is_sandbox: nil, organization_id: nil)
21
+ res = @client.post("/workspaces/create", {name: name, connect_partner_name: connect_partner_name, connect_webview_customization: connect_webview_customization, is_sandbox: is_sandbox, organization_id: organization_id}.compact)
32
22
 
33
- Seam::Resources::Workspace.load_from_response(res.body["workspace"])
23
+ Seam::Resources::Workspace.from_http_response(res, "workspace", "/workspaces/create")
34
24
  end
35
25
 
36
26
  # Returns the [workspace](https://www.seam.co/docs/core-concepts/workspaces) associated with the authentication value.
@@ -38,7 +28,7 @@ module Seam
38
28
  def get
39
29
  res = @client.get("/workspaces/get")
40
30
 
41
- Seam::Resources::Workspace.load_from_response(res.body["workspace"])
31
+ Seam::Resources::Workspace.from_http_response(res, "workspace", "/workspaces/get")
42
32
  end
43
33
 
44
34
  # Returns a list of [workspaces](https://www.seam.co/docs/core-concepts/workspaces) associated with the authentication value.
@@ -46,7 +36,7 @@ module Seam
46
36
  def list
47
37
  res = @client.get("/workspaces/list")
48
38
 
49
- Seam::Resources::Workspace.load_from_response(res.body["workspaces"])
39
+ Seam::Resources::Workspace.list_from_http_response(res, "workspaces", "/workspaces/list")
50
40
  end
51
41
 
52
42
  # Resets the [sandbox workspace](https://www.seam.co/docs/core-concepts/workspaces#sandbox-workspaces) associated with the authentication value. Note that this endpoint is only available for sandbox workspaces.
@@ -56,7 +46,7 @@ module Seam
56
46
 
57
47
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
58
48
 
59
- Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
49
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.from_http_response(res, "action_attempt", "/workspaces/reset_sandbox"), @client, wait_for_action_attempt)
60
50
  end
61
51
 
62
52
  # Updates the [workspace](https://www.seam.co/docs/core-concepts/workspaces) associated with the authentication value.
@@ -2,11 +2,12 @@
2
2
 
3
3
  require "date"
4
4
 
5
+ require_relative "errors"
5
6
  require_relative "null"
6
7
  require_relative "url_search_params"
7
8
 
8
9
  module Seam
9
- class UnserializableParamError < StandardError
10
+ class UnserializableParamError < Seam::Error
10
11
  attr_reader :param_name
11
12
 
12
13
  def initialize(param_name, reason)
data/lib/seam/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Seam
4
- VERSION = "2.166.0"
4
+ VERSION = "2.167.0"
5
5
  end
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "errors"
4
+
3
5
  module Seam
4
- class ActionAttemptError < StandardError
6
+ class ActionAttemptError < Seam::Error
5
7
  attr_reader :action_attempt
6
8
 
7
9
  def initialize(message, action_attempt)
data/lib/seam/webhook.rb CHANGED
@@ -1,15 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "svix/webhook"
4
- require "svix/errors"
3
+ require "json"
4
+ require "svix"
5
5
  require_relative "base_resource"
6
+ require_relative "errors"
6
7
  require_relative "resources/event"
7
8
 
8
9
  module Seam
9
10
  WebhookVerificationError = Svix::WebhookVerificationError
10
11
 
12
+ class InvalidWebhookPayloadError < Seam::Error
13
+ end
14
+
11
15
  class Webhook
12
- def initialize(secret)
16
+ def initialize(secret = ENV["SEAM_WEBHOOK_SECRET"])
17
+ unless secret.is_a?(String)
18
+ raise TypeError, "Webhook secret must be a string; pass it explicitly or set SEAM_WEBHOOK_SECRET"
19
+ end
20
+ if secret.empty?
21
+ raise Svix::EmptyWebhookSecretError, "Pass a webhook secret or set SEAM_WEBHOOK_SECRET to a non-empty value"
22
+ end
23
+
13
24
  @webhook = Svix::Webhook.new(secret)
14
25
  end
15
26
 
@@ -17,8 +28,17 @@ module Seam
17
28
  # generic SeamEvent for forward compatibility.
18
29
  # @return [Seam::Resources::SeamEvent]
19
30
  def verify(payload, headers)
20
- normalized_headers = headers.transform_keys(&:downcase)
21
- event_data = @webhook.verify(payload, normalized_headers)
31
+ normalized_headers = headers.transform_keys { |key| key.to_s.downcase }
32
+
33
+ event_data = begin
34
+ @webhook.verify(payload, normalized_headers)
35
+ rescue JSON::ParserError => error
36
+ raise InvalidWebhookPayloadError, "The verified webhook payload is not valid JSON: #{error.message}"
37
+ end
38
+
39
+ unless event_data.is_a?(Hash) && event_data[:event_id].is_a?(String) && event_data[:event_type].is_a?(String)
40
+ raise InvalidWebhookPayloadError, "The verified webhook payload did not contain a Seam event"
41
+ end
22
42
 
23
43
  Seam::Resources::SeamEvent.load_from_response(event_data)
24
44
  end
data/lib/seam.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "seam/errors"
3
4
  require_relative "seam/null"
5
+ require_relative "seam/request_parameters"
4
6
  require_relative "seam/url_search_params"
5
7
  require_relative "seam/strict_url_search_params_serializer"
6
8
  require_relative "seam/http"
@@ -9,16 +11,20 @@ require_relative "seam/webhook"
9
11
  require_relative "seam/wait_for_action_attempt"
10
12
 
11
13
  module Seam
12
- def self.new(**args)
13
- Seam::Http.new(**args)
14
+ def self.new(api_key = nil, **options)
15
+ Seam::Http.new(api_key, **options)
14
16
  end
15
17
 
16
- def self.from_api_key(api_key, endpoint: nil, wait_for_action_attempt: true, timeout: nil)
18
+ def self.from_api_key(api_key, endpoint: nil, wait_for_action_attempt: true, timeout: nil, faraday_options: {},
19
+ faraday_retry_options: {})
17
20
  Seam::Http.from_api_key(api_key, endpoint: endpoint, wait_for_action_attempt: wait_for_action_attempt,
18
- timeout: timeout)
21
+ timeout: timeout, faraday_options: faraday_options, faraday_retry_options: faraday_retry_options)
19
22
  end
20
23
 
21
- def self.from_personal_access_token(personal_access_token, workspace_id, endpoint: nil, wait_for_action_attempt: true, timeout: nil)
22
- Seam::Http.from_personal_access_token(personal_access_token, workspace_id, endpoint: endpoint, wait_for_action_attempt: wait_for_action_attempt, timeout: timeout)
24
+ def self.from_personal_access_token(personal_access_token, workspace_id, endpoint: nil, wait_for_action_attempt: true,
25
+ timeout: nil, faraday_options: {}, faraday_retry_options: {})
26
+ Seam::Http.from_personal_access_token(personal_access_token, workspace_id, endpoint: endpoint,
27
+ wait_for_action_attempt: wait_for_action_attempt, timeout: timeout, faraday_options: faraday_options,
28
+ faraday_retry_options: faraday_retry_options)
23
29
  end
24
30
  end