surge_api 0.16.0 → 0.18.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 (162) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +30 -0
  3. data/README.md +56 -21
  4. data/lib/surge_api/client.rb +22 -1
  5. data/lib/surge_api/internal/cursor.rb +2 -2
  6. data/lib/surge_api/internal/transport/base_client.rb +5 -0
  7. data/lib/surge_api/internal/util.rb +22 -7
  8. data/lib/surge_api/models/account_archive_params.rb +9 -1
  9. data/lib/surge_api/models/account_list_params.rb +34 -0
  10. data/lib/surge_api/models/account_retrieve_status_params.rb +9 -1
  11. data/lib/surge_api/models/account_update_params.rb +9 -1
  12. data/lib/surge_api/models/attachment_get_file_params.rb +9 -1
  13. data/lib/surge_api/models/audience_add_contact_params.rb +9 -1
  14. data/lib/surge_api/models/audience_create_params.rb +9 -1
  15. data/lib/surge_api/models/audience_list_contacts_params.rb +9 -1
  16. data/lib/surge_api/models/blast_create_params.rb +9 -1
  17. data/lib/surge_api/models/campaign_create_params.rb +6 -10
  18. data/lib/surge_api/models/campaign_list_params.rb +9 -1
  19. data/lib/surge_api/models/campaign_retrieve_params.rb +9 -1
  20. data/lib/surge_api/models/campaign_update_params.rb +6 -10
  21. data/lib/surge_api/models/contact_create_params.rb +9 -1
  22. data/lib/surge_api/models/contact_list_params.rb +9 -1
  23. data/lib/surge_api/models/contact_retrieve_params.rb +9 -1
  24. data/lib/surge_api/models/contact_update_params.rb +9 -1
  25. data/lib/surge_api/models/message.rb +1 -0
  26. data/lib/surge_api/models/message_create_params.rb +6 -11
  27. data/lib/surge_api/models/message_delivered_webhook_event.rb +1 -0
  28. data/lib/surge_api/models/message_failed_webhook_event.rb +1 -0
  29. data/lib/surge_api/models/message_list_params.rb +9 -1
  30. data/lib/surge_api/models/message_params.rb +74 -2
  31. data/lib/surge_api/models/message_received_webhook_event.rb +1 -0
  32. data/lib/surge_api/models/message_retrieve_params.rb +9 -1
  33. data/lib/surge_api/models/message_sent_webhook_event.rb +1 -0
  34. data/lib/surge_api/models/phone_number.rb +1 -1
  35. data/lib/surge_api/models/phone_number_list_params.rb +9 -1
  36. data/lib/surge_api/models/phone_number_purchase_params.rb +9 -1
  37. data/lib/surge_api/models/phone_number_release_params.rb +22 -0
  38. data/lib/surge_api/models/phone_number_update_params.rb +38 -0
  39. data/lib/surge_api/models/recording_delete_params.rb +9 -1
  40. data/lib/surge_api/models/recording_get_file_params.rb +9 -1
  41. data/lib/surge_api/models/recording_list_params.rb +9 -1
  42. data/lib/surge_api/models/recording_retrieve_params.rb +9 -1
  43. data/lib/surge_api/models/user_create_params.rb +9 -1
  44. data/lib/surge_api/models/user_create_token_params.rb +9 -1
  45. data/lib/surge_api/models/user_delete_params.rb +9 -1
  46. data/lib/surge_api/models/user_list_params.rb +9 -1
  47. data/lib/surge_api/models/user_retrieve_params.rb +9 -1
  48. data/lib/surge_api/models/user_update_params.rb +9 -1
  49. data/lib/surge_api/models/verification_check_params.rb +9 -1
  50. data/lib/surge_api/models/verification_create_params.rb +9 -1
  51. data/lib/surge_api/models.rb +6 -0
  52. data/lib/surge_api/resources/accounts.rb +29 -0
  53. data/lib/surge_api/resources/campaigns.rb +4 -14
  54. data/lib/surge_api/resources/messages.rb +6 -7
  55. data/lib/surge_api/resources/phone_numbers.rb +46 -0
  56. data/lib/surge_api/resources/verifications.rb +7 -4
  57. data/lib/surge_api/resources/webhooks.rb +11 -1
  58. data/lib/surge_api/version.rb +1 -1
  59. data/lib/surge_api.rb +4 -0
  60. data/rbi/surge_api/client.rbi +6 -0
  61. data/rbi/surge_api/internal/util.rbi +8 -0
  62. data/rbi/surge_api/models/account_archive_params.rbi +18 -5
  63. data/rbi/surge_api/models/account_list_params.rbi +59 -0
  64. data/rbi/surge_api/models/account_retrieve_status_params.rbi +8 -0
  65. data/rbi/surge_api/models/account_update_params.rbi +8 -0
  66. data/rbi/surge_api/models/attachment_get_file_params.rbi +18 -5
  67. data/rbi/surge_api/models/audience_add_contact_params.rbi +12 -1
  68. data/rbi/surge_api/models/audience_create_params.rbi +12 -1
  69. data/rbi/surge_api/models/audience_list_contacts_params.rbi +8 -0
  70. data/rbi/surge_api/models/blast_create_params.rbi +8 -0
  71. data/rbi/surge_api/models/campaign_create_params.rbi +7 -27
  72. data/rbi/surge_api/models/campaign_list_params.rbi +8 -0
  73. data/rbi/surge_api/models/campaign_retrieve_params.rbi +18 -5
  74. data/rbi/surge_api/models/campaign_update_params.rbi +7 -27
  75. data/rbi/surge_api/models/contact_create_params.rbi +8 -0
  76. data/rbi/surge_api/models/contact_list_params.rbi +8 -0
  77. data/rbi/surge_api/models/contact_retrieve_params.rbi +18 -5
  78. data/rbi/surge_api/models/contact_update_params.rbi +8 -0
  79. data/rbi/surge_api/models/message.rbi +2 -0
  80. data/rbi/surge_api/models/message_create_params.rbi +7 -29
  81. data/rbi/surge_api/models/message_delivered_webhook_event.rbi +5 -0
  82. data/rbi/surge_api/models/message_failed_webhook_event.rbi +5 -0
  83. data/rbi/surge_api/models/message_list_params.rbi +8 -0
  84. data/rbi/surge_api/models/message_params.rbi +225 -6
  85. data/rbi/surge_api/models/message_received_webhook_event.rbi +5 -0
  86. data/rbi/surge_api/models/message_retrieve_params.rbi +18 -5
  87. data/rbi/surge_api/models/message_sent_webhook_event.rbi +5 -0
  88. data/rbi/surge_api/models/phone_number_list_params.rbi +8 -0
  89. data/rbi/surge_api/models/phone_number_purchase_params.rbi +8 -0
  90. data/rbi/surge_api/models/phone_number_release_params.rbi +40 -0
  91. data/rbi/surge_api/models/phone_number_update_params.rbi +65 -0
  92. data/rbi/surge_api/models/recording_delete_params.rbi +18 -5
  93. data/rbi/surge_api/models/recording_get_file_params.rbi +18 -5
  94. data/rbi/surge_api/models/recording_list_params.rbi +8 -0
  95. data/rbi/surge_api/models/recording_retrieve_params.rbi +18 -5
  96. data/rbi/surge_api/models/user_create_params.rbi +8 -0
  97. data/rbi/surge_api/models/user_create_token_params.rbi +8 -0
  98. data/rbi/surge_api/models/user_delete_params.rbi +18 -5
  99. data/rbi/surge_api/models/user_list_params.rbi +8 -0
  100. data/rbi/surge_api/models/user_retrieve_params.rbi +18 -5
  101. data/rbi/surge_api/models/user_update_params.rbi +8 -0
  102. data/rbi/surge_api/models/verification_check_params.rbi +12 -1
  103. data/rbi/surge_api/models/verification_create_params.rbi +12 -1
  104. data/rbi/surge_api/models.rbi +6 -0
  105. data/rbi/surge_api/resources/accounts.rbi +18 -0
  106. data/rbi/surge_api/resources/campaigns.rbi +10 -2
  107. data/rbi/surge_api/resources/messages.rbi +9 -1
  108. data/rbi/surge_api/resources/phone_numbers.rbi +34 -0
  109. data/rbi/surge_api/resources/verifications.rbi +5 -1
  110. data/rbi/surge_api/resources/webhooks.rbi +10 -2
  111. data/sig/surge_api/client.rbs +3 -0
  112. data/sig/surge_api/internal/util.rbs +4 -0
  113. data/sig/surge_api/models/account_archive_params.rbs +8 -3
  114. data/sig/surge_api/models/account_list_params.rbs +32 -0
  115. data/sig/surge_api/models/account_retrieve_status_params.rbs +5 -0
  116. data/sig/surge_api/models/account_update_params.rbs +5 -0
  117. data/sig/surge_api/models/attachment_get_file_params.rbs +11 -3
  118. data/sig/surge_api/models/audience_add_contact_params.rbs +10 -2
  119. data/sig/surge_api/models/audience_create_params.rbs +6 -1
  120. data/sig/surge_api/models/audience_list_contacts_params.rbs +5 -1
  121. data/sig/surge_api/models/blast_create_params.rbs +5 -0
  122. data/sig/surge_api/models/campaign_create_params.rbs +4 -9
  123. data/sig/surge_api/models/campaign_list_params.rbs +5 -1
  124. data/sig/surge_api/models/campaign_retrieve_params.rbs +8 -3
  125. data/sig/surge_api/models/campaign_update_params.rbs +4 -12
  126. data/sig/surge_api/models/contact_create_params.rbs +5 -0
  127. data/sig/surge_api/models/contact_list_params.rbs +5 -1
  128. data/sig/surge_api/models/contact_retrieve_params.rbs +8 -3
  129. data/sig/surge_api/models/contact_update_params.rbs +5 -0
  130. data/sig/surge_api/models/message.rbs +2 -1
  131. data/sig/surge_api/models/message_create_params.rbs +4 -9
  132. data/sig/surge_api/models/message_delivered_webhook_event.rbs +2 -1
  133. data/sig/surge_api/models/message_failed_webhook_event.rbs +2 -1
  134. data/sig/surge_api/models/message_list_params.rbs +5 -1
  135. data/sig/surge_api/models/message_params.rbs +88 -6
  136. data/sig/surge_api/models/message_received_webhook_event.rbs +2 -1
  137. data/sig/surge_api/models/message_retrieve_params.rbs +8 -3
  138. data/sig/surge_api/models/message_sent_webhook_event.rbs +2 -1
  139. data/sig/surge_api/models/phone_number_list_params.rbs +5 -1
  140. data/sig/surge_api/models/phone_number_purchase_params.rbs +5 -0
  141. data/sig/surge_api/models/phone_number_release_params.rbs +20 -0
  142. data/sig/surge_api/models/phone_number_update_params.rbs +36 -0
  143. data/sig/surge_api/models/recording_delete_params.rbs +8 -3
  144. data/sig/surge_api/models/recording_get_file_params.rbs +11 -3
  145. data/sig/surge_api/models/recording_list_params.rbs +5 -1
  146. data/sig/surge_api/models/recording_retrieve_params.rbs +8 -3
  147. data/sig/surge_api/models/user_create_params.rbs +5 -0
  148. data/sig/surge_api/models/user_create_token_params.rbs +5 -1
  149. data/sig/surge_api/models/user_delete_params.rbs +8 -3
  150. data/sig/surge_api/models/user_list_params.rbs +5 -1
  151. data/sig/surge_api/models/user_retrieve_params.rbs +8 -3
  152. data/sig/surge_api/models/user_update_params.rbs +5 -0
  153. data/sig/surge_api/models/verification_check_params.rbs +6 -1
  154. data/sig/surge_api/models/verification_create_params.rbs +6 -1
  155. data/sig/surge_api/models.rbs +6 -0
  156. data/sig/surge_api/resources/accounts.rbs +6 -0
  157. data/sig/surge_api/resources/campaigns.rbs +2 -2
  158. data/sig/surge_api/resources/messages.rbs +1 -1
  159. data/sig/surge_api/resources/phone_numbers.rbs +12 -0
  160. data/sig/surge_api/resources/verifications.rbs +1 -0
  161. data/sig/surge_api/resources/webhooks.rbs +3 -1
  162. metadata +25 -2
