surge_api 0.1.0 → 0.2.1

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 (50) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +39 -0
  3. data/README.md +12 -63
  4. data/lib/surge_api/file_part.rb +10 -7
  5. data/lib/surge_api/internal/transport/pooled_net_requester.rb +34 -31
  6. data/lib/surge_api/internal/type/file_input.rb +7 -4
  7. data/lib/surge_api/internal/type/union.rb +1 -1
  8. data/lib/surge_api/internal/util.rb +5 -5
  9. data/lib/surge_api/models/account_create_params.rb +13 -6
  10. data/lib/surge_api/models/account_update_params.rb +13 -6
  11. data/lib/surge_api/models/campaign_create_params.rb +7 -183
  12. data/lib/surge_api/models/campaign_params.rb +228 -0
  13. data/lib/surge_api/models/contact_opted_in_webhook_event.rb +54 -0
  14. data/lib/surge_api/models/contact_opted_out_webhook_event.rb +54 -0
  15. data/lib/surge_api/models/message_create_params.rb +8 -134
  16. data/lib/surge_api/models/message_params.rb +216 -0
  17. data/lib/surge_api/models/unwrap_webhook_event.rb +5 -1
  18. data/lib/surge_api/models.rb +8 -0
  19. data/lib/surge_api/resources/campaigns.rb +7 -18
  20. data/lib/surge_api/resources/messages.rb +7 -12
  21. data/lib/surge_api/resources/webhooks.rb +1 -1
  22. data/lib/surge_api/version.rb +1 -1
  23. data/lib/surge_api.rb +4 -0
  24. data/rbi/surge_api/file_part.rbi +1 -1
  25. data/rbi/surge_api/models/account_create_params.rbi +19 -8
  26. data/rbi/surge_api/models/account_update_params.rbi +19 -8
  27. data/rbi/surge_api/models/campaign_create_params.rbi +20 -346
  28. data/rbi/surge_api/models/campaign_params.rbi +481 -0
  29. data/rbi/surge_api/models/contact_opted_in_webhook_event.rbi +95 -0
  30. data/rbi/surge_api/models/contact_opted_out_webhook_event.rbi +95 -0
  31. data/rbi/surge_api/models/message_create_params.rbi +24 -243
  32. data/rbi/surge_api/models/message_params.rbi +430 -0
  33. data/rbi/surge_api/models/unwrap_webhook_event.rbi +2 -0
  34. data/rbi/surge_api/models.rbi +8 -0
  35. data/rbi/surge_api/resources/campaigns.rbi +4 -89
  36. data/rbi/surge_api/resources/messages.rbi +5 -22
  37. data/rbi/surge_api/resources/webhooks.rbi +2 -0
  38. data/sig/surge_api/file_part.rbs +1 -1
  39. data/sig/surge_api/models/campaign_create_params.rbs +7 -106
  40. data/sig/surge_api/models/campaign_params.rbs +141 -0
  41. data/sig/surge_api/models/contact_opted_in_webhook_event.rbs +45 -0
  42. data/sig/surge_api/models/contact_opted_out_webhook_event.rbs +45 -0
  43. data/sig/surge_api/models/message_create_params.rbs +7 -119
  44. data/sig/surge_api/models/message_params.rbs +189 -0
  45. data/sig/surge_api/models/unwrap_webhook_event.rbs +2 -0
  46. data/sig/surge_api/models.rbs +8 -0
  47. data/sig/surge_api/resources/campaigns.rbs +1 -9
  48. data/sig/surge_api/resources/messages.rbs +1 -6
  49. data/sig/surge_api/resources/webhooks.rbs +2 -0
  50. metadata +14 -2
@@ -7,147 +7,21 @@ module SurgeAPI
7
7
  extend SurgeAPI::Internal::Type::RequestParameters::Converter
8
8
  include SurgeAPI::Internal::Type::RequestParameters
9
9
 
10
- # @!attribute conversation
11
- # Params for selecting or creating a new conversation. Either the id or the
12
- # Contact must be given.
10
+ # @!attribute message_params
11
+ # Payload for creating a message. Either an attachment or the body must be given.
12
+ # You can specify the recipient either using the 'conversation' parameter or the
13
+ # 'to'/'from' parameters, but not both.
13
14
  #
14
- # @return [SurgeAPI::Models::MessageCreateParams::Conversation]
15
- required :conversation, -> { SurgeAPI::MessageCreateParams::Conversation }
15
+ # @return [SurgeAPI::Models::MessageParams::MessageParamsWithConversation, SurgeAPI::Models::MessageParams::SimpleMessageParams]
16
+ required :message_params, union: -> { SurgeAPI::MessageParams }
16
17
 
