Skip to content

Commit

Permalink
Merge pull request #121 from plivo/tollfree-sdk-fix
Browse files Browse the repository at this point in the history
changes made
  • Loading branch information
nixonsam authored Mar 30, 2020
2 parents cd4c182 + 716295c commit bebcfcb
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

## [4.5.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.5.0) (2020-03-30)
- Add Tollfree support for Powerpack

## [4.4.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.4.0) (2020-03-27)
- Add post call quality feedback API support.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The Plivo Ruby SDK makes it simpler to integrate communications into your Ruby a
Add this line to your application's Gemfile:

```ruby
gem 'plivo', '>= 4.4.0'
gem 'plivo', '>= 4.5.0'
```

And then execute:
Expand Down
102 changes: 102 additions & 0 deletions lib/plivo/resources/powerpacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,30 @@ def add_number(number)
perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + number.to_s ,
'POST')
end

def add_tollfree(tollfree)
number_pool_uuid = getnumberpool_uuid(uuid)
perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Tollfree/' + tollfree.to_s ,
'POST')
end

def remove_number(number, unrent= false)
number_pool_uuid = getnumberpool_uuid(uuid)
perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + number.to_s ,
'DELETE', { unrent: unrent }, false)
end

def remove_tollfree(number, unrent= false)
number_pool_uuid = getnumberpool_uuid(uuid)
perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Tollfree/' + number.to_s ,
'DELETE', { unrent: unrent }, false)
end

def remove_shortcode(number)
number_pool_uuid = getnumberpool_uuid(uuid)
perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Shortcode/' + number.to_s ,
'DELETE', { unrent: false }, false)
end

def list_shortcodes(options = nil)
number_pool_uuid = getnumberpool_uuid(uuid)
Expand All @@ -184,13 +201,43 @@ def list_shortcodes(options = nil)
perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Shortcode',
'GET', params)
end

def list_tollfree(options = nil)
number_pool_uuid = getnumberpool_uuid(uuid)
return perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Tollfree',
'GET') if options.nil?
params = {}
%i[offset limit].each do |param|
if options.key?(param) && valid_param?(param, options[param],
[Integer, Integer], true)
params[param] = options[param]
end
end

if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
raise_invalid_request('The maximum number of results that can be '\
"fetched is 20. limit can't be more than 20 or less than 1")
end

if options.key?(:offset) && options[:offset] < 0
raise_invalid_request("Offset can't be negative")
end
perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Tollfree',
'GET', params)
end

def find_shortcode(shortcode)
number_pool_uuid = getnumberpool_uuid(uuid)
perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Shortcode/' + shortcode.to_s ,
'GET')
end

def find_tollfree(tollfree)
number_pool_uuid = getnumberpool_uuid(uuid)
perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Tollfree/' + tollfree.to_s ,
'GET')
end

def buy_add_number(options = nil)
number_pool_uuid = getnumberpool_uuid(uuid)
params = {}
Expand Down Expand Up @@ -267,6 +314,10 @@ def shortcodes
options = {'number_pool_id' => @number_pool_id}
Shortcode.new(@_client, {resource_json: options})
end
def tollfree
options = {'number_pool_id' => @number_pool_id}
Tollfree.new(@_client, {resource_json: options})
end
end

class Numbers < Base::Resource
Expand Down Expand Up @@ -455,6 +506,57 @@ def find(shortcode)
perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Shortcode/' + shortcode.to_s ,
'GET')
end

def remove(shortcode)
perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Shortcode/' + shortcode.to_s ,
'DELETE', { unrent: false }, false)
end
end

class Tollfree < Base::Resource
def initialize(client, options = nil)
@_name = 'Tollfree'
@_identifier_string = 'number_pool_id'
super
end

def add(tollfree)
perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Tollfree/' + tollfree.to_s ,
'POST')
end

def list(options = nil)
return perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Tollfree',
'GET') if options.nil?
params = {}
%i[offset limit].each do |param|
if options.key?(param) && valid_param?(param, options[param],
[Integer, Integer], true)
params[param] = options[param]
end
end

if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
raise_invalid_request('The maximum number of results that can be '\
"fetched is 20. limit can't be more than 20 or less than 1")
end

if options.key?(:offset) && options[:offset] < 0
raise_invalid_request("Offset can't be negative")
end
perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Tollfree',
'GET')
end

def find(tollfree)
perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Tollfree/' + tollfree.to_s ,
'GET')
end

def remove(tollfree, unrent= false)
perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Tollfree/' + tollfree.to_s ,
'DELETE', { unrent: unrent }, false)
end
end

class PowerpackInterface < Base::ResourceInterface
Expand Down
3 changes: 2 additions & 1 deletion lib/plivo/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module Plivo
VERSION = '4.4.0'.freeze
VERSION = '4.5.0'.freeze