@@ -7,6 +7,12 @@ module SurgeAPI
7
7
  extend SurgeAPI::Internal::Type::RequestParameters::Converter
8
8
  include SurgeAPI::Internal::Type::RequestParameters
9
9
 
10
+ # @!attribute account_id
11
+ # The account ID to list users for.
12
+ #
13
+ # @return [String]
14
+ required :account_id, String
15
+
10
16
  # @!attribute after
11
17
  # Cursor for forward pagination. Use the next_cursor from a previous response.
12
18
  #
@@ -20,10 +26,12 @@ module SurgeAPI
20
26
  # @return [String, nil]
21
27
  optional :before, String
22
28
 
23
- # @!method initialize(after: nil, before: nil, request_options: {})
29
+ # @!method initialize(account_id:, after: nil, before: nil, request_options: {})
24
30
  # Some parameter documentations has been truncated, see
25
31
  # {SurgeAPI::Models::UserListParams} for more details.
26
32
  #
33
+ # @param account_id [String] The account ID to list users for.
34
+ #
27
35
  # @param after [String] Cursor for forward pagination. Use the next_cursor from a previous response.
28
36
  #
29
37
  # @param before [String] Cursor for backward pagination. Use the previous_cursor from a previous response
@@ -7,7 +7,15 @@ module SurgeAPI
7
7
  extend SurgeAPI::Internal::Type::RequestParameters::Converter
