surge_api 0.1.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 (212) hide show
  1. checksums.yaml +7 -0
  2. data/.ignore +2 -0
  3. data/CHANGELOG.md +28 -0
  4. data/README.md +286 -0
  5. data/SECURITY.md +27 -0
  6. data/lib/surge_api/client.rb +106 -0
  7. data/lib/surge_api/errors.rb +228 -0
  8. data/lib/surge_api/file_part.rb +55 -0
  9. data/lib/surge_api/internal/transport/base_client.rb +567 -0
  10. data/lib/surge_api/internal/transport/pooled_net_requester.rb +201 -0
  11. data/lib/surge_api/internal/type/array_of.rb +168 -0
  12. data/lib/surge_api/internal/type/base_model.rb +531 -0
  13. data/lib/surge_api/internal/type/base_page.rb +55 -0
  14. data/lib/surge_api/internal/type/boolean.rb +77 -0
  15. data/lib/surge_api/internal/type/converter.rb +327 -0
  16. data/lib/surge_api/internal/type/enum.rb +131 -0
  17. data/lib/surge_api/internal/type/file_input.rb +108 -0
  18. data/lib/surge_api/internal/type/hash_of.rb +188 -0
  19. data/lib/surge_api/internal/type/request_parameters.rb +42 -0
  20. data/lib/surge_api/internal/type/union.rb +250 -0
  21. data/lib/surge_api/internal/type/unknown.rb +81 -0
  22. data/lib/surge_api/internal/util.rb +915 -0
  23. data/lib/surge_api/internal.rb +20 -0
  24. data/lib/surge_api/models/account.rb +60 -0
  25. data/lib/surge_api/models/account_create_params.rb +481 -0
  26. data/lib/surge_api/models/account_retrieve_status_params.rb +32 -0
  27. data/lib/surge_api/models/account_status.rb +104 -0
  28. data/lib/surge_api/models/account_update_params.rb +480 -0
  29. data/lib/surge_api/models/blast.rb +61 -0
  30. data/lib/surge_api/models/blast_create_params.rb +90 -0
  31. data/lib/surge_api/models/call_ended_webhook_event.rb +106 -0
  32. data/lib/surge_api/models/campaign.rb +208 -0
  33. data/lib/surge_api/models/campaign_approved_webhook_event.rb +74 -0
  34. data/lib/surge_api/models/campaign_create_params.rb +202 -0
  35. data/lib/surge_api/models/contact.rb +59 -0
  36. data/lib/surge_api/models/contact_create_params.rb +54 -0
  37. data/lib/surge_api/models/contact_retrieve_params.rb +14 -0
  38. data/lib/surge_api/models/contact_update_params.rb +54 -0
  39. data/lib/surge_api/models/conversation_created_webhook_event.rb +70 -0
  40. data/lib/surge_api/models/error.rb +34 -0
  41. data/lib/surge_api/models/message.rb +146 -0
  42. data/lib/surge_api/models/message_create_params.rb +153 -0
  43. data/lib/surge_api/models/message_delivered_webhook_event.rb +159 -0
  44. data/lib/surge_api/models/message_failed_webhook_event.rb +167 -0
  45. data/lib/surge_api/models/message_received_webhook_event.rb +159 -0
  46. data/lib/surge_api/models/message_sent_webhook_event.rb +159 -0
  47. data/lib/surge_api/models/organization.rb +419 -0
  48. data/lib/surge_api/models/phone_number.rb +48 -0
  49. data/lib/surge_api/models/phone_number_purchase_params.rb +65 -0
  50. data/lib/surge_api/models/unwrap_webhook_event.rb +26 -0
  51. data/lib/surge_api/models/user.rb +51 -0
  52. data/lib/surge_api/models/user_create_params.rb +46 -0
  53. data/lib/surge_api/models/user_create_token_params.rb +22 -0
  54. data/lib/surge_api/models/user_retrieve_params.rb +14 -0
  55. data/lib/surge_api/models/user_token_response.rb +19 -0
  56. data/lib/surge_api/models/user_update_params.rb +46 -0
  57. data/lib/surge_api/models/verification.rb +58 -0
  58. data/lib/surge_api/models/verification_check.rb +43 -0
  59. data/lib/surge_api/models/verification_check_params.rb +22 -0
  60. data/lib/surge_api/models/verification_create_params.rb +22 -0
  61. data/lib/surge_api/models/webhook_unwrap_params.rb +14 -0
  62. data/lib/surge_api/models.rb +117 -0
  63. data/lib/surge_api/request_options.rb +77 -0
  64. data/lib/surge_api/resources/accounts.rb +102 -0
  65. data/lib/surge_api/resources/blasts.rb +53 -0
  66. data/lib/surge_api/resources/campaigns.rb +57 -0
  67. data/lib/surge_api/resources/contacts.rb +99 -0
  68. data/lib/surge_api/resources/messages.rb +75 -0
  69. data/lib/surge_api/resources/phone_numbers.rb +48 -0
  70. data/lib/surge_api/resources/users.rb +119 -0
  71. data/lib/surge_api/resources/verifications.rb +60 -0
  72. data/lib/surge_api/resources/webhooks.rb +22 -0
  73. data/lib/surge_api/version.rb +5 -0
  74. data/lib/surge_api.rb +100 -0
  75. data/manifest.yaml +15 -0
  76. data/rbi/surge_api/client.rbi +73 -0
  77. data/rbi/surge_api/errors.rbi +205 -0
  78. data/rbi/surge_api/file_part.rbi +37 -0
  79. data/rbi/surge_api/internal/transport/base_client.rbi +292 -0
  80. data/rbi/surge_api/internal/transport/pooled_net_requester.rbi +79 -0
  81. data/rbi/surge_api/internal/type/array_of.rbi +104 -0
  82. data/rbi/surge_api/internal/type/base_model.rbi +302 -0
  83. data/rbi/surge_api/internal/type/base_page.rbi +42 -0
  84. data/rbi/surge_api/internal/type/boolean.rbi +58 -0
  85. data/rbi/surge_api/internal/type/converter.rbi +216 -0
  86. data/rbi/surge_api/internal/type/enum.rbi +82 -0
  87. data/rbi/surge_api/internal/type/file_input.rbi +59 -0
  88. data/rbi/surge_api/internal/type/hash_of.rbi +104 -0
  89. data/rbi/surge_api/internal/type/request_parameters.rbi +29 -0
  90. data/rbi/surge_api/internal/type/union.rbi +128 -0
  91. data/rbi/surge_api/internal/type/unknown.rbi +58 -0
  92. data/rbi/surge_api/internal/util.rbi +487 -0
  93. data/rbi/surge_api/internal.rbi +16 -0
  94. data/rbi/surge_api/models/account.rbi +83 -0
  95. data/rbi/surge_api/models/account_create_params.rbi +1104 -0
  96. data/rbi/surge_api/models/account_retrieve_status_params.rbi +96 -0
  97. data/rbi/surge_api/models/account_status.rbi +185 -0
  98. data/rbi/surge_api/models/account_update_params.rbi +1105 -0
  99. data/rbi/surge_api/models/blast.rbi +108 -0
  100. data/rbi/surge_api/models/blast_create_params.rbi +145 -0
  101. data/rbi/surge_api/models/call_ended_webhook_event.rbi +205 -0
  102. data/rbi/surge_api/models/campaign.rbi +331 -0
  103. data/rbi/surge_api/models/campaign_approved_webhook_event.rbi +149 -0
  104. data/rbi/surge_api/models/campaign_create_params.rbi +386 -0
  105. data/rbi/surge_api/models/contact.rbi +88 -0
  106. data/rbi/surge_api/models/contact_create_params.rbi +87 -0
  107. data/rbi/surge_api/models/contact_retrieve_params.rbi +27 -0
  108. data/rbi/surge_api/models/contact_update_params.rbi +87 -0
  109. data/rbi/surge_api/models/conversation_created_webhook_event.rbi +129 -0
  110. data/rbi/surge_api/models/error.rbi +51 -0
  111. data/rbi/surge_api/models/message.rbi +283 -0
  112. data/rbi/surge_api/models/message_create_params.rbi +281 -0
  113. data/rbi/surge_api/models/message_delivered_webhook_event.rbi +331 -0
  114. data/rbi/surge_api/models/message_failed_webhook_event.rbi +335 -0
  115. data/rbi/surge_api/models/message_received_webhook_event.rbi +331 -0
  116. data/rbi/surge_api/models/message_sent_webhook_event.rbi +322 -0
  117. data/rbi/surge_api/models/organization.rbi +649 -0
  118. data/rbi/surge_api/models/phone_number.rbi +72 -0
  119. data/rbi/surge_api/models/phone_number_purchase_params.rbi +122 -0
  120. data/rbi/surge_api/models/unwrap_webhook_event.rbi +26 -0
  121. data/rbi/surge_api/models/user.rbi +80 -0
  122. data/rbi/surge_api/models/user_create_params.rbi +76 -0
  123. data/rbi/surge_api/models/user_create_token_params.rbi +46 -0
  124. data/rbi/surge_api/models/user_retrieve_params.rbi +27 -0
  125. data/rbi/surge_api/models/user_token_response.rbi +31 -0
  126. data/rbi/surge_api/models/user_update_params.rbi +76 -0
  127. data/rbi/surge_api/models/verification.rbi +86 -0
  128. data/rbi/surge_api/models/verification_check.rbi +84 -0
  129. data/rbi/surge_api/models/verification_check_params.rbi +40 -0
  130. data/rbi/surge_api/models/verification_create_params.rbi +40 -0
  131. data/rbi/surge_api/models/webhook_unwrap_params.rbi +27 -0
  132. data/rbi/surge_api/models.rbi +80 -0
  133. data/rbi/surge_api/request_options.rbi +59 -0
  134. data/rbi/surge_api/resources/accounts.rbi +94 -0
  135. data/rbi/surge_api/resources/blasts.rbi +48 -0
  136. data/rbi/surge_api/resources/campaigns.rbi +115 -0
  137. data/rbi/surge_api/resources/contacts.rbi +85 -0
  138. data/rbi/surge_api/resources/messages.rbi +72 -0
  139. data/rbi/surge_api/resources/phone_numbers.rbi +43 -0
  140. data/rbi/surge_api/resources/users.rbi +96 -0
  141. data/rbi/surge_api/resources/verifications.rbi +43 -0
  142. data/rbi/surge_api/resources/webhooks.rbi +31 -0
  143. data/rbi/surge_api/version.rbi +5 -0
  144. data/sig/surge_api/client.rbs +42 -0
  145. data/sig/surge_api/errors.rbs +117 -0
  146. data/sig/surge_api/file_part.rbs +21 -0
  147. data/sig/surge_api/internal/transport/base_client.rbs +131 -0
  148. data/sig/surge_api/internal/transport/pooled_net_requester.rbs +45 -0
  149. data/sig/surge_api/internal/type/array_of.rbs +48 -0
  150. data/sig/surge_api/internal/type/base_model.rbs +102 -0
  151. data/sig/surge_api/internal/type/base_page.rbs +24 -0
  152. data/sig/surge_api/internal/type/boolean.rbs +26 -0
  153. data/sig/surge_api/internal/type/converter.rbs +79 -0
  154. data/sig/surge_api/internal/type/enum.rbs +32 -0
  155. data/sig/surge_api/internal/type/file_input.rbs +25 -0
  156. data/sig/surge_api/internal/type/hash_of.rbs +48 -0
  157. data/sig/surge_api/internal/type/request_parameters.rbs +17 -0
  158. data/sig/surge_api/internal/type/union.rbs +52 -0
  159. data/sig/surge_api/internal/type/unknown.rbs +26 -0
  160. data/sig/surge_api/internal/util.rbs +185 -0
  161. data/sig/surge_api/internal.rbs +9 -0
  162. data/sig/surge_api/models/account.rbs +40 -0
  163. data/sig/surge_api/models/account_create_params.rbs +433 -0
  164. data/sig/surge_api/models/account_retrieve_status_params.rbs +40 -0
  165. data/sig/surge_api/models/account_status.rbs +71 -0
  166. data/sig/surge_api/models/account_update_params.rbs +435 -0
  167. data/sig/surge_api/models/blast.rbs +64 -0
  168. data/sig/surge_api/models/blast_create_params.rbs +82 -0
  169. data/sig/surge_api/models/call_ended_webhook_event.rbs +99 -0
  170. data/sig/surge_api/models/campaign.rbs +122 -0
  171. data/sig/surge_api/models/campaign_approved_webhook_event.rbs +67 -0
  172. data/sig/surge_api/models/campaign_create_params.rbs +127 -0
  173. data/sig/surge_api/models/contact.rbs +53 -0
  174. data/sig/surge_api/models/contact_create_params.rbs +54 -0
  175. data/sig/surge_api/models/contact_retrieve_params.rbs +15 -0
  176. data/sig/surge_api/models/contact_update_params.rbs +54 -0
  177. data/sig/surge_api/models/conversation_created_webhook_event.rbs +62 -0
  178. data/sig/surge_api/models/error.rbs +27 -0
  179. data/sig/surge_api/models/message.rbs +138 -0
  180. data/sig/surge_api/models/message_create_params.rbs +140 -0
  181. data/sig/surge_api/models/message_delivered_webhook_event.rbs +143 -0
  182. data/sig/surge_api/models/message_failed_webhook_event.rbs +148 -0
  183. data/sig/surge_api/models/message_received_webhook_event.rbs +143 -0
  184. data/sig/surge_api/models/message_sent_webhook_event.rbs +143 -0
  185. data/sig/surge_api/models/organization.rbs +385 -0
  186. data/sig/surge_api/models/phone_number.rbs +37 -0
  187. data/sig/surge_api/models/phone_number_purchase_params.rbs +62 -0
  188. data/sig/surge_api/models/unwrap_webhook_event.rbs +18 -0
  189. data/sig/surge_api/models/user.rbs +48 -0
  190. data/sig/surge_api/models/user_create_params.rbs +47 -0
  191. data/sig/surge_api/models/user_create_token_params.rbs +26 -0
  192. data/sig/surge_api/models/user_retrieve_params.rbs +15 -0
  193. data/sig/surge_api/models/user_token_response.rbs +15 -0
  194. data/sig/surge_api/models/user_update_params.rbs +47 -0
  195. data/sig/surge_api/models/verification.rbs +48 -0
  196. data/sig/surge_api/models/verification_check.rbs +45 -0
  197. data/sig/surge_api/models/verification_check_params.rbs +23 -0
  198. data/sig/surge_api/models/verification_create_params.rbs +23 -0
  199. data/sig/surge_api/models/webhook_unwrap_params.rbs +15 -0
  200. data/sig/surge_api/models.rbs +77 -0
  201. data/sig/surge_api/request_options.rbs +34 -0
  202. data/sig/surge_api/resources/accounts.rbs +30 -0
  203. data/sig/surge_api/resources/blasts.rbs +19 -0
  204. data/sig/surge_api/resources/campaigns.rbs +21 -0
  205. data/sig/surge_api/resources/contacts.rbs +32 -0
  206. data/sig/surge_api/resources/messages.rbs +18 -0
  207. data/sig/surge_api/resources/phone_numbers.rbs +16 -0
  208. data/sig/surge_api/resources/users.rbs +36 -0
  209. data/sig/surge_api/resources/verifications.rbs +18 -0
  210. data/sig/surge_api/resources/webhooks.rbs +17 -0
  211. data/sig/surge_api/version.rbs +3 -0
  212. metadata +269 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bd72992441d9bff1aa161673f62cd5957d2f626eee83f83dfd3f259341377826