17
- # @!attribute attachments
18
- #
19
- # @return [Array<SurgeAPI::Models::MessageCreateParams::Attachment>, nil]
20
- optional :attachments, -> { SurgeAPI::Internal::Type::ArrayOf[SurgeAPI::MessageCreateParams::Attachment] }
21
-
22
- # @!attribute body
23
- # The message body.
24
- #
25
- # @return [String, nil]
26
- optional :body, String
27
-
28
- # @!attribute send_at
29
- # An optional datetime for scheduling message up to a couple of months in the
30
- # future.
31
- #
32
- # @return [Time, nil]
33
- optional :send_at, Time
34
-
35
- # @!attribute to
36
- # The recipient's phone number in E.164 format. Cannot be used together with
37
- # 'conversation'.
38
- #
39
- # @return [String]
40
- required :to, String
41
-
42
- # @!attribute from
43
- # The sender's phone number in E.164 format or phone number ID. If omitted, uses
44
- # the account's default phone number. Cannot be used together with 'conversation'.
45
- #
46
- # @return [String, nil]
47
- optional :from, String
48
-
49
- # @!method initialize(conversation:, to:, attachments: nil, body: nil, send_at: nil, from: nil, request_options: {})
18
+ # @!method initialize(message_params:, request_options: {})
50
19
  # Some parameter documentations has been truncated, see
51
20
  # {SurgeAPI::Models::MessageCreateParams} for more details.
52
21
  #
53
- # @param conversation [SurgeAPI::Models::MessageCreateParams::Conversation] Params for selecting or creating a new conversation. Either the id or the Contac
54
- #
55
- # @param to [String] The recipient's phone number in E.164 format. Cannot be used together with 'conv
56
- #
57
- # @param attachments [Array<SurgeAPI::Models::MessageCreateParams::Attachment>]
58
- #
59
- # @param body [String] The message body.
60
- #
61
- # @param send_at [Time] An optional datetime for scheduling message up to a couple of months in the futu
62
- #
63
- # @param from [String] The sender's phone number in E.164 format or phone number ID. If omitted, uses t
22
+ # @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.
64
23
  #
65
24
  # @param request_options [SurgeAPI::RequestOptions, Hash{Symbol=>Object}]
66
-
67
- class Conversation < SurgeAPI::Internal::Type::BaseModel
68
- # @!attribute contact
69
- # Parameters for creating a contact
70
- #
71
- # @return [SurgeAPI::Models::MessageCreateParams::Conversation::Contact]
72
- required :contact, -> { SurgeAPI::MessageCreateParams::Conversation::Contact }
73
-
74
- # @!attribute phone_number
75
- # The phone number from which to send the message. This can be either the phone
76
- # number in E.164 format or a Surge phone number id.
77
- #
78
- # @return [String, nil]
79
- optional :phone_number, String
80
-
81
- # @!method initialize(contact:, phone_number: nil)
82
- # Some parameter documentations has been truncated, see
83
- # {SurgeAPI::Models::MessageCreateParams::Conversation} for more details.
84
- #
85
- # Params for selecting or creating a new conversation. Either the id or the
86
- # Contact must be given.
87
- #
88
- # @param contact [SurgeAPI::Models::MessageCreateParams::Conversation::Contact] Parameters for creating a contact
89
- #
90
- # @param phone_number [String] The phone number from which to send the message. This can be either the phone nu
91
-
92
- # @see SurgeAPI::Models::MessageCreateParams::Conversation#contact
93
- class Contact < SurgeAPI::Internal::Type::BaseModel
94
- # @!attribute phone_number
95
- # The contact's phone number in E.164 format.
96
- #
97
- # @return [String]
98
- required :phone_number, String
99
-
100
- # @!attribute email
101
- # The contact's email address.
102
- #
103
- # @return [String, nil]
104
- optional :email, String
105
-
106
- # @!attribute first_name
107
- # The contact's first name.
108
- #
109
- # @return [String, nil]
110
- optional :first_name, String
111
-
112
- # @!attribute last_name
113
- # The contact's last name.
114
- #
115
- # @return [String, nil]
116
- optional :last_name, String
117
-
118
- # @!attribute metadata
119
- # Set of key-value pairs that will be stored with the object.
120
- #
121
- # @return [Hash{Symbol=>String}, nil]
122
- optional :metadata, SurgeAPI::Internal::Type::HashOf[String]
123
-
124
- # @!method initialize(phone_number:, email: nil, first_name: nil, last_name: nil, metadata: nil)
125
- # Parameters for creating a contact
126
- #
127
- # @param phone_number [String] The contact's phone number in E.164 format.
128
- #
129
- # @param email [String] The contact's email address.
130
- #
131
- # @param first_name [String] The contact's first name.
132
- #
133
- # @param last_name [String] The contact's last name.
134
- #
135
- # @param metadata [Hash{Symbol=>String}] Set of key-value pairs that will be stored with the object.
136
- end
137
- end
138
-
139
- class Attachment < SurgeAPI::Internal::Type::BaseModel
140
- # @!attribute url
141
- # The URL of the attachment.
142
- #
143
- # @return [String]
144
- required :url, String
145
-
146
- # @!method initialize(url:)
147
- # Params for creating an attachment
148
- #
149
- # @param url [String] The URL of the attachment.
150
- end
151
25
  end