8
8
  include SurgeAPI::Internal::Type::RequestParameters
9
9
 
10
- # @!method initialize(request_options: {})
10
+ # @!attribute id
11
+ # The ID of the user to retrieve.
12
+ #
13
+ # @return [String]
14
+ required :id, String
15
+
16
+ # @!method initialize(id:, request_options: {})
17
+ # @param id [String] The ID of the user to retrieve.
18
+ #
11
19
  # @param request_options [SurgeAPI::RequestOptions, Hash{Symbol=>Object}]
12
20
  end
13
21
  end
@@ -7,6 +7,12 @@ module SurgeAPI
7
7
  extend SurgeAPI::Internal::Type::RequestParameters::Converter
8
8
  include SurgeAPI::Internal::Type::RequestParameters
9
9
 
10
+ # @!attribute id
11
+ # The ID of the user to update.
12
+ #
13
+ # @return [String]
14
+ required :id, String
15
+
10
16
  # @!attribute first_name
11
17
  # The user's first name.
12
18
  #
@@ -31,7 +37,9 @@ module SurgeAPI
31
37
  # @return [String, nil]
32
38
  optional :photo_url, String
33
39
 
34
- # @!method initialize(first_name:, last_name: nil, metadata: nil, photo_url: nil, request_options: {})
40
+ # @!method initialize(id:, first_name:, last_name: nil, metadata: nil, photo_url: nil, request_options: {})
41
+ # @param id [String] The ID of the user to update.
42
+ #
35
43
  # @param first_name [String] The user's first name.