4
+ data.tar.gz: 37b27a1c5c4aa7406a0c81753b3b93469bb6181055cc3e9c6e4c9737cd2317a0
5
+ SHA512:
6
+ metadata.gz: 5482581f94873824fd774a5abcac9fcfb723c168cd3fc84f6f05603cc887e66870b3407f6a1546777c2f82b920ce3fc9c798c8fbc522fa8b42398cc8b10274c0
7
+ data.tar.gz: 8897a9b535eeac8e8b995e23e2b7793ecf57474f14d13ded041f4ba91eaa6f9730912ac844287621ff427d8eb7fddff3151e8e1b311745947b81794692ec92c8
data/.ignore ADDED
@@ -0,0 +1,2 @@
1
+ rbi/*
2
+ sig/*
data/CHANGELOG.md ADDED
@@ -0,0 +1,28 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (2025-09-26)
4
+
5
+ Full Changelog: [v0.0.1...v0.1.0](https://github.com/surgeapi/ruby-sdk/compare/v0.0.1...v0.1.0)
6
+
7
+ ### Features
8
+
9
+ * **api:** add ruby and change python package name ([d770df8](https://github.com/surgeapi/ruby-sdk/commit/d770df89ffb02a0a7555fa90a5c943b54547f620))
10
+ * **api:** api update ([0c2d323](https://github.com/surgeapi/ruby-sdk/commit/0c2d3235047d5dfce44bc923b049950c4957854d))
11
+ * **api:** ignore phone-number string format error ([bffdc29](https://github.com/surgeapi/ruby-sdk/commit/bffdc29d31f717392acce96b505ba6a3de744811))
12
+ * **api:** manual updates ([a8e1b08](https://github.com/surgeapi/ruby-sdk/commit/a8e1b08ab8829c4e1028d539eb1535109863810d))
13
+ * **api:** manual updates ([da2aa08](https://github.com/surgeapi/ruby-sdk/commit/da2aa08c75571cc01019d23c60725e379eb01202))
14
+ * expose response headers for both streams and errors ([21bbb9e](https://github.com/surgeapi/ruby-sdk/commit/21bbb9e80873a5fe04e2436938a6a56e52ef4873))
15
+ * **types:** remove explicit params types ([c43f650](https://github.com/surgeapi/ruby-sdk/commit/c43f650cfe2a3c0ab05231d7f2db15cf3f108b81))
16
+ * **types:** try removing account_update_params type ([9a7763f](https://github.com/surgeapi/ruby-sdk/commit/9a7763f376cc5394cdc976b1929164ba6c354076))
17
+
18
+
19
+ ### Performance Improvements
20
+
21
+ * faster code formatting ([1559ebc](https://github.com/surgeapi/ruby-sdk/commit/1559ebc7333dcadb7f1aa94666a237fa0f4204f6))
22
+
23
+
24
+ ### Chores
25
+
26
+ * configure new SDK language ([0a9942a](https://github.com/surgeapi/ruby-sdk/commit/0a9942a34e0f7637985937fed36cced872a432e6))
27
+ * do not install brew dependencies in ./scripts/bootstrap by default ([fdb4bd7](https://github.com/surgeapi/ruby-sdk/commit/fdb4bd7238eaeb5bd5a18a21a158d02cd9d6bc52))
28
+ * update SDK settings ([bc95cd0](https://github.com/surgeapi/ruby-sdk/commit/bc95cd0533c84d203ca12c4dde56394524036ef0))
data/README.md ADDED
@@ -0,0 +1,286 @@
1
+ # Surge Ruby API library
2
+
3
+ The Surge Ruby library provides convenient access to the Surge REST API from any Ruby 3.2.0+ application. It ships with comprehensive types & docstrings in Yard, RBS, and RBI – [see below](https://github.com/surgeapi/ruby-sdk#Sorbet) for usage with Sorbet. The standard library's `net/http` is used as the HTTP transport, with connection pooling via the `connection_pool` gem.
4
+
5
+ It is generated with [Stainless](https://www.stainless.com/).
6
+
7
+ ## Documentation
8
+
9
+ Documentation for releases of this gem can be found [on RubyDoc](https://gemdocs.org/gems/surge_api).
10
+
11
+ The REST API documentation can be found on [docs.surge.app](https://docs.surge.app).
12
+
13
+ ## Installation
14
+
15
+ To use this gem, install via Bundler by adding the following to your application's `Gemfile`:
16
+
17
+ <!-- x-release-please-start-version -->
18
+
19
+ ```ruby
20
+ gem "surge_api", "~> 0.1.0"
21
+ ```
22
+
23
+ <!-- x-release-please-end -->
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ require "bundler/setup"
29
+ require "surge_api"
30
+
31
+ surge = SurgeAPI::Client.new(
32
+ api_key: ENV["SURGE_API_KEY"] # This is the default and can be omitted
33
+ )
34
+
35
+ message = surge.messages.create(
36
+ "acct_01j9a43avnfqzbjfch6pygv1td",
37
+ conversation: {contact: {first_name: "Dom", last_name: "Toretto", phone_number: "+13235556439"}},
38
+ attachments: [{url: "https://toretto.family/coronas.gif"}],
39
+ body: "Thought you could leave without saying goodbye?"
40
+ )
41
+
42
+ puts(message.id)
43
+ ```
44
+
45
+ ### Handling errors
46
+
47
+ When the library is unable to connect to the API, or if the API returns a non-success status code (i.e., 4xx or 5xx response), a subclass of `SurgeAPI::Errors::APIError` will be thrown:
48
+
49
+ ```ruby
50
+ begin
51
+ message = surge.messages.create(
52
+ "acct_01j9a43avnfqzbjfch6pygv1td",
53
+ conversation: {contact: {first_name: "Dom", last_name: "Toretto", phone_number: "+13235556439"}},
54
+ attachments: [{url: "https://toretto.family/coronas.gif"}],
55
+ body: "Thought you could leave without saying goodbye?"
56
+ )
57
+ rescue SurgeAPI::Errors::APIConnectionError => e
58
+ puts("The server could not be reached")
59
+ puts(e.cause) # an underlying Exception, likely raised within `net/http`
60
+ rescue SurgeAPI::Errors::RateLimitError => e
61
+ puts("A 429 status code was received; we should back off a bit.")
62
+ rescue SurgeAPI::Errors::APIStatusError => e
63
+ puts("Another non-200-range status code was received")
64
+ puts(e.status)
65
+ end
66
+ ```
67
+
68
+ Error codes are as follows:
69
+
70
+ | Cause | Error Type |
71
+ | ---------------- | -------------------------- |
72
+ | HTTP 400 | `BadRequestError` |
73
+ | HTTP 401 | `AuthenticationError` |
74
+ | HTTP 403 | `PermissionDeniedError` |
75
+ | HTTP 404 | `NotFoundError` |
76
+ | HTTP 409 | `ConflictError` |
77
+ | HTTP 422 | `UnprocessableEntityError` |
78
+ | HTTP 429 | `RateLimitError` |
79
+ | HTTP >= 500 | `InternalServerError` |
80
+ | Other HTTP error | `APIStatusError` |
81
+ | Timeout | `APITimeoutError` |
82
+ | Network error | `APIConnectionError` |
83
+
84
+ ### Retries
85
+
86
+ Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
87
+
88
+ Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict, 429 Rate Limit, >=500 Internal errors, and timeouts will all be retried by default.
89
+
90
+ You can use the `max_retries` option to configure or disable this:
91
+
92
+ ```ruby
93
+ # Configure the default for all requests:
94
+ surge = SurgeAPI::Client.new(
95
+ max_retries: 0 # default is 2
96
+ )
97
+
98
+ # Or, configure per-request:
99
+ surge.messages.create(
100
+ "acct_01j9a43avnfqzbjfch6pygv1td",
101
+ conversation: {contact: {first_name: "Dom", last_name: "Toretto", phone_number: "+13235556439"}},
102
+ attachments: [{url: "https://toretto.family/coronas.gif"}],
103
+ body: "Thought you could leave without saying goodbye?",
104
+ request_options: {max_retries: 5}
105
+ )
106
+ ```
107
+
108
+ ### Timeouts
109
+
110
+ By default, requests will time out after 60 seconds. You can use the timeout option to configure or disable this:
111
+
112
+ ```ruby
113
+ # Configure the default for all requests:
114
+ surge = SurgeAPI::Client.new(
115
+ timeout: nil # default is 60
116
+ )
117
+
118
+ # Or, configure per-request:
119
+ surge.messages.create(
120
+ "acct_01j9a43avnfqzbjfch6pygv1td",
121
+ conversation: {contact: {first_name: "Dom", last_name: "Toretto", phone_number: "+13235556439"}},
122
+ attachments: [{url: "https://toretto.family/coronas.gif"}],
123
+ body: "Thought you could leave without saying goodbye?",
124
+ request_options: {timeout: 5}
125
+ )
126
+ ```
127
+
128
+ On timeout, `SurgeAPI::Errors::APITimeoutError` is raised.
129
+
130
+ Note that requests that time out are retried by default.
131
+
132
+ ## Advanced concepts
133
+
134
+ ### BaseModel
135
+
136
+ All parameter and response objects inherit from `SurgeAPI::Internal::Type::BaseModel`, which provides several conveniences, including:
137
+
138
+ 1. All fields, including unknown ones, are accessible with `obj[:prop]` syntax, and can be destructured with `obj => {prop: prop}` or pattern-matching syntax.
139
+
140
+ 2. Structural equivalence for equality; if two API calls return the same values, comparing the responses with == will return true.
141
+
142
+ 3. Both instances and the classes themselves can be pretty-printed.
143
+
144
+ 4. Helpers such as `#to_h`, `#deep_to_h`, `#to_json`, and `#to_yaml`.
145
+
146
+ ### Making custom or undocumented requests
147
+
148
+ #### Undocumented properties
149
+
150
+ You can send undocumented parameters to any endpoint, and read undocumented response properties, like so:
151
+
152
+ Note: the `extra_` parameters of the same name overrides the documented parameters.
153
+
154
+ ```ruby
155
+ message =
156
+ surge.messages.create(
157
+ "acct_01j9a43avnfqzbjfch6pygv1td",
158
+ conversation: {contact: {first_name: "Dom", last_name: "Toretto", phone_number: "+13235556439"}},
159
+ attachments: [{url: "https://toretto.family/coronas.gif"}],
160
+ body: "Thought you could leave without saying goodbye?",
161
+ request_options: {
162
+ extra_query: {my_query_parameter: value},
163
+ extra_body: {my_body_parameter: value},
164
+ extra_headers: {"my-header": value}
165
+ }
166
+ )
167
+
168
+ puts(message[:my_undocumented_property])
169
+ ```
170
+
171
+ #### Undocumented request params
172
+
173
+ If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` under the `request_options:` parameter when making a request, as seen in the examples above.
174
+
175
+ #### Undocumented endpoints
176
+
177
+ To make requests to undocumented endpoints while retaining the benefit of auth, retries, and so on, you can make requests using `client.request`, like so:
178
+
179
+ ```ruby
180
+ response = client.request(
181
+ method: :post,
182
+ path: '/undocumented/endpoint',
183
+ query: {"dog": "woof"},
184
+ headers: {"useful-header": "interesting-value"},
185
+ body: {"hello": "world"}
186
+ )
187
+ ```
188
+
189
+ ### Concurrency & connection pooling
190
+
191
+ The `SurgeAPI::Client` instances are threadsafe, but are only are fork-safe when there are no in-flight HTTP requests.
192
+
193
+ Each instance of `SurgeAPI::Client` has its own HTTP connection pool with a default size of 99. As such, we recommend instantiating the client once per application in most settings.
194
+
195
+ When all available connections from the pool are checked out, requests wait for a new connection to become available, with queue time counting towards the request timeout.
196
+
197
+ Unless otherwise specified, other classes in the SDK do not have locks protecting their underlying data structure.
198
+
199
+ ## Sorbet
200
+
201
+ This library provides comprehensive [RBI](https://sorbet.org/docs/rbi) definitions, and has no dependency on sorbet-runtime.
202
+
203
+ You can provide typesafe request parameters like so:
204
+
205
+ ```ruby
206
+ surge.messages.create(
207
+ "acct_01j9a43avnfqzbjfch6pygv1td",
208
+ conversation: SurgeAPI::MessageCreateParams::Conversation.new(
209
+ contact: SurgeAPI::MessageCreateParams::Conversation::Contact.new(
210
+ first_name: "Dom",
211
+ last_name: "Toretto",
212
+ phone_number: "+13235556439"
213
+ )
214
+ ),
215
+ attachments: [SurgeAPI::MessageCreateParams::Attachment.new(url: "https://toretto.family/coronas.gif")],
216
+ body: "Thought you could leave without saying goodbye?"
217
+ )
218
+ ```
219
+
220
+ Or, equivalently:
221
+
222
+ ```ruby
223
+ # Hashes work, but are not typesafe:
224
+ surge.messages.create(
225
+ "acct_01j9a43avnfqzbjfch6pygv1td",
226
+ conversation: {contact: {first_name: "Dom", last_name: "Toretto", phone_number: "+13235556439"}},
227
+ attachments: [{url: "https://toretto.family/coronas.gif"}],
228
+ body: "Thought you could leave without saying goodbye?"
229
+ )
230
+
231
+ # You can also splat a full Params class:
232
+ params = SurgeAPI::MessageCreateParams.new(
233
+ conversation: SurgeAPI::MessageCreateParams::Conversation.new(
234
+ contact: SurgeAPI::MessageCreateParams::Conversation::Contact.new(
235
+ first_name: "Dom",
236
+ last_name: "Toretto",
237
+ phone_number: "+13235556439"
238
+ )
239
+ ),
240
+ attachments: [SurgeAPI::MessageCreateParams::Attachment.new(url: "https://toretto.family/coronas.gif")],
241
+ body: "Thought you could leave without saying goodbye?"
242
+ )
243
+ surge.messages.create("acct_01j9a43avnfqzbjfch6pygv1td", **params)
244
+ ```
245
+
246
+ ### Enums
247
+
248
+ Since this library does not depend on `sorbet-runtime`, it cannot provide [`T::Enum`](https://sorbet.org/docs/tenum) instances. Instead, we provide "tagged symbols" instead, which is always a primitive at runtime:
249
+
250
+ ```ruby
251
+ # :high
252
+ puts(SurgeAPI::CampaignCreateParams::Volume::HIGH)
253
+
254
+ # Revealed type: `T.all(SurgeAPI::CampaignCreateParams::Volume, Symbol)`
255
+ T.reveal_type(SurgeAPI::CampaignCreateParams::Volume::HIGH)
256
+ ```
257
+
258
+ Enum parameters have a "relaxed" type, so you can either pass in enum constants or their literal value:
259
+
260
+ ```ruby
261
+ # Using the enum constants preserves the tagged type information:
262
+ surge.campaigns.create(
263
+ volume: SurgeAPI::CampaignCreateParams::Volume::HIGH,
264
+ # …
265
+ )
266
+
267
+ # Literal values are also permissible:
268
+ surge.campaigns.create(
269
+ volume: :high,
270
+ # …
271
+ )
272
+ ```
273
+
274
+ ## Versioning
275
+
276
+ This package follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions. As the library is in initial development and has a major version of `0`, APIs may change at any time.
277
+
278
+ This package considers improvements to the (non-runtime) `*.rbi` and `*.rbs` type definitions to be non-breaking changes.
279
+
280
+ ## Requirements
281
+
282
+ Ruby 3.2.0 or higher.
283
+
284
+ ## Contributing
285
+
286
+ See [the contributing documentation](https://github.com/surgeapi/ruby-sdk/tree/main/CONTRIBUTING.md).
data/SECURITY.md ADDED
@@ -0,0 +1,27 @@
1
+ # Security Policy
2
+
3
+ ## Reporting Security Issues
4
+
5
+ This SDK is generated by [Stainless Software Inc](http://stainless.com). Stainless takes security seriously, and encourages you to report any security vulnerability promptly so that appropriate action can be taken.
6
+
7
+ To report a security issue, please contact the Stainless team at security@stainless.com.
8
+
9
+ ## Responsible Disclosure
10
+
11
+ We appreciate the efforts of security researchers and individuals who help us maintain the security of
12
+ SDKs we generate. If you believe you have found a security vulnerability, please adhere to responsible
13
+ disclosure practices by allowing us a reasonable amount of time to investigate and address the issue
14
+ before making any information public.
15
+
16
+ ## Reporting Non-SDK Related Security Issues
17
+
18
+ If you encounter security issues that are not directly related to SDKs but pertain to the services
19
+ or products provided by Surge, please follow the respective company's security reporting guidelines.
20
+
21
+ ### Surge Terms and Policies
22
+
23
+ Please contact support@surge.app for any questions or concerns regarding the security of our services.
24
+
25
+ ---
26
+
27
+ Thank you for helping us keep the SDKs and systems they interact with secure.
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SurgeAPI
4
+ class Client < SurgeAPI::Internal::Transport::BaseClient
5
+ # Default max number of retries to attempt after a failed retryable request.
6
+ DEFAULT_MAX_RETRIES = 2
7
+
8
+ # Default per-request timeout.
9
+ DEFAULT_TIMEOUT_IN_SECONDS = 60.0
10
+
11
+ # Default initial retry delay in seconds.
12
+ # Overall delay is calculated using exponential backoff + jitter.
13
+ DEFAULT_INITIAL_RETRY_DELAY = 0.5
14
+
15
+ # Default max retry delay in seconds.
16
+ DEFAULT_MAX_RETRY_DELAY = 8.0
17
+
18
+ # @return [String]
19
+ attr_reader :api_key
20
+
21
+ # @return [SurgeAPI::Resources::Accounts]
22
+ attr_reader :accounts
23
+
24
+ # @return [SurgeAPI::Resources::Blasts]
25
+ attr_reader :blasts
26
+
27
+ # @return [SurgeAPI::Resources::Campaigns]
28
+ attr_reader :campaigns
29
+
30
+ # @return [SurgeAPI::Resources::Contacts]
31
+ attr_reader :contacts
32
+
33
+ # @return [SurgeAPI::Resources::Messages]
34
+ attr_reader :messages
35
+
36
+ # @return [SurgeAPI::Resources::PhoneNumbers]
37
+ attr_reader :phone_numbers
38
+
39
+ # @return [SurgeAPI::Resources::Users]
40
+ attr_reader :users
41
+
42
+ # @return [SurgeAPI::Resources::Verifications]
43
+ attr_reader :verifications
44
+
45
+ # @return [SurgeAPI::Resources::Webhooks]
46
+ attr_reader :webhooks
47
+
48
+ # @api private
49
+ #
50
+ # @return [Hash{String=>String}]
51
+ private def auth_headers
52
+ return {} if @api_key.nil?
53
+
54
+ {"authorization" => "Bearer #{@api_key}"}
55
+ end
56
+
57
+ # Creates and returns a new client for interacting with the API.
58
+ #
59
+ # @param api_key [String, nil] Defaults to `ENV["SURGE_API_KEY"]`
60
+ #
61
+ # @param base_url [String, nil] Override the default base URL for the API, e.g.,
62
+ # `"https://api.example.com/v2/"`. Defaults to `ENV["SURGE_BASE_URL"]`
63
+ #
64
+ # @param max_retries [Integer] Max number of retries to attempt after a failed retryable request.
65
+ #
66
+ # @param timeout [Float]
67
+ #
68
+ # @param initial_retry_delay [Float]
69
+ #
70
+ # @param max_retry_delay [Float]
71
+ def initialize(
72
+ api_key: ENV["SURGE_API_KEY"],
73
+ base_url: ENV["SURGE_BASE_URL"],
74
+ max_retries: self.class::DEFAULT_MAX_RETRIES,
75
+ timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS,
76
+ initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY,
77
+ max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY
78
+ )
79
+ base_url ||= "https://api.surge.app"
80
+
81
+ if api_key.nil?
82
+ raise ArgumentError.new("api_key is required, and can be set via environ: \"SURGE_API_KEY\"")
83
+ end
84
+
85
+ @api_key = api_key.to_s
86
+
87
+ super(
88
+ base_url: base_url,
89
+ timeout: timeout,
90
+ max_retries: max_retries,
91
+ initial_retry_delay: initial_retry_delay,
92
+ max_retry_delay: max_retry_delay
93
+ )
94
+
95
+ @accounts = SurgeAPI::Resources::Accounts.new(client: self)
96
+ @blasts = SurgeAPI::Resources::Blasts.new(client: self)
97
+ @campaigns = SurgeAPI::Resources::Campaigns.new(client: self)
98
+ @contacts = SurgeAPI::Resources::Contacts.new(client: self)
99
+ @messages = SurgeAPI::Resources::Messages.new(client: self)
100
+ @phone_numbers = SurgeAPI::Resources::PhoneNumbers.new(client: self)
101
+ @users = SurgeAPI::Resources::Users.new(client: self)
102
+ @verifications = SurgeAPI::Resources::Verifications.new(client: self)
103
+ @webhooks = SurgeAPI::Resources::Webhooks.new(client: self)
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,228 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SurgeAPI
4
+ module Errors
5
+ class Error < StandardError
6
+ # @!attribute cause
7
+ #
8
+ # @return [StandardError, nil]
9
+ end
10
+
11
+ class ConversionError < SurgeAPI::Errors::Error
12
+ # @return [StandardError, nil]
13
+ def cause = @cause.nil? ? super : @cause
14
+
15
+ # @api private
16
+ #
17
+ # @param on [Class<StandardError>]
18
+ # @param method [Symbol]
19
+ # @param target [Object]
20
+ # @param value [Object]
21
+ # @param cause [StandardError, nil]
22
+ def initialize(on:, method:, target:, value:, cause: nil)
23
+ cls = on.name.split("::").last
24
+
25
+ message = [
26
+ "Failed to parse #{cls}.#{method} from #{value.class} to #{target.inspect}.",
27
+ "To get the unparsed API response, use #{cls}[#{method.inspect}].",
28
+ cause && "Cause: #{cause.message}"
29
+ ].filter(&:itself).join(" ")
30
+
31
+ @cause = cause
32
+ super(message)
33
+ end
34
+ end
35
+
36
+ class APIError < SurgeAPI::Errors::Error
37
+ # @return [URI::Generic]
38
+ attr_accessor :url
39
+
40
+ # @return [Integer, nil]
41
+ attr_accessor :status
42
+
43
+ # @return [Hash{String=>String}, nil]
44
+ attr_accessor :headers
45
+
46
+ # @return [Object, nil]
47
+ attr_accessor :body
48
+
49
+ # @api private
50
+ #
51
+ # @param url [URI::Generic]
52
+ # @param status [Integer, nil]
53
+ # @param headers [Hash{String=>String}, nil]
54
+ # @param body [Object, nil]
55
+ # @param request [nil]
56
+ # @param response [nil]
57
+ # @param message [String, nil]
58
+ def initialize(url:, status: nil, headers: nil, body: nil, request: nil, response: nil, message: nil)
59
+ @url = url
60
+ @status = status
61
+ @headers = headers
62
+ @body = body
63
+ @request = request
64
+ @response = response
65
+ super(message)
66
+ end
67
+ end
68
+
69
+ class APIConnectionError < SurgeAPI::Errors::APIError
70
+ # @!attribute status
71
+ #
72
+ # @return [nil]
73
+
74
+ # @!attribute body
75
+ #
76
+ # @return [nil]
77
+
78
+ # @api private
79
+ #
80
+ # @param url [URI::Generic]
81
+ # @param status [nil]
82
+ # @param headers [Hash{String=>String}, nil]
83
+ # @param body [nil]
84
+ # @param request [nil]
85
+ # @param response [nil]
86
+ # @param message [String, nil]
87
+ def initialize(
88
+ url:,
89
+ status: nil,
90
+ headers: nil,
91
+ body: nil,
92
+ request: nil,
93
+ response: nil,
94
+ message: "Connection error."
95
+ )
96
+ super
97
+ end
98
+ end
99
+
100
+ class APITimeoutError < SurgeAPI::Errors::APIConnectionError
101
+ # @api private
102
+ #
103
+ # @param url [URI::Generic]
104
+ # @param status [nil]
105
+ # @param headers [Hash{String=>String}, nil]
106
+ # @param body [nil]
107
+ # @param request [nil]
108
+ # @param response [nil]
109
+ # @param message [String, nil]
110
+ def initialize(
111
+ url:,
112
+ status: nil,
113
+ headers: nil,
114
+ body: nil,
115
+ request: nil,
116
+ response: nil,
117
+ message: "Request timed out."
118
+ )
119
+ super
120
+ end
121
+ end
122
+
123
+ class APIStatusError < SurgeAPI::Errors::APIError
124
+ # @api private
125
+ #
126
+ # @param url [URI::Generic]
127
+ # @param status [Integer]
128
+ # @param headers [Hash{String=>String}, nil]
129
+ # @param body [Object, nil]
130
+ # @param request [nil]
131
+ # @param response [nil]
132
+ # @param message [String, nil]
133
+ #
134
+ # @return [self]
135
+ def self.for(url:, status:, headers:, body:, request:, response:, message: nil)
136
+ kwargs =
137
+ {
138
+ url: url,
139
+ status: status,
140
+ headers: headers,
141
+ body: body,
142
+ request: request,
143
+ response: response,
144
+ message: message
145
+ }
146
+
147
+ case status
148
+ in 400
149
+ SurgeAPI::Errors::BadRequestError.new(**kwargs)
150
+ in 401
151
+ SurgeAPI::Errors::AuthenticationError.new(**kwargs)
152
+ in 403
153
+ SurgeAPI::Errors::PermissionDeniedError.new(**kwargs)
154
+ in 404
155
+ SurgeAPI::Errors::NotFoundError.new(**kwargs)
156
+ in 409
157
+ SurgeAPI::Errors::ConflictError.new(**kwargs)
158
+ in 422
159
+ SurgeAPI::Errors::UnprocessableEntityError.new(**kwargs)
160
+ in 429
161
+ SurgeAPI::Errors::RateLimitError.new(**kwargs)
162
+ in (500..)
163
+ SurgeAPI::Errors::InternalServerError.new(**kwargs)
164
+ else
165
+ SurgeAPI::Errors::APIStatusError.new(**kwargs)
166
+ end
167
+ end
168
+
169
+ # @!parse
170
+ # # @return [Integer]
171
+ # attr_accessor :status
172
+
173
+ # @api private
174
+ #
175
+ # @param url [URI::Generic]
176
+ # @param status [Integer]
177
+ # @param headers [Hash{String=>String}, nil]
178
+ # @param body [Object, nil]
179
+ # @param request [nil]
180
+ # @param response [nil]
181
+ # @param message [String, nil]
182
+ def initialize(url:, status:, headers:, body:, request:, response:, message: nil)
183
+ message ||= {url: url.to_s, status: status, body: body}
184
+ super(
185
+ url: url,
186
+ status: status,
187
+ headers: headers,
188
+ body: body,
189
+ request: request,
190
+ response: response,
191
+ message: message&.to_s
192
+ )
193
+ end
194
+ end
195
+
196
+ class BadRequestError < SurgeAPI::Errors::APIStatusError
197
+ HTTP_STATUS = 400
198
+ end
199
+
200
+ class AuthenticationError < SurgeAPI::Errors::APIStatusError
201
+ HTTP_STATUS = 401
202
+ end
203
+
204
+ class PermissionDeniedError < SurgeAPI::Errors::APIStatusError
205
+ HTTP_STATUS = 403
206
+ end
207
+
208
+ class NotFoundError < SurgeAPI::Errors::APIStatusError
209
+ HTTP_STATUS = 404
210
+ end
211
+
212
+ class ConflictError < SurgeAPI::Errors::APIStatusError
213
+ HTTP_STATUS = 409
214
+ end
215
+
216
+ class UnprocessableEntityError < SurgeAPI::Errors::APIStatusError
217
+ HTTP_STATUS = 422
218
+ end
219
+
220
+ class RateLimitError < SurgeAPI::Errors::APIStatusError
221
+ HTTP_STATUS = 429
222
+ end
223
+
224
+ class InternalServerError < SurgeAPI::Errors::APIStatusError
225
+ HTTP_STATUS = (500..)
226
+ end
227
+ end
228
+ end