152
26
  end
153
27
  end
@@ -0,0 +1,216 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SurgeAPI
4
+ module Models
5
+ # Payload for creating a message. Either an attachment or the body must be given.
6
+ # You can specify the recipient either using the 'conversation' parameter or the
7
+ # 'to'/'from' parameters, but not both.
8
+ module MessageParams
9
+ extend SurgeAPI::Internal::Type::Union
10
+
11
+ # Create a message while including parameters for the conversation in which the message should be sent.
12
+ variant -> { SurgeAPI::MessageParams::MessageParamsWithConversation }
13
+
14
+ # Create a basic message by specifying just the to/from phone numbers.
15
+ variant -> { SurgeAPI::MessageParams::SimpleMessageParams }
16
+
17
+ class MessageParamsWithConversation < SurgeAPI::Internal::Type::BaseModel
18
+ # @!attribute conversation
19
+ # Params for selecting or creating a new conversation. Either the id or the
20
+ # Contact must be given.
21
+ #
22
+ # @return [SurgeAPI::Models::MessageParams::MessageParamsWithConversation::Conversation]
23
+ required :conversation, -> { SurgeAPI::MessageParams::MessageParamsWithConversation::Conversation }
24
+
25
+ # @!attribute attachments
26
+ #
27
+ # @return [Array<SurgeAPI::Models::MessageParams::MessageParamsWithConversation::Attachment>, nil]
28
+ optional :attachments,
29
+ -> { SurgeAPI::Internal::Type::ArrayOf[SurgeAPI::MessageParams::MessageParamsWithConversation::Attachment] }
30
+
31
+ # @!attribute body
32
+ # The message body.
33
+ #
34
+ # @return [String, nil]
35
+ optional :body, String
36
+
37
+ # @!attribute send_at
38
+ # An optional datetime for scheduling message up to a couple of months in the
39
+ # future.
40
+ #
41
+ # @return [Time, nil]
42
+ optional :send_at, Time
43
+
44
+ # @!method initialize(conversation:, attachments: nil, body: nil, send_at: nil)
45
+ # Some parameter documentations has been truncated, see
46
+ # {SurgeAPI::Models::MessageParams::MessageParamsWithConversation} for more
47
+ # details.
48
+ #
49
+ # Create a message while including parameters for the conversation in which the
50
+ # message should be sent.
51
+ #
52
+ # @param conversation [SurgeAPI::Models::MessageParams::MessageParamsWithConversation::Conversation] Params for selecting or creating a new conversation. Either the id or the Contac
53
+ #
54
+ # @param attachments [Array<SurgeAPI::Models::MessageParams::MessageParamsWithConversation::Attachment>]
55
+ #
56
+ # @param body [String] The message body.
57
+ #
58
+ # @param send_at [Time] An optional datetime for scheduling message up to a couple of months in the futu
59
+
60
+ # @see SurgeAPI::Models::MessageParams::MessageParamsWithConversation#conversation
61
+ class Conversation < SurgeAPI::Internal::Type::BaseModel
62
+ # @!attribute contact
63
+ # Parameters for creating a contact
64
+ #
65
+ # @return [SurgeAPI::Models::MessageParams::MessageParamsWithConversation::Conversation::Contact]
66
+ required :contact, -> { SurgeAPI::MessageParams::MessageParamsWithConversation::Conversation::Contact }
67
+
68
+ # @!attribute phone_number
69
+ # The phone number from which to send the message. This can be either the phone
70
+ # number in E.164 format or a Surge phone number id.
71
+ #
72
+ # @return [String, nil]
73
+ optional :phone_number, String
74
+
75
+ # @!method initialize(contact:, phone_number: nil)
76
+ # Some parameter documentations has been truncated, see
77
+ # {SurgeAPI::Models::MessageParams::MessageParamsWithConversation::Conversation}
78
+ # for more details.
79
+ #
80
+ # Params for selecting or creating a new conversation. Either the id or the
81
+ # Contact must be given.
82
+ #
83
+ # @param contact [SurgeAPI::Models::MessageParams::MessageParamsWithConversation::Conversation::Contact] Parameters for creating a contact
84
+ #
85
+ # @param phone_number [String] The phone number from which to send the message. This can be either the phone nu
86
+
87
+ # @see SurgeAPI::Models::MessageParams::MessageParamsWithConversation::Conversation#contact
88
+ class Contact < SurgeAPI::Internal::Type::BaseModel
89
+ # @!attribute phone_number
90
+ # The contact's phone number in E.164 format.
91
+ #
92
+ # @return [String]
93
+ required :phone_number, String
94
+
95
+ # @!attribute email
96
+ # The contact's email address.
97
+ #
98
+ # @return [String, nil]
99
+ optional :email, String
100
+
101
+ # @!attribute first_name
102
+ # The contact's first name.
103
+ #
104
+ # @return [String, nil]
105
+ optional :first_name, String
106
+
107
+ # @!attribute last_name
108
+ # The contact's last name.
109
+ #
110
+ # @return [String, nil]
111
+ optional :last_name, String
112
+
113
+ # @!attribute metadata
114
+ # Set of key-value pairs that will be stored with the object.
115
+ #
116
+ # @return [Hash{Symbol=>String}, nil]
117
+ optional :metadata, SurgeAPI::Internal::Type::HashOf[String]
118
+
119
+ # @!method initialize(phone_number:, email: nil, first_name: nil, last_name: nil, metadata: nil)
120
+ # Parameters for creating a contact
121
+ #
122
+ # @param phone_number [String] The contact's phone number in E.164 format.
123
+ #
124
+ # @param email [String] The contact's email address.
125
+ #
126
+ # @param first_name [String] The contact's first name.
127
+ #
128
+ # @param last_name [String] The contact's last name.
129
+ #
130
+ # @param metadata [Hash{Symbol=>String}] Set of key-value pairs that will be stored with the object.
131
+ end
132
+ end
133
+
134
+ class Attachment < SurgeAPI::Internal::Type::BaseModel
135
+ # @!attribute url
136
+ # The URL of the attachment.
137
+ #
138
+ # @return [String]
139
+ required :url, String
140
+
141
+ # @!method initialize(url:)
142
+ # Params for creating an attachment
143
+ #
144
+ # @param url [String] The URL of the attachment.
145
+ end
146
+ end
147
+
148
+ class SimpleMessageParams < SurgeAPI::Internal::Type::BaseModel
149
+ # @!attribute to
150
+ # The recipient's phone number in E.164 format. Cannot be used together with
151
+ # 'conversation'.
152
+ #
153
+ # @return [String]
154
+ required :to, String
155
+
156
+ # @!attribute attachments
157
+ #
158
+ # @return [Array<SurgeAPI::Models::MessageParams::SimpleMessageParams::Attachment>, nil]
159
+ optional :attachments,
160
+ -> { SurgeAPI::Internal::Type::ArrayOf[SurgeAPI::MessageParams::SimpleMessageParams::Attachment] }
161
+
162
+ # @!attribute body
163
+ # The message body.
164
+ #
165
+ # @return [String, nil]
166
+ optional :body, String
167
+
168
+ # @!attribute from
169
+ # The sender's phone number in E.164 format or phone number ID. If omitted, uses
170
+ # the account's default phone number. Cannot be used together with 'conversation'.
171
+ #
172
+ # @return [String, nil]
173
+ optional :from, String
174
+
175
+ # @!attribute send_at
176
+ # An optional datetime for scheduling message up to a couple of months in the
177
+ # future.
178
+ #
179
+ # @return [Time, nil]
180
+ optional :send_at, Time
181
+
182
+ # @!method initialize(to:, attachments: nil, body: nil, from: nil, send_at: nil)
183
+ # Some parameter documentations has been truncated, see
184
+ # {SurgeAPI::Models::MessageParams::SimpleMessageParams} for more details.
185
+ #
186
+ # Create a basic message by specifying just the to/from phone numbers.
187
+ #
188
+ # @param to [String] The recipient's phone number in E.164 format. Cannot be used together with 'conv
189
+ #
190
+ # @param attachments [Array<SurgeAPI::Models::MessageParams::SimpleMessageParams::Attachment>]
191
+ #
192
+ # @param body [String] The message body.
193
+ #
194
+ # @param from [String] The sender's phone number in E.164 format or phone number ID. If omitted, uses t
195
+ #
196
+ # @param send_at [Time] An optional datetime for scheduling message up to a couple of months in the futu
197
+
198
+ class Attachment < SurgeAPI::Internal::Type::BaseModel
199
+ # @!attribute url
200
+ # The URL of the attachment.
201
+ #
202
+ # @return [String]
203
+ required :url, String
204
+
205
+ # @!method initialize(url:)
206
+ # Params for creating an attachment
207
+ #
208
+ # @param url [String] The URL of the attachment.
209
+ end
210
+ end
211
+
212
+ # @!method self.variants
213
+ # @return [Array(SurgeAPI::Models::MessageParams::MessageParamsWithConversation, SurgeAPI::Models::MessageParams::SimpleMessageParams)]
214
+ end
215
+ end
216
+ end
@@ -9,6 +9,10 @@ module SurgeAPI
9
9
 