36
44
  #
37
45
  # @param last_name [String] The user's last name.
@@ -7,13 +7,21 @@ module SurgeAPI
7
7
  extend SurgeAPI::Internal::Type::RequestParameters::Converter
8
8
  include SurgeAPI::Internal::Type::RequestParameters
9
9
 
10
+ # @!attribute id
11
+ # The ID of the verification to check against.
12
+ #
13
+ # @return [String]
14
+ required :id, String
15
+
10
16
  # @!attribute code
11
17
  # The Verification code that was received.
12
18
  #
13
19
  # @return [String]
14
20
  required :code, String
15
21
 
16
- # @!method initialize(code:, request_options: {})
22
+ # @!method initialize(id:, code:, request_options: {})
23
+ # @param id [String] The ID of the verification to check against.
24
+ #
17
25
  # @param code [String] The Verification code that was received.
18
26
  #
19
27
  # @param request_options [SurgeAPI::RequestOptions, Hash{Symbol=>Object}]
@@ -7,13 +7,21 @@ module SurgeAPI
7
7
  extend SurgeAPI::Internal::Type::RequestParameters::Converter
8
8
  include SurgeAPI::Internal::Type::RequestParameters
9
9
 
10
+ # @!attribute account_id
11
+ # The account to associate with the verification.
12
+ #
13
+ # @return [String]
14
+ required :account_id, String
15
+
10
16
  # @!attribute phone_number
11
17
  # The phone number to be verified. In E.164 format.
12
18
  #
13
19
  # @return [String]
14
20
  required :phone_number, String
15
21
 
16
- # @!method initialize(phone_number:, request_options: {})
22
+ # @!method initialize(account_id:, phone_number:, request_options: {})
23
+ # @param account_id [String] The account to associate with the verification.
24
+ #
17
25
  # @param phone_number [String] The phone number to be verified. In E.164 format.
18
26
  #
19
27
  # @param request_options [SurgeAPI::RequestOptions, Hash{Symbol=>Object}]
@@ -45,6 +45,8 @@ module SurgeAPI
45
45
 
46
46
  AccountCreateParams = SurgeAPI::Models::AccountCreateParams
47
47
 
48
+ AccountListParams = SurgeAPI::Models::AccountListParams
49
+
48
50
  AccountRetrieveStatusParams = SurgeAPI::Models::AccountRetrieveStatusParams
49
51
 
50
52
  AccountStatus = SurgeAPI::Models::AccountStatus
@@ -127,6 +129,10 @@ module SurgeAPI
127
129
 
128
130
  PhoneNumberPurchaseParams = SurgeAPI::Models::PhoneNumberPurchaseParams
129
131
 
132
+ PhoneNumberReleaseParams = SurgeAPI::Models::PhoneNumberReleaseParams
133
+
134
+ PhoneNumberUpdateParams = SurgeAPI::Models::PhoneNumberUpdateParams
135
+
130
136
  RecordingCompletedWebhookEvent = SurgeAPI::Models::RecordingCompletedWebhookEvent
131
137
 
132
138
  RecordingDeleteParams = SurgeAPI::Models::RecordingDeleteParams
@@ -67,6 +67,35 @@ module SurgeAPI
67
67
  )
68
68
  end
69
69
 
70
+ # Some parameter documentations has been truncated, see
71
+ # {SurgeAPI::Models::AccountListParams} for more details.
72
+ #
73
+ # List all accounts for the calling platform with cursor-based pagination.
74
+ #
75
+ # @overload list(after: nil, before: nil, request_options: {})
76
+ #
77
+ # @param after [String] Cursor for forward pagination. Use the next_cursor from a previous response.
78
+ #
79
+ # @param before [String] Cursor for backward pagination. Use the previous_cursor from a previous response
80
+ #
81
+ # @param request_options [SurgeAPI::RequestOptions, Hash{Symbol=>Object}, nil]
82
+ #
83
+ # @return [SurgeAPI::Internal::Cursor<SurgeAPI::Models::Account>]
84
+ #
85
+ # @see SurgeAPI::Models::AccountListParams
86
+ def list(params = {})
87
+ parsed, options = SurgeAPI::AccountListParams.dump_request(params)
88
+ query = SurgeAPI::Internal::Util.encode_query_params(parsed)
89
+ @client.request(
90
+ method: :get,
91
+ path: "accounts",
92
+ query: query,
93
+ page: SurgeAPI::Internal::Cursor,
94
+ model: SurgeAPI::Account,
95
+ options: options
96
+ )
97
+ end
98
+
70
99
  # Archives an account and releases all associated resources.
71
100
  #
72
101
  # **Warning**: This action will:
@@ -12,7 +12,7 @@ module SurgeAPI
12
12
  #
13
13
  # @param account_id [String] The account for which the campaign should be created.
14
14
  #
