Skip to content

Commit 081f933

Browse files
authored
Add expiration field for messages to v10 (#86)
1 parent 1e826a4 commit 081f933

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

lib/bandwidth/messaging_lib/messaging/models/bandwidth_message.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ class BandwidthMessage < BaseModel
6161
# @return [String]
6262
attr_accessor :priority
6363

64+
# A string with the date/time value that the message will automatically expire by.
65+
# @return [String]
66+
attr_accessor :expiration
67+
6468
# A mapping from model property names to API property names.
6569
def self.names
6670
@_hash = {} if @_hash.nil?
@@ -76,6 +80,7 @@ def self.names
7680
@_hash['text'] = 'text'
7781
@_hash['tag'] = 'tag'
7882
@_hash['priority'] = 'priority'
83+
@_hash['expiration'] = 'expiration'
7984
@_hash
8085
end
8186

@@ -94,6 +99,7 @@ def optionals
9499
text
95100
tag
96101
priority
102+
expiration
97103
]
98104
end
99105

@@ -113,7 +119,8 @@ def initialize(id = nil,
113119
media = nil,
114120
text = nil,
115121
tag = nil,
116-
priority = nil)
122+
priority = nil,
123+
expiration = nil)
117124
@id = id unless id == SKIP
118125
@owner = owner unless owner == SKIP
119126
@application_id = application_id unless application_id == SKIP
@@ -126,6 +133,7 @@ def initialize(id = nil,
126133
@text = text unless text == SKIP
127134
@tag = tag unless tag == SKIP
128135
@priority = priority unless priority == SKIP
136+
@expiration = expiration unless expiration == SKIP
129137
end
130138

131139
# Creates an instance of the object from a hash.
@@ -145,6 +153,7 @@ def self.from_hash(hash)
145153
text = hash.key?('text') ? hash['text'] : SKIP
146154
tag = hash.key?('tag') ? hash['tag'] : SKIP
147155
priority = hash.key?('priority') ? hash['priority'] : SKIP
156+
expiration = hash.key?('expiration') ? hash['expiration'] : SKIP
148157

149158
# Create object from extracted values.
150159
BandwidthMessage.new(id,
@@ -158,7 +167,8 @@ def self.from_hash(hash)
158167
media,
159168
text,
160169
tag,
161-
priority)
170+
priority,
171+
expiration)
162172
end
163173
end
164174
end

lib/bandwidth/messaging_lib/messaging/models/message_request.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ class MessageRequest < BaseModel
4141
# @return [PriorityEnum]
4242
attr_accessor :priority
4343

44+
# A string with the date/time value that the message will automatically expire by.
45+
# This must be a valid RFC-3339 value, e.g., 2021-03-14T01:59:26Z or 2021-03-13T20:59:26-05:00.
46+
# @return [String]
47+
attr_accessor :expiration
48+
4449
# A mapping from model property names to API property names.
4550
def self.names
4651
@_hash = {} if @_hash.nil?
@@ -51,6 +56,7 @@ def self.names
5156
@_hash['media'] = 'media'
5257
@_hash['tag'] = 'tag'
5358
@_hash['priority'] = 'priority'
59+
@_hash['expiration'] = 'expiration'
5460
@_hash
5561
end
5662

@@ -61,6 +67,7 @@ def optionals
6167
media
6268
tag
6369
priority
70+
expiration
6471
]
6572
end
6673

@@ -75,14 +82,16 @@ def initialize(application_id = nil,
7582
text = nil,
7683
media = nil,
7784
tag = nil,
78-
priority = nil)
85+
priority = nil,
86+
expiration = nil)
7987
@application_id = application_id unless application_id == SKIP
8088
@to = to unless to == SKIP
8189
@from = from unless from == SKIP
8290
@text = text unless text == SKIP
8391
@media = media unless media == SKIP
8492
@tag = tag unless tag == SKIP
8593
@priority = priority unless priority == SKIP
94+
@expiration = expiration unless expiration == SKIP
8695
end
8796

8897
# Creates an instance of the object from a hash.
@@ -97,6 +106,7 @@ def self.from_hash(hash)
97106
media = hash.key?('media') ? hash['media'] : SKIP
98107
tag = hash.key?('tag') ? hash['tag'] : SKIP
99108
priority = hash.key?('priority') ? hash['priority'] : SKIP
109+
expiration = hash.key?('expiration') ? hash['expiration'] : SKIP
100110

101111
# Create object from extracted values.
102112
MessageRequest.new(application_id,
@@ -105,7 +115,8 @@ def self.from_hash(hash)
105115
text,
106116
media,
107117
tag,
108-
priority)
118+
priority,
119+
expiration)
109120
end
110121
end
111122
end

test/integration/test_integration.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,14 @@ def test_create_message
5757
body.to = [USER_NUMBER]
5858
body.from = BW_NUMBER
5959
body.text = "Ruby Integration"
60+
body.priority = "high"
61+
body.expiration = "2091-02-01T11:29:18-05:00"
6062
response = @bandwidth_client.messaging_client.client.create_message(BW_ACCOUNT_ID, body)
63+
assert(response.data.to == [USER_NUMBER])
64+
assert(response.data.from == BW_NUMBER)
65+
assert(response.data.text == "Ruby Integration")
66+
assert(response.data.priority == "high")
67+
assert(response.data.expiration == "2091-02-01T11:29:18-05:00")
6168
assert(response.data.id.length > 0, "id value not set") #validate that _some_ id was returned
6269
end
6370

0 commit comments

Comments
 (0)