10
10
  variant -> { SurgeAPI::CampaignApprovedWebhookEvent }
11
11
 
12
+ variant -> { SurgeAPI::ContactOptedInWebhookEvent }
13
+
14
+ variant -> { SurgeAPI::ContactOptedOutWebhookEvent }
15
+
12
16
  variant -> { SurgeAPI::ConversationCreatedWebhookEvent }
13
17
 
14
18
  variant -> { SurgeAPI::MessageDeliveredWebhookEvent }
@@ -20,7 +24,7 @@ module SurgeAPI
20
24
  variant -> { SurgeAPI::MessageSentWebhookEvent }
21
25
 
22
26
  # @!method self.variants
23
- # @return [Array(SurgeAPI::Models::CallEndedWebhookEvent, SurgeAPI::Models::CampaignApprovedWebhookEvent, SurgeAPI::Models::ConversationCreatedWebhookEvent, SurgeAPI::Models::MessageDeliveredWebhookEvent, SurgeAPI::Models::MessageFailedWebhookEvent, SurgeAPI::Models::MessageReceivedWebhookEvent, SurgeAPI::Models::MessageSentWebhookEvent)]
27
+ # @return [Array(SurgeAPI::Models::CallEndedWebhookEvent, SurgeAPI::Models::CampaignApprovedWebhookEvent, SurgeAPI::Models::ContactOptedInWebhookEvent, SurgeAPI::Models::ContactOptedOutWebhookEvent, SurgeAPI::Models::ConversationCreatedWebhookEvent, SurgeAPI::Models::MessageDeliveredWebhookEvent, SurgeAPI::Models::MessageFailedWebhookEvent, SurgeAPI::Models::MessageReceivedWebhookEvent, SurgeAPI::Models::MessageSentWebhookEvent)]
24
28
  end
