Skip to content

Commit 6926499

Browse files
authored
Merge pull request #40 from Bandwidth/DX-2405
DX-2405 Add support for missing JSON body body
2 parents bd27996 + 0c880f3 commit 6926499

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

bandwidth.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
88
s.homepage = 'https://apimatic.io'
99
s.license = 'MIT'
1010
s.add_dependency('logging', '~> 2.3')
11-
s.add_dependency('faraday', '~> 1.0', '<= 1.3.0')
11+
s.add_dependency('faraday', '~> 1.0', '<= 1.9.3')
1212
s.add_dependency('faraday_middleware', '~> 1.0')
1313
s.add_dependency('certifi', '~> 2018.1', '>= 2018.01.18')
1414
s.add_dependency('faraday-http-cache', '~> 2.2')

lib/bandwidth/api_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ def self.clean_url(url)
144144
# Parses JSON string.
145145
# @param [String] A JSON string.
146146
def self.json_deserialize(json)
147+
return {} if json.nil? || json.empty?
147148
JSON.parse(json)
148149
rescue StandardError
149150
raise TypeError, 'Server responded with invalid JSON.'

test/integration/test_integration.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ def setup
3838
phone_number_lookup_basic_auth_user_name: BW_USERNAME,
3939
phone_number_lookup_basic_auth_password: BW_PASSWORD
4040
)
41+
42+
@bandwidth_client_invalid_auth = Bandwidth::Client.new(
43+
voice_basic_auth_user_name: "bad_username",
44+
voice_basic_auth_password: "bad_password",
45+
messaging_basic_auth_user_name: "bad_username",
46+
messaging_basic_auth_password: "bad_password",
47+
multi_factor_auth_basic_auth_user_name: "bad_username",
48+
multi_factor_auth_basic_auth_password: "bad_password",
49+
phone_number_lookup_basic_auth_user_name: "bad_username",
50+
phone_number_lookup_basic_auth_password: "bad_password"
51+
)
4152
end
4253

4354
def test_create_message
@@ -79,6 +90,19 @@ def test_upload_download_media
7990
assert_equal(downloaded_media, media, "Downloaded media file not equal to upload")
8091
end
8192

93+
def test_get_message
94+
# Send a successful request to the GET messages API
95+
response = @bandwidth_client.messaging_client.client.get_messages(BW_ACCOUNT_ID, :message_id => "abc123")
96+
assert_equal(response.status_code, 200, "API did not return a 200 OK")
97+
end
98+
99+
def test_get_message_invalid_auth
100+
# Send an unsuccessful request to the GET messages API
101+
assert_raise MessagingException do
102+
response = @bandwidth_client_invalid_auth.messaging_client.client.get_messages(BW_ACCOUNT_ID)
103+
end
104+
end
105+
82106
def test_create_call_and_get_call_state
83107
body = CreateCallRequest.new
84108
body.from = BW_NUMBER

0 commit comments

Comments
 (0)