15
- # @param campaign_params [SurgeAPI::CampaignParams] Parameters for creating a new campaign. Either provide full campaign details or
15
+ # @param campaign_params [SurgeAPI::Models::CampaignParams::StandardCampaignParams, SurgeAPI::Models::CampaignParams::ExternalCampaignParams] Parameters for creating a new campaign. Either provide full campaign details or
16
16
  #
17
17
  # @param request_options [SurgeAPI::RequestOptions, Hash{Symbol=>Object}, nil]
18
18
  #
@@ -21,15 +21,10 @@ module SurgeAPI
21
21
  # @see SurgeAPI::Models::CampaignCreateParams
22
22
  def create(account_id, params)
23
23
  parsed, options = SurgeAPI::CampaignCreateParams.dump_request(params)
24
- case parsed
25
- in {campaign_params: Hash => union, **rest}
26
- parsed = {**rest, **union}
27
- else
28
- end
29
24
  @client.request(
30
25
  method: :post,
31
26
  path: ["accounts/%1$s/campaigns", account_id],
32
- body: parsed,
27
+ body: parsed[:campaign_params],
33
28
  model: SurgeAPI::Campaign,
34
29
  options: options
35
30
  )
@@ -67,7 +62,7 @@ module SurgeAPI
67
62
  #
68
63
  # @param id [String] The ID of the campaign to update.
69
64
  #
70
- # @param campaign_params [SurgeAPI::CampaignParams] Parameters for creating a new campaign. Either provide full campaign details or
65
+ # @param campaign_params [SurgeAPI::Models::CampaignParams::StandardCampaignParams, SurgeAPI::Models::CampaignParams::ExternalCampaignParams] Parameters for creating a new campaign. Either provide full campaign details or
71
66
  #
72
67
  # @param request_options [SurgeAPI::RequestOptions, Hash{Symbol=>Object}, nil]
73
68
  #
@@ -76,15 +71,10 @@ module SurgeAPI
76
71
  # @see SurgeAPI::Models::CampaignUpdateParams
77
72
  def update(id, params)
78
73
  parsed, options = SurgeAPI::CampaignUpdateParams.dump_request(params)
79
- case parsed
80
- in {campaign_params: Hash => union, **rest}
81
- parsed = {**rest, **union}
82
- else
83
- end
84
74
  @client.request(
85
75
  method: :patch,
86
76
  path: ["campaigns/%1$s", id],
87
- body: parsed,
77
+ body: parsed[:campaign_params],
88
78
  model: SurgeAPI::Campaign,
89
79
  options: options
90
80
  )
@@ -32,11 +32,15 @@ module SurgeAPI
32
32
  # `conversation` field, and `conversation.phone_number` should be specified
33
33
  # instead.
34
34
  #
35
+ # Optionally, you can pass a `settings` object to override account-level settings
36
+ # for this message. Currently the only supported setting is `link_shortening`,
37
+ # which accepts `"enabled"` or `"disabled"`.
38
+ #
35
39
  # @overload create(account_id, message_params:, request_options: {})
36
40
  #
37
41
  # @param account_id [String] The account from which the message should be sent.
38
42
  #
39
- # @param message_params [SurgeAPI::MessageParams] Payload for creating a message. Either an attachment or the body must be given.
43
+ # @param message_params [SurgeAPI::Models::MessageParams::MessageParamsWithConversation, SurgeAPI::Models::MessageParams::SimpleMessageParams] Payload for creating a message. Either an attachment or the body must be given.
40
44
  #
41
45
  # @param request_options [SurgeAPI::RequestOptions, Hash{Symbol=>Object}, nil]
42
46
  #
@@ -45,15 +49,10 @@ module SurgeAPI
45
49
  # @see SurgeAPI::Models::MessageCreateParams
46
50
  def create(account_id, params)
47
51
  parsed, options = SurgeAPI::MessageCreateParams.dump_request(params)
48
- case parsed
49
- in {message_params: Hash => union, **rest}
50
- parsed = {**rest, **union}
51
- else
52
- end
53
52
  @client.request(
54
53
  method: :post,
55
54
  path: ["accounts/%1$s/messages", account_id],
56
- body: parsed,
55
+ body: parsed[:message_params],
57
56
  model: SurgeAPI::Message,
58
57
  options: options
59
58
  )
@@ -3,6 +3,32 @@
3
3
  module SurgeAPI
4
4
  module Resources
5
5
  class PhoneNumbers
6
+ # Updates a phone number's details.
7
+ #
8
+ # @overload update(id, campaign_id: nil, name: nil, request_options: {})
9
+ #
10
+ # @param id [String] The ID of the phone number to update.
11
+ #
12
+ # @param campaign_id [String] Campaign ID to attach this number to (`cpn_...`).
13
+ #
14
+ # @param name [String] A human-readable name for the phone number.
15
+ #
16
+ # @param request_options [SurgeAPI::RequestOptions, Hash{Symbol=>Object}, nil]
17
+ #
18
+ # @return [SurgeAPI::Models::PhoneNumber]
19
+ #
20
+ # @see SurgeAPI::Models::PhoneNumberUpdateParams
21
+ def update(id, params = {})
22
+ parsed, options = SurgeAPI::PhoneNumberUpdateParams.dump_request(params)
23
+ @client.request(
24
+ method: :patch,
25
+ path: ["phone_numbers/%1$s", id],
26
+ body: parsed,
27
+ model: SurgeAPI::PhoneNumber,
28
+ options: options
29
+ )
30
+ end
31
+
6
32
  # Some parameter documentations has been truncated, see