25
29
  end
26
30
  end
@@ -61,10 +61,16 @@ module SurgeAPI
61
61
 
62
62
  CampaignCreateParams = SurgeAPI::Models::CampaignCreateParams
63
63
 
64
+ CampaignParams = SurgeAPI::Models::CampaignParams
65
+
64
66
  Contact = SurgeAPI::Models::Contact
65
67
 
66
68
  ContactCreateParams = SurgeAPI::Models::ContactCreateParams
67
69
 
70
+ ContactOptedInWebhookEvent = SurgeAPI::Models::ContactOptedInWebhookEvent
71
+
72
+ ContactOptedOutWebhookEvent = SurgeAPI::Models::ContactOptedOutWebhookEvent
73
+
68
74
  ContactRetrieveParams = SurgeAPI::Models::ContactRetrieveParams
69
75
 
70
76
  ContactUpdateParams = SurgeAPI::Models::ContactUpdateParams
@@ -81,6 +87,8 @@ module SurgeAPI
81
87
 
82
88
  MessageFailedWebhookEvent = SurgeAPI::Models::MessageFailedWebhookEvent
83
89
 
90
+ MessageParams = SurgeAPI::Models::MessageParams
91
+
84
92
  MessageReceivedWebhookEvent = SurgeAPI::Models::MessageReceivedWebhookEvent
85
93
 
86
94
  MessageSentWebhookEvent = SurgeAPI::Models::MessageSentWebhookEvent
@@ -8,27 +8,11 @@ module SurgeAPI
8
8
  #