end
20 changes: 20 additions & 0 deletions spec/mocks/tollfreeListResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"api_id": "cd5fde12-d229-11e9-b61e-0242ac110007",
"meta": {
"limit": 20,
"next": "",
"offset": 0,
"previous": "",
"total_count": 1
},
"objects": [
{
"account_phone_number_resource": "/v1/Account/MAODZKMDFJMJU3MTEYNG/Number/15799140348/",
"added_on": "2019-09-03T08:50:09.578928Z",
"country_iso2": "CA",
"number": "18772209942",
"number_pool_uuid": "659c7f88-c819-46e2-8af4-2d8a84249099",
"type": "tollfree"
}
]
}
8 changes: 8 additions & 0 deletions spec/mocks/tollfreeResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"account_phone_number_resource": "/v1/Account/MAODZKMDFJMJU3MTEYNG/Number/15799140348/",
"added_on": "2019-09-03T08:50:09.578928Z",
"country_iso2": "CA",
"number": "18772209942",
"number_pool_uuid": "659c7f88-c819-46e2-8af4-2d8a84249099",
"type": "tollfree"
}
89 changes: 88 additions & 1 deletion spec/resource_powerpacks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def to_json_list(list_object)
end

it 'delete powerpack' do
contents = File.read(Dir.pwd + '/spec/mocks/powerpackDeleteResponse.json')
contents = File.read(Dir.pwd + '/spec/mocks/powerpackDelete.json')
mock(200, JSON.parse(contents))
powerpack = @api.powerpacks
.get(
Expand Down Expand Up @@ -80,6 +80,23 @@ def to_json_list(list_object)
data: nil)
expect(response.shortcode).to eql('444444')
end
it 'find tollfree' do
contents = File.read(Dir.pwd + '/spec/mocks/tollfreeResponse.json')
mock(200, JSON.parse(contents))
powerpack = @api.powerpacks
.get(
'86bbb125-97bb-4d72-89fd-81d5c515b015'
)
response = powerpack.find_tollfree('18772209942')
# response = powerpack.numberpool.tollfree.find('14845733594')
expect(JSON.parse(to_json(response)))
.to eql(JSON.parse(contents))
compare_requests(uri: '/v1/Account/MAXXXXXXXXXXXXXXXXXX/NumerPool/'\
'659c7f88-c819-46e2-8af4-2d8a84249099/Tollfree/18772209942/',
method: 'GET',
data: nil)
expect(response.number).to eql('18772209942')
end
it 'find numbers' do
contents = File.read(Dir.pwd + '/spec/mocks/numberpoolResponse.json')
mock(200, JSON.parse(contents))
Expand Down Expand Up @@ -116,4 +133,74 @@ def to_json_list(list_object)
expect(response.number).to eql('14845733594')
end

it 'add tollfree' do
contents = File.read(Dir.pwd + '/spec/mocks/tollfreeResponse.json')
mock(200, JSON.parse(contents))
powerpack = @api.powerpacks
.get(
'86bbb125-97bb-4d72-89fd-81d5c515b015'
)
response = powerpack.add_tollfree('18772209942')
# response = powerpack.numberpool.tollfree.add('15799140348')
expect(JSON.parse(to_json(response)))
.to eql(JSON.parse(contents))
compare_requests(uri: '/v1/Account/MAXXXXXXXXXXXXXXXXXX/NumerPool/'\
'659c7f88-c819-46e2-8af4-2d8a84249099/Tollfree/18772209942/',
method: 'POST',
data: nil)
expect(response.number).to eql('18772209942')
end

it 'list tollfree' do
contents = File.read(Dir.pwd + '/spec/mocks/tollfreeListResponse.json')
mock(200, JSON.parse(contents))
powerpack = @api.powerpacks
.get(
'86bbb125-97bb-4d72-89fd-81d5c515b015'
)
response = powerpack.list_tollfree()
# response = powerpack.numberpool.tollfree.add('15799140348')
expect(JSON.parse(to_json(response)))
.to eql(JSON.parse(contents))
compare_requests(uri: '/v1/Account/MAXXXXXXXXXXXXXXXXXX/NumerPool/'\
'659c7f88-c819-46e2-8af4-2d8a84249099/Tollfree/',
method: 'GET',
data: nil)
expect(response.objects.number).to eql('18772209942')
end

it 'remove tollfree' do
contents = File.read(Dir.pwd + '/spec/mocks/powerpackDelete.json')
mock(200, JSON.parse(contents))
powerpack = @api.powerpacks
.get(
'86bbb125-97bb-4d72-89fd-81d5c515b015'
)
response = powerpack.remove_tollfree('18772209942', true)
expect(JSON.parse(to_json(response)))
.to eql(JSON.parse(contents))
compare_requests(uri: '/v1/Account/MAXXXXXXXXXXXXXXXXXX/Tollfree/18772209942/'\
'86bbb125-97bb-4d72-89fd-81d5c515b015/',
method: 'DELETE',
data: nil)
expect(response.message).to eql(response.message)
end

it 'remove shortcode' do
contents = File.read(Dir.pwd + '/spec/mocks/powerpackDelete.json')
mock(200, JSON.parse(contents))
powerpack = @api.powerpacks
.get(
'86bbb125-97bb-4d72-89fd-81d5c515b015'
)
response = powerpack.remove_tollfree('444444')
expect(JSON.parse(to_json(response)))
.to eql(JSON.parse(contents))
compare_requests(uri: '/v1/Account/MAXXXXXXXXXXXXXXXXXX/Shortcode/444444/'\
'86bbb125-97bb-4d72-89fd-81d5c515b015/',
method: 'DELETE',
data: nil)
expect(response.message).to eql(response.message)
end

end

0 comments on commit bebcfcb

Please sign in to comment.