7
33
  # {SurgeAPI::Models::PhoneNumberListParams} for more details.
8
34
  #
@@ -70,6 +96,26 @@ module SurgeAPI
70
96
  )
71
97
  end
72
98
 
99
+ # Releases a phone number from the account.
100
+ #
101
+ # @overload release(id, request_options: {})
102
+ #
103
+ # @param id [String] The ID of the phone number to release.
104
+ #
105
+ # @param request_options [SurgeAPI::RequestOptions, Hash{Symbol=>Object}, nil]
106
+ #
107
+ # @return [SurgeAPI::Models::PhoneNumber]
108
+ #
109
+ # @see SurgeAPI::Models::PhoneNumberReleaseParams
110
+ def release(id, params = {})
111
+ @client.request(
112
+ method: :delete,
113
+ path: ["phone_numbers/%1$s", id],
114
+ model: SurgeAPI::PhoneNumber,
115
+ options: params[:request_options]
116
+ )
117
+ end
118
+
73
119
  # @api private
74
120
  #
75
121
  # @param client [SurgeAPI::Client]
@@ -3,9 +3,12 @@
3
3
  module SurgeAPI
4
4
  module Resources
5
5
  class Verifications
6
- # Creates a new Verification and sends the code to the given phone number.
6
+ # Creates a new Verification for an account and sends the code to the given phone
7
+ # number.
7
8
  #
8
- # @overload create(phone_number:, request_options: {})
9
+ # @overload create(account_id, phone_number:, request_options: {})
10
+ #
11
+ # @param account_id [String] The account to associate with the verification.
9
12
  #
10
13
  # @param phone_number [String] The phone number to be verified. In E.164 format.
11
14
  #
@@ -14,11 +17,11 @@ module SurgeAPI
14
17
  # @return [SurgeAPI::Models::Verification]
15
18
  #
16
19
  # @see SurgeAPI::Models::VerificationCreateParams
17
- def create(params)
20
+ def create(account_id, params)
18
21
  parsed, options = SurgeAPI::VerificationCreateParams.dump_request(params)