9
9
  # Creates a campaign to register account to send text messages.
10
10
  #
11
- # @overload create(account_id, consent_flow:, description:, message_samples:, privacy_policy_url:, use_cases:, volume:, includes: nil, link_sample: nil, terms_and_conditions_url: nil, request_options: {})
11
+ # @overload create(account_id, campaign_params:, request_options: {})
12
12
  #
13
13
  # @param account_id [String] The account for which the campaign should be created.
14
14
  #
15
- # @param consent_flow [String] A string explaining the method through which end users will opt in to receive me
16
- #
17
- # @param description [String] An explanation of the organization's purpose and how it will be using text messa
18
- #
19
- # @param message_samples [Array<String>] An array of 2-5 strings with examples of the messages that will be sent from thi
20
- #
21
- # @param privacy_policy_url [String] The URL of the privacy policy for the brand in question. This may be a shared pr
22
- #
23
- # @param use_cases [Array<Symbol, SurgeAPI::Models::CampaignCreateParams::UseCase>] A list containing 1-5 types of messages that will be sent with this campaign.
24
- #
25
- # @param volume [Symbol, SurgeAPI::Models::CampaignCreateParams::Volume] This will be one of the following:
26
- #
27
- # @param includes [Array<Symbol, SurgeAPI::Models::CampaignCreateParams::Include>] A list of properties that this campaign should include. These properties can be
28
- #
29
- # @param link_sample [String] A sample link that might be sent by this campaign. If links from other domains a
30
- #
31
- # @param terms_and_conditions_url [String] The URL of the terms and conditions presented to end users when they opt in to m
15
+ # @param campaign_params [SurgeAPI::CampaignParams] Parameters for creating a new campaign. Either provide full campaign details or
32
16
  #
33
17
  # @param request_options [SurgeAPI::RequestOptions, Hash{Symbol=>Object}, nil]
34
18
  #
@@ -37,6 +21,11 @@ module SurgeAPI
37
21
  # @see SurgeAPI::Models::CampaignCreateParams
38
22
  def create(account_id, params)
