Skip to content

Commit 91dae68

Browse files
authored
Merge pull request #11 from Bandwidth/release/2021-01-27-20-40-15
New deploy
2 parents 621cc1f + 0c6c385 commit 91dae68

File tree

15 files changed

+554
-144
lines changed

15 files changed

+554
-144
lines changed

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22

33
source 'https://rubygems.org'
44

5+
group :test do
6+
gem 'rake'
7+
end
8+
59
gemspec

Rakefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,12 @@ lib = File.expand_path('../lib', __FILE__)
22
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
33

44
require "bundler/gem_tasks"
5+
require 'rake/testtask'
6+
7+
Rake::TestTask.new(:test) do |t|
8+
t.libs << "test"
9+
t.test_files = FileList['test/**/test_*.rb', 'spec/**/*_spec.rb']
10+
t.warning = false
11+
end
12+
13+
task :default => :test

bandwidth.gemspec

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |s|
22
s.name = 'bandwidth-sdk'
3-
s.version = '4.0.0'
3+
s.version = '5.0.0'
44
s.summary = 'bandwidth'
55
s.description = 'Bandwidth\'s set of APIs'
66
s.authors = ['APIMatic SDK Generator']
@@ -13,6 +13,8 @@ Gem::Specification.new do |s|
1313
s.add_dependency('certifi', '~> 2018.1', '>= 2018.01.18')
1414
s.add_dependency('faraday-http-cache', '~> 2.2')
1515
s.add_dependency('builder', '~> 3.2.4')
16+
s.add_development_dependency('minitest', '~> 5.14', '>= 5.14.1')
17+
s.add_development_dependency('minitest-proveit', '~> 1.0')
1618
s.required_ruby_version = '>= 2.0'
1719
s.files = Dir['{bin,lib,man,test,spec}/**/*', 'README*', 'LICENSE*']
1820
s.require_paths = ['lib']

lib/bandwidth/messaging_lib/messaging.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
require_relative 'messaging/client.rb'
88

99
# Models
10+
require_relative 'messaging/models/bandwidth_messages_list.rb'
11+
require_relative 'messaging/models/bandwidth_message_item.rb'
12+
require_relative 'messaging/models/page_info.rb'
1013
require_relative 'messaging/models/media.rb'
1114
require_relative 'messaging/models/tag.rb'
1215
require_relative 'messaging/models/deferred_result.rb'

lib/bandwidth/messaging_lib/messaging/controllers/api_controller.rb

Lines changed: 130 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ def initialize(config, http_call_back: nil)
1212
end
1313