19
22
  @client.request(
20
23
  method: :post,
21
- path: "verifications",
24
+ path: ["accounts/%1$s/verifications", account_id],
22
25
  body: parsed,
23
26
  model: SurgeAPI::Verification,
24
27
  options: options
@@ -5,8 +5,18 @@ module SurgeAPI
5
5
  class Webhooks
6
6
  # @param payload [String] The raw webhook payload as a string
7
7
  #
8
+ # @param headers [Hash{String=>String}] The raw HTTP headers that came with the payload
9
+ #
10
+ # @param key [String, nil] The webhook signing key
11
+ #
8
12
  # @return [SurgeAPI::Models::CallEndedWebhookEvent, SurgeAPI::Models::CampaignApprovedWebhookEvent, SurgeAPI::Models::ContactOptedInWebhookEvent, SurgeAPI::Models::ContactOptedOutWebhookEvent, SurgeAPI::Models::ConversationCreatedWebhookEvent, SurgeAPI::Models::LinkFollowedWebhookEvent, SurgeAPI::Models::MessageDeliveredWebhookEvent, SurgeAPI::Models::MessageFailedWebhookEvent, SurgeAPI::Models::MessageReceivedWebhookEvent, SurgeAPI::Models::MessageSentWebhookEvent, SurgeAPI::Models::PhoneNumberAttachedToCampaignWebhookEvent, SurgeAPI::Models::RecordingCompletedWebhookEvent, SurgeAPI::Models::VoicemailReceivedWebhookEvent]
9
- def unwrap(payload)
13
+ def unwrap(payload, headers:, key: @client.webhook_signing_secret)
14
+ if key.nil?
15
+ raise ArgumentError.new("Cannot verify a webhook without a key on either the client's webhook_signing_secret or passed in as an argument")
16
+ end
17
+
18
+ ::StandardWebhooks::Webhook.new(key).verify(payload, headers)
19
+
10
20
  parsed = JSON.parse(payload, symbolize_names: true)
11
21
  SurgeAPI::Internal::Type::Converter.coerce(SurgeAPI::Models::UnwrapWebhookEvent, parsed)
12
22
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SurgeAPI
4
- VERSION = "0.16.0"
4
+ VERSION = "0.18.0"
5
5
  end
data/lib/surge_api.rb CHANGED
@@ -30,6 +30,7 @@ end
30
30
 
31
31
  # Gems.
32
32
  require "connection_pool"
33
+ require "standardwebhooks"
33
34
 
34
35
  # Package files.
35
36
  require_relative "surge_api/version"
@@ -58,6 +59,7 @@ require_relative "surge_api/models/message_params"
58
59
  require_relative "surge_api/models/account"
59
60
  require_relative "surge_api/models/account_archive_params"
60
61
  require_relative "surge_api/models/account_create_params"
62
+ require_relative "surge_api/models/account_list_params"
61
63
  require_relative "surge_api/models/account_retrieve_status_params"
62
64
  require_relative "surge_api/models/account_status"
63
65
  require_relative "surge_api/models/account_update_params"
@@ -99,6 +101,8 @@ require_relative "surge_api/models/phone_number"
99
101
  require_relative "surge_api/models/phone_number_attached_to_campaign_webhook_event"
100
102
  require_relative "surge_api/models/phone_number_list_params"
101
103
  require_relative "surge_api/models/phone_number_purchase_params"
104
+ require_relative "surge_api/models/phone_number_release_params"
105
+ require_relative "surge_api/models/phone_number_update_params"
102
106
  require_relative "surge_api/models/recording_completed_webhook_event"
103
107
  require_relative "surge_api/models/recording_delete_params"
104
108
  require_relative "surge_api/models/recording_delete_response"
@@ -13,6 +13,9 @@ module SurgeAPI
13
13
  sig { returns(String) }
14
14
  attr_reader :api_key
15
15
 
16
+ sig { returns(T.nilable(String)) }
17
+ attr_reader :webhook_signing_secret
18
+
16
19
  sig { returns(SurgeAPI::Resources::Accounts) }
17
20
  attr_reader :accounts
18
21
 
@@ -58,6 +61,7 @@ module SurgeAPI
58
61
  sig do
59
62
  params(
60
63
  api_key: T.nilable(String),
64
+ webhook_signing_secret: T.nilable(String),
61
65
  base_url: T.nilable(String),
62
66
  max_retries: Integer,
63
67
  timeout: Float,
@@ -68,6 +72,8 @@ module SurgeAPI
68
72
  def self.new(
69
73
  # Defaults to `ENV["SURGE_API_KEY"]`
70
74
  api_key: ENV["SURGE_API_KEY"],
75
+ # Defaults to `ENV["SURGE_WEBHOOK_SIGNING_SECRET"]`
76
+ webhook_signing_secret: ENV["SURGE_WEBHOOK_SIGNING_SECRET"],
71
77
  # Override the default base URL for the API, e.g.,
72
78
  # `"https://api.example.com/v2/"`. Defaults to `ENV["SURGE_BASE_URL"]`
73
79
  base_url: ENV["SURGE_BASE_URL"],
@@ -148,12 +148,20 @@ module SurgeAPI
148
148
  end
149
149
  end
150
150
 
151
+ # https://www.rfc-editor.org/rfc/rfc3986.html#section-3.3
152
+ RFC_3986_NOT_PCHARS = T.let(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/, Regexp)
153
+
151
154
  class << self
152
155
  # @api private
153
156
  sig { params(uri: URI::Generic).returns(String) }
154
157
  def uri_origin(uri)
155
158
  end
156
159
 
160
+ # @api private
161
+ sig { params(path: T.any(String, Integer)).returns(String) }
162
+ def encode_path(path)
163
+ end
164
+
157
165
  # @api private
158
166
  sig { params(path: T.any(String, T::Array[String])).returns(String) }
159
167
  def interpolate_path(path)
@@ -11,15 +11,28 @@ module SurgeAPI
11
11
  T.any(SurgeAPI::AccountArchiveParams, SurgeAPI::Internal::AnyHash)
12
12
  end
13
13
 
14
+ # The ID of the account to archive.
15
+ sig { returns(String) }
16
+ attr_accessor :id
17
+
14
18
  sig do
15
- params(request_options: SurgeAPI::RequestOptions::OrHash).returns(
16
- T.attached_class
17
- )
19
+ params(
20
+ id: String,
21
+ request_options: SurgeAPI::RequestOptions::OrHash
22
+ ).returns(T.attached_class)
18
23
  end
19
- def self.new(request_options: {})
24
+ def self.new(
25
+ # The ID of the account to archive.
26
+ id:,
27
+ request_options: {}
28
+ )
20
29
  end
21
30
 
22
- sig { override.returns({ request_options: SurgeAPI::RequestOptions }) }
31
+ sig do
32
+ override.returns(
33
+ { id: String, request_options: SurgeAPI::RequestOptions }
34
+ )
35
+ end
23
36
  def to_hash
24
37
  end
25
38
  end
@@ -0,0 +1,59 @@
1
+ # typed: strong
2
+
3
+ module SurgeAPI
4
+ module Models
5
+ class AccountListParams < SurgeAPI::Internal::Type::BaseModel
6
+ extend SurgeAPI::Internal::Type::RequestParameters::Converter
7
+ include SurgeAPI::Internal::Type::RequestParameters
8
+
9
+ OrHash =
10
+ T.type_alias do
11
+ T.any(SurgeAPI::AccountListParams, SurgeAPI::Internal::AnyHash)
12
+ end
13
+
14
+ # Cursor for forward pagination. Use the next_cursor from a previous response.
15
+ sig { returns(T.nilable(String)) }
16
+ attr_reader :after
17
+
18
+ sig { params(after: String).void }
19
+ attr_writer :after
20
+
21
+ # Cursor for backward pagination. Use the previous_cursor from a previous
22
+ # response.
23
+ sig { returns(T.nilable(String)) }
24
+ attr_reader :before
25
+
26
+ sig { params(before: String).void }
27
+ attr_writer :before
28
+
29
+ sig do
30
+ params(
31
+ after: String,
32
+ before: String,
33
+ request_options: SurgeAPI::RequestOptions::OrHash
34
+ ).returns(T.attached_class)
35
+ end
36
+ def self.new(
37
+ # Cursor for forward pagination. Use the next_cursor from a previous response.
38
+ after: nil,
39
+ # Cursor for backward pagination. Use the previous_cursor from a previous
40
+ # response.
41
+ before: nil,
42
+ request_options: {}
43
+ )
44
+ end
45
+
46
+ sig do
47
+ override.returns(
48
+ {
49
+ after: String,
50
+ before: String,
51
+ request_options: SurgeAPI::RequestOptions
52
+ }
53
+ )
54
+ end
55
+ def to_hash
56
+ end
57
+ end
58
+ end
59
+ end
@@ -14,6 +14,10 @@ module SurgeAPI
14
14
  )
15
15
  end
16
16
 
17
+ # ID of the account to check
18
+ sig { returns(String) }
19
+ attr_accessor :account_id
20
+
17
21
  # capabilities about which to check the status
18
22
  sig do
19
23
  returns(
@@ -38,6 +42,7 @@ module SurgeAPI
38
42
 
39
43
  sig do
40
44
  params(
45
+ account_id: String,
41
46
  capabilities:
42
47
  T::Array[
43
48
  SurgeAPI::AccountRetrieveStatusParams::Capability::OrSymbol
@@ -46,6 +51,8 @@ module SurgeAPI
46
51
  ).returns(T.attached_class)
47
52
  end
48
53
  def self.new(
54
+ # ID of the account to check
55
+ account_id:,
49
56
  # capabilities about which to check the status
50
57
  capabilities: nil,
51
58
  request_options: {}
@@ -55,6 +62,7 @@ module SurgeAPI
55
62
  sig do
56
63
  override.returns(
57
64
  {
65
+ account_id: String,
58
66
  capabilities:
59
67
  T::Array[
60
68
  SurgeAPI::AccountRetrieveStatusParams::Capability::OrSymbol
@@ -11,6 +11,10 @@ module SurgeAPI
11
11
  T.any(SurgeAPI::AccountUpdateParams, SurgeAPI::Internal::AnyHash)
12
12
  end
13
13
 
14
+ # The ID for the account to update.
15
+ sig { returns(String) }
16
+ attr_accessor :id
17
+
14
18
  # The name by which the people this account communicates with know it. If not
15
19
  # provided, this will match the name field.
16
20
  sig { returns(T.nilable(String)) }
@@ -48,6 +52,7 @@ module SurgeAPI
48
52
 
49
53
  sig do
50
54
  params(
55
+ id: String,
51
56
  brand_name: String,
52
57
  name: String,
53
58
  organization: SurgeAPI::AccountUpdateParams::Organization::OrHash,
@@ -56,6 +61,8 @@ module SurgeAPI
56
61
  ).returns(T.attached_class)
57
62
  end
58
63
  def self.new(
64
+ # The ID for the account to update.
65
+ id:,
59
66
  # The name by which the people this account communicates with know it. If not
60
67
  # provided, this will match the name field.
61
68
  brand_name: nil,
@@ -77,6 +84,7 @@ module SurgeAPI
77
84
  sig do
78
85
  override.returns(
79
86
  {
87
+ id: String,
80
88
  brand_name: String,
81
89
  name: String,
82
90
  organization: SurgeAPI::AccountUpdateParams::Organization,
@@ -11,15 +11,28 @@ module SurgeAPI
11
11
  T.any(SurgeAPI::AttachmentGetFileParams, SurgeAPI::Internal::AnyHash)
12
12
  end
13
13
 
14
+ # The ID of the attachment.
15
+ sig { returns(String) }
16
+ attr_accessor :attachment_id
17
+
14
18
  sig do
15
- params(request_options: SurgeAPI::RequestOptions::OrHash).returns(
16
- T.attached_class
17
- )
19
+ params(
20
+ attachment_id: String,
21
+ request_options: SurgeAPI::RequestOptions::OrHash
22
+ ).returns(T.attached_class)
18
23
  end
19
- def self.new(request_options: {})
24
+ def self.new(
25
+ # The ID of the attachment.
26
+ attachment_id:,
27
+ request_options: {}
28
+ )
20
29
  end
21
30
 
22
- sig { override.returns({ request_options: SurgeAPI::RequestOptions }) }
31
+ sig do
32
+ override.returns(
33
+ { attachment_id: String, request_options: SurgeAPI::RequestOptions }
34
+ )
35
+ end
23
36
  def to_hash
24
37
  end
25
38
  end