39
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
40
29
  @client.request(
41
30
  method: :post,
42
31
  path: ["accounts/%1$s/campaigns", account_id],
@@ -32,21 +32,11 @@ module SurgeAPI
32
32
  # `conversation` field, and `conversation.phone_number` should be specified
33
33
  # instead.
34
34
  #
35
- # @overload create(account_id, conversation:, to:, attachments: nil, body: nil, send_at: nil, from: nil, request_options: {})
35
+ # @overload create(account_id, message_params:, request_options: {})
36
36
  #
37
37
  # @param account_id [String] The account from which the message should be sent.
38
38
  #
39
- # @param conversation [SurgeAPI::Models::MessageCreateParams::Conversation] Params for selecting or creating a new conversation. Either the id or the Contac
40
- #
41
- # @param to [String] The recipient's phone number in E.164 format. Cannot be used together with 'conv
42
- #
43
- # @param attachments [Array<SurgeAPI::Models::MessageCreateParams::Attachment>]
44
- #
45
- # @param body [String] The message body.
46
- #
47
- # @param send_at [Time] An optional datetime for scheduling message up to a couple of months in the futu
48
- #
49
- # @param from [String] The sender's phone number in E.164 format or phone number ID. If omitted, uses t
39
+ # @param message_params [SurgeAPI::MessageParams] Payload for creating a message. Either an attachment or the body must be given.
50
40
  #
51
41
  # @param request_options [SurgeAPI::RequestOptions, Hash{Symbol=>Object}, nil]
52
42
  #
@@ -55,6 +45,11 @@ module SurgeAPI
55
45
  # @see SurgeAPI::Models::MessageCreateParams
56
46
  def create(account_id, params)
57
47
  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
58
53
  @client.request(
59
54
  method: :post,
60
55
  path: ["accounts/%1$s/messages", account_id],
@@ -5,7 +5,7 @@ module SurgeAPI
5
5
  class Webhooks
6
6
  # @param payload [String] The raw webhook payload as a string
7
7
  #
8
- # @return [SurgeAPI::Models::CallEndedWebhookEvent, SurgeAPI::Models::CampaignApprovedWebhookEvent, SurgeAPI::Models::ConversationCreatedWebhookEvent, SurgeAPI::Models::MessageDeliveredWebhookEvent, SurgeAPI::Models::MessageFailedWebhookEvent, SurgeAPI::Models::MessageReceivedWebhookEvent, SurgeAPI::Models::MessageSentWebhookEvent]
8
+ # @return [SurgeAPI::Models::CallEndedWebhookEvent, SurgeAPI::Models::CampaignApprovedWebhookEvent, SurgeAPI::Models::ContactOptedInWebhookEvent, SurgeAPI::Models::ContactOptedOutWebhookEvent, SurgeAPI::Models::ConversationCreatedWebhookEvent, SurgeAPI::Models::MessageDeliveredWebhookEvent, SurgeAPI::Models::MessageFailedWebhookEvent, SurgeAPI::Models::MessageReceivedWebhookEvent, SurgeAPI::Models::MessageSentWebhookEvent]
9
9
  def unwrap(payload)
10
10
  parsed = JSON.parse(payload, symbolize_names: true)
11
11
  SurgeAPI::Internal::Type::Converter.coerce(SurgeAPI::Models::UnwrapWebhookEvent, parsed)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SurgeAPI
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/surge_api.rb CHANGED
@@ -50,6 +50,8 @@ require_relative "surge_api/errors"
50
50
  require_relative "surge_api/internal/transport/base_client"
51
51
  require_relative "surge_api/internal/transport/pooled_net_requester"
52
52
  require_relative "surge_api/client"
53
+ require_relative "surge_api/models/campaign_params"
54
+ require_relative "surge_api/models/message_params"
53
55
  require_relative "surge_api/models/account"
54
56
  require_relative "surge_api/models/account_create_params"
55
57
  require_relative "surge_api/models/account_retrieve_status_params"
@@ -63,6 +65,8 @@ require_relative "surge_api/models/campaign_approved_webhook_event"
63
65
  require_relative "surge_api/models/campaign_create_params"
64
66
  require_relative "surge_api/models/contact"
65
67
  require_relative "surge_api/models/contact_create_params"
68
+ require_relative "surge_api/models/contact_opted_in_webhook_event"
69
+ require_relative "surge_api/models/contact_opted_out_webhook_event"
66
70
  require_relative "surge_api/models/contact_retrieve_params"
67
71
  require_relative "surge_api/models/contact_update_params"
68
72
  require_relative "surge_api/models/conversation_created_webhook_event"
@@ -27,7 +27,7 @@ module SurgeAPI
27
27
  sig do
28
28
  params(
29
29
  content: T.any(Pathname, StringIO, IO, String),
30
- filename: T.nilable(String),
30
+ filename: T.nilable(T.any(Pathname, String)),
31
31
  content_type: T.nilable(String)
32
32
  ).returns(T.attached_class)
33
33
  end
@@ -112,8 +112,11 @@ module SurgeAPI
112
112
  end
113
113
  attr_writer :address
114
114
 
115
- # An object representing an individual who can be contacted if the carriers have
116
- # any questions about the business.
115
+ # An object representing an individual who can be contacted if Surge or our
116
+ # carrier partners have any questions about the business. If you are registering
117
+ # on behalf of your customer, this must be a contact from your customer's company
118
+ # rather than your own. The individual will likely never be contacted unless there
119
+ # are issues with spam.
117
120
  sig do
118
121
  returns(
119
122
  T.nilable(SurgeAPI::AccountCreateParams::Organization::Contact)
@@ -269,8 +272,11 @@ module SurgeAPI
269
272
  def self.new(
270
273
  # The address of the organization's headquarters.
271
274
  address: nil,
272
- # An object representing an individual who can be contacted if the carriers have
273
- # any questions about the business.
275
+ # An object representing an individual who can be contacted if Surge or our
276
+ # carrier partners have any questions about the business. If you are registering
277
+ # on behalf of your customer, this must be a contact from your customer's company
278
+ # rather than your own. The individual will likely never be contacted unless there
279
+ # are issues with spam.
274
280
  contact: nil,
275
281
  # The two character ISO 3166 country code for the country in which the
276
282
  # organization is headquartered.
@@ -455,7 +461,8 @@ module SurgeAPI
455
461
  # using the same domain name as the website URL will be preferred (e.g. with a
456
462
  # website domain of `https://dtprecisionauto.com`, an email like
457
463
  # `dom@dtprecisionauto.com` will be preferred over one like
458
- # `dom@anothergarage.com` or `dom.toretto@gmail.com`)
464
+ # `dom@anothergarage.com` or `dom.toretto@gmail.com`. `dtprecisionauto@gmail.com`
465
+ # would also be acceptable, but not preferred)
459
466
  sig { returns(T.nilable(String)) }
460
467
  attr_accessor :email
461
468
 
@@ -486,8 +493,11 @@ module SurgeAPI
486
493
  sig { returns(T.nilable(String)) }
487
494
  attr_accessor :title_other
488
495
 
489
- # An object representing an individual who can be contacted if the carriers have
490
- # any questions about the business.
496
+ # An object representing an individual who can be contacted if Surge or our
497
+ # carrier partners have any questions about the business. If you are registering
498
+ # on behalf of your customer, this must be a contact from your customer's company
499
+ # rather than your own. The individual will likely never be contacted unless there
500
+ # are issues with spam.
491
501
  sig do
492
502
  params(
493
503
  email: T.nilable(String),
@@ -506,7 +516,8 @@ module SurgeAPI
506
516
  # using the same domain name as the website URL will be preferred (e.g. with a
507
517
  # website domain of `https://dtprecisionauto.com`, an email like
508
518
  # `dom@dtprecisionauto.com` will be preferred over one like
509
- # `dom@anothergarage.com` or `dom.toretto@gmail.com`)
519
+ # `dom@anothergarage.com` or `dom.toretto@gmail.com`. `dtprecisionauto@gmail.com`
520
+ # would also be acceptable, but not preferred)
510
521
  email: nil,
511
522
  # The first name (or given name) of the individual
512
523
  first_name: nil,
@@ -113,8 +113,11 @@ module SurgeAPI
113
113
  end
114
114
  attr_writer :address
115
115
 
116
- # An object representing an individual who can be contacted if the carriers have
117
- # any questions about the business.
116
+ # An object representing an individual who can be contacted if Surge or our
117
+ # carrier partners have any questions about the business. If you are registering
118
+ # on behalf of your customer, this must be a contact from your customer's company
119
+ # rather than your own. The individual will likely never be contacted unless there
120
+ # are issues with spam.
118
121
  sig do
119
122
  returns(
120
123
  T.nilable(SurgeAPI::AccountUpdateParams::Organization::Contact)
@@ -270,8 +273,11 @@ module SurgeAPI
270
273
  def self.new(
271
274
  # The address of the organization's headquarters.
272
275
  address: nil,
273
- # An object representing an individual who can be contacted if the carriers have
274
- # any questions about the business.
276
+ # An object representing an individual who can be contacted if Surge or our
277
+ # carrier partners have any questions about the business. If you are registering
278
+ # on behalf of your customer, this must be a contact from your customer's company
279
+ # rather than your own. The individual will likely never be contacted unless there
280
+ # are issues with spam.
275
281
  contact: nil,
276
282
  # The two character ISO 3166 country code for the country in which the
277
283
  # organization is headquartered.
@@ -456,7 +462,8 @@ module SurgeAPI
456
462
  # using the same domain name as the website URL will be preferred (e.g. with a
457
463
  # website domain of `https://dtprecisionauto.com`, an email like
458
464
  # `dom@dtprecisionauto.com` will be preferred over one like
459
- # `dom@anothergarage.com` or `dom.toretto@gmail.com`)
465
+ # `dom@anothergarage.com` or `dom.toretto@gmail.com`. `dtprecisionauto@gmail.com`
466
+ # would also be acceptable, but not preferred)
460
467
  sig { returns(T.nilable(String)) }
461
468
  attr_accessor :email
462
469
 
@@ -487,8 +494,11 @@ module SurgeAPI
487
494
  sig { returns(T.nilable(String)) }
488
495
  attr_accessor :title_other
489
496
 
490
- # An object representing an individual who can be contacted if the carriers have
491
- # any questions about the business.
497
+ # An object representing an individual who can be contacted if Surge or our
498
+ # carrier partners have any questions about the business. If you are registering
499
+ # on behalf of your customer, this must be a contact from your customer's company
500
+ # rather than your own. The individual will likely never be contacted unless there
501
+ # are issues with spam.
492
502
  sig do
493
503
  params(
494
504
  email: T.nilable(String),
@@ -507,7 +517,8 @@ module SurgeAPI
507
517
  # using the same domain name as the website URL will be preferred (e.g. with a
508
518
  # website domain of `https://dtprecisionauto.com`, an email like
509
519
  # `dom@dtprecisionauto.com` will be preferred over one like
510
- # `dom@anothergarage.com` or `dom.toretto@gmail.com`)
520
+ # `dom@anothergarage.com` or `dom.toretto@gmail.com`. `dtprecisionauto@gmail.com`
521
+ # would also be acceptable, but not preferred)
511
522
  email: nil,
512
523
  # The first name (or given name) of the individual
513
524
  first_name: nil,