1414
# listMedia
15-
# @param [String] user_id Required parameter: Example:
16-
# @param [String] continuation_token Optional parameter: Example:
15+
# @param [String] user_id Required parameter: User's account ID
16+
# @param [String] continuation_token Optional parameter: Continuation token
17+
# used to retrieve subsequent media.
1718
# @return [List of Media] response from the API call
1819
def list_media(user_id,
1920
continuation_token: nil)
@@ -83,8 +84,8 @@ def list_media(user_id,
8384
end
8485

8586
# getMedia
86-
# @param [String] user_id Required parameter: Example:
87-
# @param [String] media_id Required parameter: Example:
87+
# @param [String] user_id Required parameter: User's account ID
88+
# @param [String] media_id Required parameter: Media ID to retrieve
8889
# @return [Binary] response from the API call
8990
def get_media(user_id,
9091
media_id)
@@ -146,13 +147,17 @@ def get_media(user_id,
146147
end
147148

148149
# uploadMedia
149-
# @param [String] user_id Required parameter: Example:
150-
# @param [String] media_id Required parameter: Example:
151-
# @param [Long] content_length Required parameter: Example:
150+
# @param [String] user_id Required parameter: User's account ID
151+
# @param [String] media_id Required parameter: The user supplied custom
152+
# media ID
153+
# @param [Long] content_length Required parameter: The size of the
154+
# entity-body
152155
# @param [File | UploadIO] body Required parameter: Example:
153-
# @param [String] content_type Optional parameter:
154-
# Example:application/octet-stream
155-
# @param [String] cache_control Optional parameter: Example:
156+
# @param [String] content_type Optional parameter: The media type of the
157+
# entity-body
158+
# @param [String] cache_control Optional parameter: General-header field is
159+
# used to specify directives that MUST be obeyed by all caching mechanisms
160+
# along the request/response chain.
156161
# @return [void] response from the API call
157162
def upload_media(user_id,
158163
media_id,
@@ -234,8 +239,8 @@ def upload_media(user_id,
234239
end
235240

236241
# deleteMedia
237-
# @param [String] user_id Required parameter: Example:
238-
# @param [String] media_id Required parameter: Example:
242+
# @param [String] user_id Required parameter: User's account ID
243+
# @param [String] media_id Required parameter: The media ID to delete
239244
# @return [void] response from the API call
240245
def delete_media(user_id,
241246
media_id)
@@ -294,12 +299,122 @@ def delete_media(user_id,
294299
ApiResponse.new(_response)
295300
end
296301

302+
# getMessages
303+
# @param [String] user_id Required parameter: User's account ID
304+
# @param [String] message_id Optional parameter: The ID of the message to
305+
# search for. Special characters need to be encoded using URL encoding
306+
# @param [String] source_tn Optional parameter: The phone number that sent
307+
# the message
308+
# @param [String] destination_tn Optional parameter: The phone number that
309+
# received the message
310+
# @param [String] message_status Optional parameter: The status of the
311+
# message. One of RECEIVED, QUEUED, SENDING, SENT, FAILED, DELIVERED,
312+
# DLR_EXPIRED
313+
# @param [Integer] error_code Optional parameter: The error code of the
314+
# message
315+
# @param [String] from_date_time Optional parameter: The start of the date
316+
# range to search in ISO 8601 format. Uses the message receive time. The
317+
# date range to search in is currently 14 days.
318+
# @param [String] to_date_time Optional parameter: The end of the date range
319+
# to search in ISO 8601 format. Uses the message receive time. The date
320+
# range to search in is currently 14 days.
321+
# @param [String] page_token Optional parameter: A base64 encoded value used
322+
# for pagination of results
323+
# @param [Integer] limit Optional parameter: The maximum records requested
324+
# in search result. Default 100. The sum of limit and after cannot be more
325+
# than 10000
326+
# @return [BandwidthMessagesList] response from the API call
327+
def get_messages(user_id,
328+
message_id: nil,
329+
source_tn: nil,
330+
destination_tn: nil,
331+
message_status: nil,
332+
error_code: nil,
333+
from_date_time: nil,
334+
to_date_time: nil,
335+
page_token: nil,
336+
limit: nil)
337+
# Prepare query url.
338+
_query_builder = config.get_base_uri(Server::MESSAGINGDEFAULT)
339+
_query_builder << '/users/{userId}/messages'
340+
_query_builder = APIHelper.append_url_with_template_parameters(
341+
_query_builder,
342+
'userId' => { 'value' => user_id, 'encode' => false }
343+
)
344+
_query_builder = APIHelper.append_url_with_query_parameters(
345+
_query_builder,
346+
'messageId' => message_id,
347+
'sourceTn' => source_tn,
348+
'destinationTn' => destination_tn,
349+
'messageStatus' => message_status,
350+
'errorCode' => error_code,
351+
'fromDateTime' => from_date_time,
352+
'toDateTime' => to_date_time,
353+
'pageToken' => page_token,
354+
'limit' => limit
355+
)
356+
_query_url = APIHelper.clean_url _query_builder
357+
358+
# Prepare headers.
359+
_headers = {
360+
'accept' => 'application/json'
361+
}
362+
363+
# Prepare and execute HttpRequest.
364+
_request = config.http_client.get(
365+
_query_url,
366+
headers: _headers
367+
)
368+
MessagingBasicAuth.apply(config, _request)
369+
_response = execute_request(_request)
370+
371+
# Validate response against endpoint and global error codes.
372+
if _response.status_code == 400
373+
raise MessagingException.new(
374+
'400 Request is malformed or invalid',
375+
_response
376+
)
377+
elsif _response.status_code == 401
378+
raise MessagingException.new(
379+
'401 The specified user does not have access to the account',
380+
_response
381+
)
382+
elsif _response.status_code == 403
383+
raise MessagingException.new(
384+
'403 The user does not have access to this API',
385+
_response
386+
)
387+
elsif _response.status_code == 404
388+
raise MessagingException.new(
389+
'404 Path not found',
390+
_response
391+
)
392+
elsif _response.status_code == 415
393+
raise MessagingException.new(
394+
'415 The content-type of the request is incorrect',
395+
_response
396+
)
397+
elsif _response.status_code == 429
398+
raise MessagingException.new(
399+
'429 The rate limit has been reached',
400+
_response
401+
)
402+
end
403+
validate_response(_response)
404+
405+
# Return appropriate response type.
406+
decoded = APIHelper.json_deserialize(_response.raw_body)
407+
ApiResponse.new(
408+
_response, data: BandwidthMessagesList.from_hash(decoded)
409+
)
410+
end
411+
297412
# createMessage
298-
# @param [String] user_id Required parameter: Example:
299-
# @param [MessageRequest] body Optional parameter: Example:
413+
# @param [String] user_id Required parameter: User's account ID
414+
# @param [MessageRequest] body Required parameter: Example:
300415
# @return [BandwidthMessage] response from the API call
301416
def create_message(user_id,
302-
body: nil)
417+
body)
303418
# Prepare query url.
304419
_query_builder = config.get_base_uri(Server::MESSAGINGDEFAULT)
305420
_query_builder << '/users/{userId}/messages'

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,48 @@
66
module Bandwidth
77
# BandwidthMessage Model.
88
class BandwidthMessage < BaseModel
9-
# TODO: Write general description for this method
9+
# The id of the message
1010
# @return [String]
1111
attr_accessor :id
1212

13-
# TODO: Write general description for this method
13+
# The Bandwidth phone number associated with the message
1414
# @return [String]
1515
attr_accessor :owner
1616

17-
# TODO: Write general description for this method
17+
# The application ID associated with the message
1818
# @return [String]
1919
attr_accessor :application_id
2020

21-
# TODO: Write general description for this method
21+
# The datetime stamp of the message in ISO 8601
2222
# @return [String]
2323
attr_accessor :time
2424

25-
# TODO: Write general description for this method
25+
# The number of segments the original message from the user is broken into
26+
# before sending over to carrier networks
2627
# @return [Integer]
2728
attr_accessor :segment_count
2829

29-
# TODO: Write general description for this method
30+
# The direction of the message relative to Bandwidth. Can be in or out
3031
# @return [String]
3132
attr_accessor :direction
3233

33-
# TODO: Write general description for this method
34+
# The phone number recipients of the message
3435
# @return [List of String]
3536
attr_accessor :to
3637

37-
# TODO: Write general description for this method
38+
# The phone number the message was sent from
3839
# @return [String]
3940
attr_accessor :from
4041

41-
# TODO: Write general description for this method
42+
# The list of media URLs sent in the message
4243
# @return [List of String]
4344
attr_accessor :media
4445

45-
# TODO: Write general description for this method
46+
# The contents of the message
4647
# @return [String]
4748
attr_accessor :text
4849

49-
# TODO: Write general description for this method
50+
# The custom string set by the user
5051
# @return [String]
5152
attr_accessor :tag
5253

0 commit comments

Comments
 (0)