ruby-bandwidth-iris 4.0.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6eb0be263ea4f9801165248f8c578e6d85205ef4494711204d587979a8f0bd1
4
- data.tar.gz: 96e2af6369e6a319e3be929ace9181a49e488ea98bda0491093285d8895b4416
3
+ metadata.gz: f77d77b3e9fd1b459cab7159cff5f35ec0d4dcb00186e70d54106382c3156d20
4
+ data.tar.gz: d08b335e9133e43b37bc5d79381eda44fc9aed4cca7e91905887d9e5e1b2282e
5
5
  SHA512:
6
- metadata.gz: 5728361fdb4eab48bb47928514a32b3dec2d4c38bab3103e4d273ea0a9b429ad0a25eaee5eed4d695f54891987cde64f1dd45c91fea78233d6f9764e5437793d
7
- data.tar.gz: 855ef5ba77813675956787b8511dae06f5ed25c72015661a4d52ac6bba612d098758519b54848124a425301fdecde927a0cf8082607fe1feb26dbd7ce05f272d
6
+ metadata.gz: c359fa2a8b0a422f13262cefb9006d2e236728bda17d91184f50c8ec63b4c3f44348cadbd954987997ffc3dccc3670abf120997acc7c7cfb8350f794ef9b0a74
7
+ data.tar.gz: 4ec6c1230937b62513f1950652b11906b2090265a2ea97a1a38f737fe166d411ea0943b93fe24770adec385e3bc35e3cc2415d573c61c5acd40c5920901a8cbf
@@ -0,0 +1,2 @@
1
+ # Global rule:
2
+ * @Bandwidth/dx
@@ -0,0 +1,40 @@
1
+ ---
2
+ name: Bug Report
3
+ about: Create a bug report.
4
+ title: '[BUG] Description'
5
+ labels: 'bug'
6
+ ---
7
+
8
+ ### Checklist
9
+ - [ ] Have you provided a description of the bug?
10
+ - [ ] Have you provided your Environment information?
11
+ - [ ] Have you provided a sample code snippet?
12
+ - [ ] Have you provided a stack trace?
13
+ - [ ] Have you outlined the expected behavior?
14
+
15
+ ### Description
16
+ <!-- Please provide a clear and concise description of the bug. -->
17
+
18
+ ### Environment Information
19
+ <!-- Please provide the version of the OS, SDK, and Environment you are experiencing the bug in. -->
20
+ - OS Version: _(e.g. Windows 10)_
21
+ - SDK Version: _(e.g. 1.1.0)_
22
+ - Environment: _(e.g. Ruby 3.1.0)_
23
+
24
+ ### Sample Code Snippet
25
+ <!-- Please provide a code snippet that produces or is relevant to the bug. -->
26
+ ```ruby
27
+ # Sample Code Snippet
28
+ ```
29
+
30
+ ### Stack Trace
31
+ <!-- Please provide the stack trace that shows the bug. -->
32
+ ```shell
33
+ # Stack Trace
34
+ ```
35
+
36
+ ### Expected Behavior
37
+ <!-- Please outline the expected behavior of the SDK. -->
38
+
39
+ ### Suggested Fix
40
+ <!-- If you have a fix or a suggestion for how this bug may be resolved, describe it here. -->
@@ -0,0 +1,5 @@
1
+ blank_issues_enabled: false
2
+ contact_links:
3
+ - name: Bandwidth Support
4
+ url: https://www.bandwidth.com/support/
5
+ about: Current customers can create tickets for our Support Team here.
@@ -0,0 +1,42 @@
1
+ name: Deploy SDK
2
+
3
+ on:
4
+ release:
5
+ types:
6
+ - published
7
+
8
+ jobs:
9
+ deploy:
10
+ name: Deploy to Rubygems
11
+ if: ${{ !github.event.release.prerelease && github.event.release.target_commitish == 'master' }}
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - name: Checkout
15
+ uses: actions/checkout@v2
16
+
17
+ - name: Setup Ruby
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: '3.0'
21
+
22
+ - name: Install Packages
23
+ run: bundle install
24
+
25
+ - name: Test
26
+ run: rake
27
+
28
+ - name: Deploy to Rubygems
29
+ run: |
30
+ mkdir -p $HOME/.gem
31
+ touch $HOME/.gem/credentials
32
+ chmod 0600 $HOME/.gem/credentials
33
+ printf -- "---\n:rubygems_api_key: ${{ secrets.RUBYGEMS_API_KEY }}\n" > $HOME/.gem/credentials
34
+ gem build *.gemspec
35
+ gem push *.gem
36
+
37
+ - uses: Bandwidth/build-notify-slack-action@v1.0.0
38
+ if: always()
39
+ with:
40
+ job-status: ${{ job.status }}
41
+ slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
42
+ slack-channel: ${{ secrets.SLACK_CHANNEL }}
@@ -0,0 +1,38 @@
1
+ name: Test
2
+
3
+ on:
4
+ schedule:
5
+ - cron: "0 4 * * *"
6
+ pull_request:
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ test:
11
+ name: Test
12
+ runs-on: ${{ matrix.os }}
13
+ strategy:
14
+ matrix:
15
+ os: [windows-2022, windows-2019, ubuntu-18.04, ubuntu-20.04]
16
+ ruby-version: [2.6, 2.7, 3.0]
17
+ steps:
18
+ - name: Checkout
19
+ uses: actions/checkout@v2
20
+
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby-version }}
25
+
26
+ - name: Install Packages
27
+ run: bundle install
28
+
29
+ - name: Test
30
+ run: rake
31
+
32
+ - name: Notify Slack of Failures
33
+ uses: Bandwidth/build-notify-slack-action@v1.0.0
34
+ if: failure() && !github.event.pull_request.draft
35
+ with:
36
+ job-status: ${{ job.status }}
37
+ slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
38
+ slack-channel: ${{ secrets.SLACK_CHANNEL }}
data/Gemfile CHANGED
@@ -5,3 +5,5 @@ group :test do
5
5
  gem 'rspec', '3.9.0'
6
6
  gem 'simplecov', '~> 0.16.1'
7
7
  end
8
+
9
+ gemspec
data/README.md CHANGED
@@ -22,6 +22,7 @@ Ruby Client library for IRIS / BBS API
22
22
  | 3.0.0 | Removed functionality that causes an error to be raised when some type of `error` field is returned in the XML body response. This change reduces the situations that cause an error to be thrown to simply be 4XX and 5XX http responses. This change was made to improve communication when an error is found. Please update your code to handle this change. |
23
23
  | 3.0.2 | Fixed an incorrect retrieval of DLDA objects |
24
24
  | 4.0.0 | Removed certify gem. Users will now need to set their own SSL settings |
25
+ | 4.1.0 | Added support for SIP credentials.
25
26
 
26
27
  ### 3.x.x release
27
28
 
data/examples/account.rb CHANGED
@@ -11,5 +11,10 @@ BandwidthIris::Client.global_options = {
11
11
  :password => config['password'],
12
12
  :account_id => config['account_id']
13
13
  }
14
- puts BandwidthIris::Account.get()
14
+
15
+ begin
16
+ puts BandwidthIris::Account.get()
17
+ rescue BandwidthIris::Errors::GenericError => e
18
+ puts e.message
19
+ end
15
20
 
@@ -13,5 +13,9 @@ BandwidthIris::Client.global_options = {
13
13
  }
14
14
 
15
15
 
16
- puts BandwidthIris::AvailableNpaNxx.list({:state => 'NC', :quantity => 3})
16
+ begin
17
+ puts BandwidthIris::AvailableNpaNxx.list({:state => 'NC', :quantity => 3})
18
+ rescue BandwidthIris::Errors::GenericError => e
19
+ puts e.message
20
+ end
17
21
 
@@ -13,5 +13,9 @@ BandwidthIris::Client.global_options = {
13
13
  }
14
14
 
15
15
 
16
- puts BandwidthIris::AvailableNumber.list({:state => "NC", :quantity => 3})
16
+ begin
17
+ puts BandwidthIris::AvailableNumber.list({:state => "NC", :quantity => 3})
18
+ rescue BandwidthIris::Errors::GenericError => e
19
+ puts e.message
20
+ end
17
21
 
@@ -12,4 +12,8 @@ BandwidthIris::Client.global_options = {
12
12
  :account_id => config['account_id']
13
13
  }
14
14
 
15
- puts BandwidthIris::AvailableNumber.list({:state => "NC", :quantity => 3, :enable_t_n_detail => true})
15
+ begin
16
+ puts BandwidthIris::AvailableNumber.list({:state => "NC", :quantity => 3, :enable_t_n_detail => true})
17
+ rescue BandwidthIris::Errors::GenericError => e
18
+ puts e.message
19
+ end
data/examples/city.rb CHANGED
@@ -12,5 +12,9 @@ BandwidthIris::Client.global_options = {
12
12
  :account_id => config['account_id']
13
13
  }
14
14
 
15
- puts BandwidthIris::City.list({:available => true, :state => 'NC'})
15
+ begin
16
+ puts BandwidthIris::City.list({:available => true, :state => 'NC'})
17
+ rescue BandwidthIris::Errors::GenericError => e
18
+ puts e.message
19
+ end
16
20
 
@@ -1,4 +1,4 @@
1
- api_endpoint: "https://api.inetwork.com"
1
+ api_endpoint: "https://dashboard.bandwidth.com"
2
2
  account_id: ""
3
3
  user_name: ""
4
4
  password: ""
@@ -12,8 +12,11 @@ BandwidthIris::Client.global_options = {
12
12
  :account_id => config['account_id']
13
13
  }
14
14
 
15
-
16
- BandwidthIris::CoveredRateCenter.list({:zip => '27609', :page=>1, :size=>100}).each do |c|
17
- puts c.to_data
15
+ begin
16
+ BandwidthIris::CoveredRateCenter.list({:zip => '27609', :page=>1, :size=>100}).each do |c|
17
+ puts c.to_data
18
+ end
19
+ rescue BandwidthIris::Errors::GenericError => e
20
+ puts e.message
18
21
  end
19
22
 
data/examples/order.rb CHANGED
@@ -14,35 +14,39 @@ BandwidthIris::Client.global_options = {
14
14
 
15
15
  number = '9195551212' #exisitng number for order
16
16
 
17
+ begin
18
+ site = BandwidthIris::Site.create({
19
+ :name => "Ruby Test Site",
20
+ :description => "A Site From Ruby SDK Examples",
21
+ :address => {
22
+ :house_number => "123",
23
+ :street_name => "Anywhere St",
24
+ :city => "Raleigh",
25
+ :state_code =>"NC",
26
+ :zip => "27609",
27
+ :address_type => "Service"
28
+ }
29
+ })
30
+
31
+ order = BandwidthIris::Order.create({
32
+ :name =>"A Test Order",
33
+ :site_id => site.id,
34
+ :existing_telephone_number_order_type => {
35
+ :telephone_number_list =>
36
+ {
37
+ :telephone_number => [number]
38
+ }
39
+
40
+ }
41
+ })
42
+
43
+ puts order.to_data
44
+
45
+ order = BandwidthIris::Order.get(order.id)
46
+ rescue BandwidthIris::Errors::GenericError => e
47
+ puts e.message
48
+ end
17
49
 
18
- site = BandwidthIris::Site.create({
19
- :name => "Ruby Test Site",
20
- :description => "A Site From Ruby SDK Examples",
21
- :address => {
22
- :house_number => "123",
23
- :street_name => "Anywhere St",
24
- :city => "Raleigh",
25
- :state_code =>"NC",
26
- :zip => "27609",
27
- :address_type => "Service"
28
- }
29
- })
30
-
31
- order = BandwidthIris::Order.create({
32
- :name =>"A Test Order",
33
- :site_id => site.id,
34
- :existing_telephone_number_order_type => {
35
- :telephone_number_list =>
36
- {
37
- :telephone_number => [number]
38
- }
39
-
40
- }
41
- })
42
-
43
- puts order.to_data
44
-
45
- order = BandwidthIris::Order.get(order.id)
46
50
 
47
51
  puts order.to_data
48
52
 
data/examples/port-in.rb CHANGED
@@ -16,58 +16,62 @@ number_to_check = '+12525130283' #TODO fill with valid number
16
16
 
17
17
  host = '1.1.2.3'
18
18
 
19
+ begin
20
+ site = BandwidthIris::Site.create({
21
+ :name => "Ruby Test Site",
22
+ :description => "A Site From Ruby SDK Examples",
23
+ :address => {
24
+ :house_number => "123",
25
+ :street_name => "Anywhere St",
26
+ :city => "Raleigh",
27
+ :state_code =>"NC",
28
+ :zip => "27609",
29
+ :address_type => "Service"
30
+ }
31
+ })
19
32
 
20
- site = BandwidthIris::Site.create({
21
- :name => "Ruby Test Site",
22
- :description => "A Site From Ruby SDK Examples",
23
- :address => {
24
- :house_number => "123",
25
- :street_name => "Anywhere St",
26
- :city => "Raleigh",
27
- :state_code =>"NC",
28
- :zip => "27609",
29
- :address_type => "Service"
30
- }
31
- })
32
-
33
- data = {
34
- :peer_name => "A New SIP Peer",
35
- :is_default_peer => true,
36
- :short_messaging_protocol => "SMPP",
37
- :site_id => site[:id],
38
- :voice_hosts =>
39
- {
40
- :host => {
41
- :host_name => host
42
- }
43
- },
44
- :sms_hosts =>
45
- {
46
- :host => {
47
- :host_name => host
48
- }
49
- },
50
- :termination_hosts =>
33
+ data = {
34
+ :peer_name => "A New SIP Peer",
35
+ :is_default_peer => true,
36
+ :short_messaging_protocol => "SMPP",
37
+ :site_id => site[:id],
38
+ :voice_hosts =>
51
39
  {
52
- :termination_host => {
53
- :host_name => host,
54
- :port => 5060,
40
+ :host => {
41
+ :host_name => host
42
+ }
43
+ },
44
+ :sms_hosts =>
45
+ {
46
+ :host => {
47
+ :host_name => host
48
+ }
49
+ },
50
+ :termination_hosts =>
51
+ {
52
+ :termination_host => {
53
+ :host_name => host,
54
+ :port => 5060,
55
+ }
55
56
  }
56
- }
57
57
 
58
- }
58
+ }
59
59
 
60
- sip_peer = BandwidthIris::SipPeer.create(site[:id], data)
60
+ sip_peer = BandwidthIris::SipPeer.create(site[:id], data)
61
61
 
62
- res = BandwidthIris::LnpChecker.check(number_to_check)
62
+ res = BandwidthIris::LnpChecker.check(number_to_check)
63
63
 
64
- if res[:portable_numbers] && res[:portable_numbers][:tn] == number_to_check
65
- puts 'Your number is portable. Creating PortIn Order'
66
- port_in = BandwidthIris::PortIn.create(create_port_in_order(number_to_check, site, sip_peer))
67
- puts "Created order #{port_in[:id]}"
68
- port_in.create_file(File.open('./loa.pdf', 'r'), 'application/pdf')
64
+ if res[:portable_numbers] && res[:portable_numbers][:tn] == number_to_check
65
+ puts 'Your number is portable. Creating PortIn Order'
66
+ port_in = BandwidthIris::PortIn.create(create_port_in_order(number_to_check, site, sip_peer))
67
+ puts "Created order #{port_in[:id]}"
68
+ port_in.create_file(File.open('./loa.pdf', 'r'), 'application/pdf')
69
+ end
70
+ rescue BandwidthIris::Errors::GenericError => e
71
+ puts e.message
69
72
  end
70
73
 
74
+
71
75
  def create_port_in_order(number, site, sip_peer)
72
76
  {
73
77
  :site_id => site[:id],
data/examples/sip_peer.rb CHANGED
@@ -14,47 +14,51 @@ BandwidthIris::Client.global_options = {
14
14
 
15
15
  host = '10.20.30.41'
16
16
 
17
+ begin
18
+ site = BandwidthIris::Site.create({
19
+ :name => "Ruby Test Site",
20
+ :description => "A Site From Ruby SDK Examples",
21
+ :address => {
22
+ :house_number => "123",
23
+ :street_name => "Anywhere St",
24
+ :city => "Raleigh",
25
+ :state_code =>"NC",
26
+ :zip => "27609",
27
+ :address_type => "Service"
28
+ }
29
+ })
17
30
 
18
- site = BandwidthIris::Site.create({
19
- :name => "Ruby Test Site",
20
- :description => "A Site From Ruby SDK Examples",
21
- :address => {
22
- :house_number => "123",
23
- :street_name => "Anywhere St",
24
- :city => "Raleigh",
25
- :state_code =>"NC",
26
- :zip => "27609",
27
- :address_type => "Service"
28
- }
29
- })
30
-
31
- data = {
32
- :peer_name => "A New SIP Peer",
33
- :is_default_peer => true,
34
- :short_messaging_protocol => "SMPP",
35
- :site_id => site[:id],
36
- :voice_hosts =>
37
- {
38
- :host => {
39
- :host_name => host
40
- }
41
- },
42
- :sms_hosts =>
43
- {
44
- :host => {
45
- :host_name => host
46
- }
47
- },
48
- :termination_hosts =>
31
+ data = {
32
+ :peer_name => "A New SIP Peer",
33
+ :is_default_peer => true,
34
+ :short_messaging_protocol => "SMPP",
35
+ :site_id => site[:id],
36
+ :voice_hosts =>
37
+ {
38
+ :host => {
39
+ :host_name => host
40
+ }
41
+ },
42
+ :sms_hosts =>
49
43
  {
50
- :termination_host => {
51
- :host_name => host,
52
- :port => 5060,
44
+ :host => {
45
+ :host_name => host
46
+ }
47
+ },
48
+ :termination_hosts =>
49
+ {
50
+ :termination_host => {
51
+ :host_name => host,
52
+ :port => 5060,
53
+ }
53
54
  }
54
- }
55
55
 
56
- }
57
- sip_peer = BandwidthIris::SipPeer.create(site[:id], data)
56
+ }
57
+ sip_peer = BandwidthIris::SipPeer.create(site[:id], data)
58
+ rescue BandwidthIris::Errors::GenericError => e
59
+ puts e.message
60
+ end
61
+
58
62
 
59
63
 
60
64
  sip_peer.delete(site[:id])
data/examples/site.rb CHANGED
@@ -12,18 +12,21 @@ BandwidthIris::Client.global_options = {
12
12
  :account_id => config['account_id']
13
13
  }
14
14
 
15
-
16
- site = BandwidthIris::Site.create({
17
- :name => "Ruby Test Sitei1",
18
- :description => "A Site From Ruby SDK Examples",
19
- :address => {
20
- :house_number => "123",
21
- :street_name => "Anywhere St",
22
- :city => "Raleigh",
23
- :state_code =>"NC",
24
- :zip => "27609",
25
- :address_type => "Service"
26
- }
27
- })
15
+ begin
16
+ site = BandwidthIris::Site.create({
17
+ :name => "Ruby Test Sitei1",
18
+ :description => "A Site From Ruby SDK Examples",
19
+ :address => {
20
+ :house_number => "123",
21
+ :street_name => "Anywhere St",
22
+ :city => "Raleigh",
23
+ :state_code =>"NC",
24
+ :zip => "27609",
25
+ :address_type => "Service"
26
+ }
27
+ })
28
+ rescue BandwidthIris::Errors::GenericError => e
29
+ puts e.message
30
+ end
28
31
 
29
32
  site.delete()
data/examples/tn.rb CHANGED
@@ -13,8 +13,11 @@ BandwidthIris::Client.global_options = {
13
13
  :account_id => config['account_id']
14
14
  }
15
15
 
16
- list = BandwidthIris::Tn.list({:npa => '818', :page => 1, :size => 100}).each do |n|
17
- puts n.to_data
16
+ begin
17
+ list = BandwidthIris::Tn.list({:npa => '818', :page => 1, :size => 100}).each do |n|
18
+ puts n.to_data
19
+ end
20
+ puts BandwidthIris::Tn.get(list[0][:full_number]).to_data
21
+ rescue BandwidthIris::Errors::GenericError => e
22
+ puts e.message
18
23
  end
19
-
20
- puts BandwidthIris::Tn.get(list[0][:full_number]).to_data
@@ -1,5 +1,6 @@
1
1
  require 'faraday'
2
2
  require 'faraday_middleware'
3
+ require 'active_support'
3
4
  require 'active_support/xml_mini'
4
5
  require 'active_support/core_ext/hash/conversions'
5
6
  require 'active_support/core_ext/string/inflections'
@@ -28,7 +29,7 @@ module BandwidthIris
28
29
  @set_adapter = lambda {|faraday| faraday.adapter(Faraday.default_adapter)}
29
30
  @create_connection = lambda{||
30
31
  Faraday.new(api_endpoint) { |faraday|
31
- faraday.basic_auth(user_name, password)
32
+ faraday.request :basic_auth, user_name, password
32
33
  #faraday.response :logger
33
34
  faraday.headers['Accept'] = 'application/xml'
34
35
  faraday.headers['user-agent'] = 'Ruby-Bandwidth-Iris'
@@ -119,7 +120,7 @@ module BandwidthIris
119
120
  # @param response response object
120
121
  def check_response(response)
121
122
  parsed_body = parse_xml(response.body || '')
122
- raise Errors::GenericError.new('', "Http code #{response.status}", response.status) if response.status >= 400
123
+ raise Errors::GenericError.new(response.status, response.reason_phrase, response.headers, parsed_body) if response.status >= 400
123
124
  parsed_body
124
125
  end
125
126
 
@@ -18,7 +18,7 @@ module BandwidthIris
18
18
 
19
19
  def self.get(client, id)
20
20
  data = client.make_request(:get, "#{client.concat_account_path(DLDA_PATH)}/#{id}")[0]
21
- data[:id] = data[:order_id]
21
+ data[:id] = data[:dlda_order][:order_id]
22
22
  Dlda.new(data, client)
23
23
  end
24
24
  wrap_client_arg :get
@@ -2,17 +2,29 @@ module BandwidthIris
2
2
  module Errors
3
3
  # Generic error class
4
4
  class GenericError < StandardError
5
- # @return [String] Error code
6
- attr_reader :code
7
-
8
- # @return [String] Http status code
5
+ # @return [String] HTTP status code
9
6
  attr_reader :http_status
10
7
 
8
+ # return [String] Reason
9
+ attr_reader :reason
10
+
11
+ # return [Hash] Headers
12
+ attr_reader :headers
13
+
14
+ # return [Hash] Body
15
+ attr_reader :body
16
+
17
+ # @return [String] Iris Error code
18
+ attr_reader :code
19
+
11
20
  # @api private
12
- def initialize code, message, http_status
13
- super message
14
- @code = code
21
+ def initialize http_status, reason, headers, body
15
22
  @http_status = http_status
23
+ @reason = reason
24
+ @headers = headers
25
+ @body = body
26
+ @code = body.nil? ? '' : body[:error][:code]
27
+ super message = "HTTP Error\nStatus Code: #{@http_status}\nReason: #{@reason}\nHTTP Headers: #{@headers}\nResponse Body: #{@body}\nIris Error Code: #{@code}"
16
28
  end
17
29
  end
18
30
 
@@ -11,7 +11,7 @@ module BandwidthIris
11
11
  wrap_client_arg :list
12
12
 
13
13
  def self.get(client, number)
14
- client.make_request(:get, "#{client.concat_account_path(INSERVICE_NUMBER_PATH)}/#{URI.escape(number)}")[0]
14
+ client.make_request(:get, "#{client.concat_account_path(INSERVICE_NUMBER_PATH)}/#{CGI.escape(number)}")[0]
15
15
  end
16
16
  wrap_client_arg :get
17
17
 
@@ -64,12 +64,12 @@ module BandwidthIris
64
64
  end
65
65
 
66
66
  def get_file_metadata(file_name)
67
- @client.make_request(:get, "#{@client.concat_account_path(PORT_IN_PATH)}/#{id}/#{LOAS_PATH}/#{URI.encode(file_name)}/metadata")[0]
67
+ @client.make_request(:get, "#{@client.concat_account_path(PORT_IN_PATH)}/#{id}/#{LOAS_PATH}/#{CGI.escape(file_name)}/metadata")[0]
68
68
  end
69
69
 
70
70
  def get_file(file_name)
71
71
  connection = @client.create_connection()
72
- response = connection.get("/#{@client.api_version}#{@client.concat_account_path(PORT_IN_PATH)}/#{id}/#{LOAS_PATH}/#{URI.encode(file_name)}")
72
+ response = connection.get("/#{@client.api_version}#{@client.concat_account_path(PORT_IN_PATH)}/#{id}/#{LOAS_PATH}/#{CGI.escape(file_name)}")
73
73
  [response.body, response.headers['Content-Type'] || 'application/octet-stream']
74
74
  end
75
75
 
@@ -0,0 +1,42 @@
1
+ module BandwidthIris
2
+ SIP_CREDENTIAL_PATH = 'sipcredentials'
3
+
4
+ class SipCredential
5
+ extend ClientWrapper
6
+ include ApiItem
7
+
8
+ def self.list(client, query = nil)
9
+ list = client.make_request(:get, client.concat_account_path(SIP_CREDENTIAL_PATH), query)[0][:sip_credential]
10
+ list = if list.is_a?(Array) then list else [list] end
11
+ list.map do |i|
12
+ SipCredential.new(i, client)
13
+ end
14
+ end
15
+ wrap_client_arg :list
16
+
17
+ def self.get(client, id)
18
+ data = client.make_request(:get, "#{client.concat_account_path(SIP_CREDENTIAL_PATH)}/#{id}")[0]
19
+ SipCredential.new(data[:sip_credential], client)
20
+ end
21
+ wrap_client_arg :get
22
+
23
+ def self.create(client, item)
24
+ data = client.make_request(
25
+ :post,
26
+ client.concat_account_path(SIP_CREDENTIAL_PATH),
27
+ { :sip_credentials => { :sip_credential => item } }
28
+ )[0][:valid_sip_credentials]
29
+ SipCredential.new(data[:sip_credential], client)
30
+ end
31
+ wrap_client_arg :create
32
+
33
+
34
+ def update(data)
35
+ @client.make_request(:put,"#{@client.concat_account_path(SIP_CREDENTIAL_PATH)}/#{user_name}", {:sip_credential => data})
36
+ end
37
+
38
+ def delete
39
+ @client.make_request(:delete,"#{@client.concat_account_path(SIP_CREDENTIAL_PATH)}/#{user_name}")
40
+ end
41
+ end
42
+ end
@@ -26,7 +26,7 @@ module BandwidthIris
26
26
 
27
27
 
28
28
  def get_tns(number = nil)
29
- r = @client.make_request(:get,"#{@client.concat_account_path(SITE_PATH)}/#{site_id}/#{SIPPEER_PATH}/#{id}/tns#{if number then '/' + URI.escape(number) else '' end}")[0]
29
+ r = @client.make_request(:get,"#{@client.concat_account_path(SITE_PATH)}/#{site_id}/#{SIPPEER_PATH}/#{id}/tns#{if number then '/' + CGI.escape(number) else '' end}")[0]
30
30
  if number
31
31
  r[:sip_peer_telephone_number]
32
32
  else
@@ -37,7 +37,7 @@ module BandwidthIris
37
37
  end
38
38
 
39
39
  def update_tns(number, data)
40
- @client.make_request(:put,"#{@client.concat_account_path(SITE_PATH)}/#{site_id}/#{SIPPEER_PATH}/#{id}/tns/#{URI.escape(number)}", {:sip_peer_telephone_number => data})[0]
40
+ @client.make_request(:put,"#{@client.concat_account_path(SITE_PATH)}/#{site_id}/#{SIPPEER_PATH}/#{id}/tns/#{CGI.escape(number)}", {:sip_peer_telephone_number => data})[0]
41
41
  end
42
42
 
43
43
  def move_tns(numbers)
@@ -6,7 +6,7 @@ module BandwidthIris
6
6
  include ApiItem
7
7
 
8
8
  def self.get(client, number)
9
- data = client.make_request(:get, "#{TN_PATH}/#{URI.escape(number)}")[0]
9
+ data = client.make_request(:get, "#{TN_PATH}/#{CGI.escape(number)}")[0]
10
10
  Tn.new(data, client)
11
11
  end
12
12
  wrap_client_arg :get
@@ -23,19 +23,19 @@ module BandwidthIris
23
23
  wrap_client_arg :list
24
24
 
25
25
  def get_sites()
26
- @client.make_request(:get, "#{TN_PATH}/#{URI.escape(telephone_number)}/sites")[0]
26
+ @client.make_request(:get, "#{TN_PATH}/#{CGI.escape(telephone_number)}/sites")[0]
27
27
  end
28
28
 
29
29
  def get_sip_peers()
30
- @client.make_request(:get, "#{TN_PATH}/#{URI.escape(telephone_number)}/sippeers")[0]
30
+ @client.make_request(:get, "#{TN_PATH}/#{CGI.escape(telephone_number)}/sippeers")[0]
31
31
  end
32
32
 
33
33
  def get_rate_center()
34
- @client.make_request(:get, "#{TN_PATH}/#{URI.escape(telephone_number)}/ratecenter")[0][:telephone_number_details]
34
+ @client.make_request(:get, "#{TN_PATH}/#{CGI.escape(telephone_number)}/ratecenter")[0][:telephone_number_details]
35
35
  end
36
36
 
37
37
  def get_details()
38
- @client.make_request(:get, "#{TN_PATH}/#{URI.escape(telephone_number)}/tndetails")[0][:telephone_number_details]
38
+ @client.make_request(:get, "#{TN_PATH}/#{CGI.escape(telephone_number)}/tndetails")[0][:telephone_number_details]
39
39
  end
40
40
  end
41
41
  end
@@ -1,4 +1,4 @@
1
1
  module BandwidthIris
2
2
  # Version of this gem
3
- VERSION = "4.0.0"
3
+ VERSION = "5.0.0"
4
4
  end
@@ -20,6 +20,7 @@ require 'bandwidth-iris/order'
20
20
  require 'bandwidth-iris/port_in'
21
21
  require 'bandwidth-iris/port_out'
22
22
  require 'bandwidth-iris/rate_center'
23
+ require 'bandwidth-iris/sip_credential'
23
24
  require 'bandwidth-iris/sip_peer'
24
25
  require 'bandwidth-iris/site'
25
26
  require 'bandwidth-iris/subscription'
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.add_dependency "faraday_middleware"
20
20
  spec.add_dependency "nori"
21
21
  spec.add_dependency "activesupport",">= 4.2.7"
22
+ spec.add_dependency "rexml"
22
23
 
23
24
  spec.add_development_dependency "bundler", ">= 1.3"
24
25
  spec.add_development_dependency "rake", ">= 11.1.0"
@@ -46,7 +46,6 @@ describe BandwidthIris::Client do
46
46
  it 'should create new faraday connection' do
47
47
  connection = client.create_connection()
48
48
  expect(connection).to be_a(Faraday::Connection)
49
- expect(connection.headers['Authorization']).to eql("Basic #{Base64.strict_encode64('username:password')}")
50
49
  end
51
50
  end
52
51
 
@@ -60,6 +59,12 @@ describe BandwidthIris::Client do
60
59
  client.stubs.verify_stubbed_calls()
61
60
  end
62
61
 
62
+ it 'should pass basic auth headers' do
63
+ # Note: This endpoint does not exist. It is stubbed in order to echo back the Authorization headers that are added by Faraday middleware.
64
+ client.stubs.get('/v1.0/test-auth') { |env| [200, {}, "<Result><EchoedAuth>#{env[:request_headers]['Authorization']}</EchoedAuth></Result>"] }
65
+ expect(client.make_request(:get, '/test-auth')).to eql([{:echoed_auth=>"Basic #{Base64.strict_encode64('username:password')}"}, {}])
66
+ end
67
+
63
68
  it 'should make GET request and return xml data' do
64
69
  client.stubs.get('/v1.0/path1') { |env| [200, {}, '<Result><Test>data</Test></Result>'] }
65
70
  client.stubs.get('/v1.0/path2?testField=10') { |env| [200, {'Location'=>'url'}, '<Root><TestValue>10</TestValue><DataArray>1</DataArray><DataArray>2</DataArray><BoolValue>true</BoolValue><BoolValue2>false</BoolValue2><DateTimeValue>2015-05-29T01:02:03Z</DateTimeValue></Root>'] }
@@ -83,8 +88,13 @@ describe BandwidthIris::Client do
83
88
  end
84
89
 
85
90
  it 'should raise error if http status >= 400' do
86
- client.stubs.get('/v1.0/path1') { |env| [400, {}, ''] }
87
- expect{client.make_request(:get, '/path1')}.to raise_error(Errors::GenericError, "Http code 400")
91
+ client.stubs.get('/v1.0/path1') { |env| [400, {'content-type'=>'application/xml'}, '<SearchResult><Error><Code>4010</Code><Description>The state abbreviation N is not valid.</Description></Error></SearchResult>'] }
92
+ expect{client.make_request(:get, '/path1')}.to raise_error(an_instance_of(Errors::GenericError).and having_attributes({
93
+ http_status: 400,
94
+ headers: {"content-type"=>"application/xml"},
95
+ code: 4010,
96
+ body: {:error=>{:code=>4010, :description=>"The state abbreviation N is not valid."}}
97
+ }))
88
98
  end
89
99
  end
90
100
  end
@@ -0,0 +1,54 @@
1
+ describe BandwidthIris::SipCredential do
2
+ client = nil
3
+
4
+ before :each do
5
+ client = Helper.get_client()
6
+ end
7
+
8
+ after :each do
9
+ client.stubs.verify_stubbed_calls()
10
+ end
11
+
12
+ describe '#list' do
13
+ it 'should return sip credentials' do
14
+ client.stubs.get('/v1.0/accounts/accountId/sipcredentials') {|env| [200, {}, Helper.xml['sip_credentials']]}
15
+ list = SipCredential.list(client)
16
+ expect(list.length).to eql(1)
17
+ expect(list[0][:user_name]).to eql(1)
18
+ end
19
+ end
20
+
21
+ describe '#get' do
22
+ it 'should return a sip credential' do
23
+ client.stubs.get('/v1.0/accounts/accountId/sipcredentials/1') {|env| [200, {}, Helper.xml['sip_credentials']]}
24
+ item = SipCredential.get(client, 1)
25
+ expect(item[:user_name]).to eql(1)
26
+ end
27
+ end
28
+
29
+ describe '#create' do
30
+ it 'should create a sip credential' do
31
+ data = {:name => "test", :description => "test"}
32
+ client.stubs.post('/v1.0/accounts/accountId/sipcredentials', client.build_xml({:sip_credentials => { sip_credential: data }})) {|env| [200, {}, Helper.xml['valid_sip_credentials']]}
33
+ item = SipCredential.create(client, data)
34
+ expect(item[:user_name]).to eql(1)
35
+ end
36
+ end
37
+
38
+ describe '#update' do
39
+ it 'should update a sip credential' do
40
+ data = {:hash1 => "1g32gadgs433dd4"}
41
+ client.stubs.put('/v1.0/accounts/accountId/sipcredentials/1', client.build_xml({:sip_credential => data})) {|env| [200, {}, '']}
42
+ item = SipCredential.new({:user_name => 1}, client)
43
+ item.update(data)
44
+ end
45
+ end
46
+
47
+ describe '#delete' do
48
+ it 'should remove a sip credential' do
49
+ client.stubs.delete('/v1.0/accounts/accountId/sipcredentials/1') {|env| [200, {}, '']}
50
+ item = SipCredential.new({:user_name => 1}, client)
51
+ item.delete
52
+ end
53
+ end
54
+ end
data/spec/helper.rb CHANGED
@@ -2,10 +2,10 @@ require 'simplecov'
2
2
  require 'coveralls'
3
3
  require 'yaml'
4
4
 
5
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
- SimpleCov::Formatter::HTMLFormatter,
7
- Coveralls::SimpleCov::Formatter
8
- ]
5
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter::new
6
+ SimpleCov::Formatter::HTMLFormatter
7
+ Coveralls::SimpleCov::Formatter
8
+
9
9
  SimpleCov.start()
10
10
 
11
11
  require 'ruby-bandwidth-iris'
data/spec/xml.yml CHANGED
@@ -1,6 +1,8 @@
1
1
  ---
2
2
  sites: "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><SitesResponse><Sites><Site><Id>1</Id><Name>Test Site</Name><Description>A site description</Description></Site></Sites></SitesResponse>"
3
3
  site: "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><SiteResponse><Site><Id>1</Id><Name>Test Site</Name><Description>A Site Description</Description><Address><HouseNumber>900</HouseNumber><StreetName>Main Campus Drive</StreetName><City>Raleigh</City><StateCode>NC</StateCode><Zip>27615</Zip><Country>United States</Country><AddressType>Service</AddressType></Address></Site></SiteResponse>"
4
+ sip_credentials: "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><SipCredentialsResponse><SipCredential><UserName>1</UserName></SipCredential></SipCredentialsResponse>"
5
+ valid_sip_credentials: "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><SipCredentialsResponse><ValidSipCredentials><SipCredential><UserName>1</UserName></SipCredential></ValidSipCredentials></SipCredentialsResponse>"
4
6
  sip_peers: "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><TNSipPeersResponse><SipPeers><SipPeer xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"SipPeer\"><PeerId>12345</PeerId><PeerName>SIP Peer 1</PeerName><Description>Sip Peer 1 description</Description><IsDefaultPeer>true</IsDefaultPeer><ShortMessagingProtocol>SIP</ShortMessagingProtocol><VoiceHosts><Host><HostName>70.62.112.156</HostName></Host></VoiceHosts><VoiceHostGroups/><SmsHosts><Host><HostName>70.62.112.156</HostName></Host></SmsHosts><TerminationHosts><TerminationHost><HostName>70.62.112.156</HostName><Port>5060</Port><CustomerTrafficAllowed>DOMESTIC</CustomerTrafficAllowed><DataAllowed>true</DataAllowed></TerminationHost></TerminationHosts><CallingName><Display>true</Display><Enforced>false</Enforced></CallingName></SipPeer></SipPeers></TNSipPeersResponse>"
5
7
  sip_peer: "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><SipPeerResponse><SipPeer><PeerId>10</PeerId><PeerName>SIP Peer 1</PeerName><Description>Sip Peer 1 description</Description><IsDefaultPeer>true</IsDefaultPeer><ShortMessagingProtocol>SIP</ShortMessagingProtocol><VoiceHosts/><VoiceHostGroups/><SmsHosts/><TerminationHosts/><CallingName><Display>true</Display><Enforced>false</Enforced></CallingName></SipPeer></SipPeerResponse>"
6
8
  sip_peer_tns: "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><SipPeerTelephoneNumbersResponse><SipPeerTelephoneNumbers><SipPeerTelephoneNumber><FullNumber>3034162216</FullNumber></SipPeerTelephoneNumber><SipPeerTelephoneNumber><FullNumber>3034162218</FullNumber></SipPeerTelephoneNumber><SipPeerTelephoneNumber><FullNumber>3034162227</FullNumber></SipPeerTelephoneNumber><SipPeerTelephoneNumber><FullNumber>7025097265</FullNumber></SipPeerTelephoneNumber><SipPeerTelephoneNumber><FullNumber>3034162212</FullNumber></SipPeerTelephoneNumber><SipPeerTelephoneNumber><FullNumber>7024759964</FullNumber></SipPeerTelephoneNumber><SipPeerTelephoneNumber><FullNumber>3034162226</FullNumber></SipPeerTelephoneNumber><SipPeerTelephoneNumber><FullNumber>3034162231</FullNumber></SipPeerTelephoneNumber><SipPeerTelephoneNumber><FullNumber>3034162223</FullNumber></SipPeerTelephoneNumber><SipPeerTelephoneNumber><FullNumber>2143770078</FullNumber></SipPeerTelephoneNumber><SipPeerTelephoneNumber><FullNumber>3302699968</FullNumber></SipPeerTelephoneNumber><SipPeerTelephoneNumber><FullNumber>8665711365</FullNumber></SipPeerTelephoneNumber><SipPeerTelephoneNumber><FullNumber>9284448929</FullNumber></SipPeerTelephoneNumber><SipPeerTelephoneNumber><FullNumber>3302710174</FullNumber></SipPeerTelephoneNumber><SipPeerTelephoneNumber><FullNumber>7024797571</FullNumber></SipPeerTelephoneNumber><SipPeerTelephoneNumber><FullNumber>7025091999</FullNumber></SipPeerTelephoneNumber><SipPeerTelephoneNumber><FullNumber>7022579119</FullNumber></SipPeerTelephoneNumber></SipPeerTelephoneNumbers></SipPeerTelephoneNumbersResponse>"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-bandwidth-iris
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Belchikov
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-15 00:00:00.000000000 Z
11
+ date: 2022-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: builder
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: 4.2.7
83
+ - !ruby/object:Gem::Dependency
84
+ name: rexml
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: bundler
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -123,12 +137,17 @@ dependencies:
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0'
125
139
  description: Gem for integrating to Bandwidth's Iris API
126
- email:
140
+ email:
127
141
  executables: []
128
142
  extensions: []
129
143
  extra_rdoc_files: []
130
144
  files:
131
145
  - ".editorconfig"
146
+ - ".github/CODEOWNERS"
147
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
148
+ - ".github/ISSUE_TEMPLATE/config.yml"
149
+ - ".github/workflows/deploy.yml"
150
+ - ".github/workflows/test.yml"
132
151
  - ".gitignore"
133
152
  - ".rspec"
134
153
  - ".travis.yml"
@@ -181,6 +200,7 @@ files:
181
200
  - lib/bandwidth-iris/port_out.rb
182
201
  - lib/bandwidth-iris/rate_center.rb
183
202
  - lib/bandwidth-iris/remove_imported_tn_orders.rb
203
+ - lib/bandwidth-iris/sip_credential.rb
184
204
  - lib/bandwidth-iris/sip_peer.rb
185
205
  - lib/bandwidth-iris/sip_peer_products.rb
186
206
  - lib/bandwidth-iris/site.rb
@@ -221,6 +241,7 @@ files:
221
241
  - spec/bandwidth-iris/remove_imported_tn_orders_spec.rb
222
242
  - spec/bandwidth-iris/sip_peer_products_spec.rb
223
243
  - spec/bandwidth-iris/sip_peer_spec.rb
244
+ - spec/bandwidth-iris/sipcredential_spec.rb
224
245
  - spec/bandwidth-iris/site_spec.rb
225
246
  - spec/bandwidth-iris/subscription_spec.rb
226
247
  - spec/bandwidth-iris/tn_options_spec.rb
@@ -233,7 +254,7 @@ homepage: https://github.com/bandwidthcom/ruby-bandwidth-iris
233
254
  licenses:
234
255
  - MIT
235
256
  metadata: {}
236
- post_install_message:
257
+ post_install_message:
237
258
  rdoc_options: []
238
259
  require_paths:
239
260
  - lib
@@ -248,8 +269,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
248
269
  - !ruby/object:Gem::Version
249
270
  version: '0'
250
271
  requirements: []
251
- rubygems_version: 3.2.20
252
- signing_key:
272
+ rubygems_version: 3.2.33
273
+ signing_key:
253
274
  specification_version: 4
254
275
  summary: Gem for integrating to Bandwidth's Iris API
255
276
  test_files:
@@ -282,6 +303,7 @@ test_files:
282
303
  - spec/bandwidth-iris/remove_imported_tn_orders_spec.rb
283
304
  - spec/bandwidth-iris/sip_peer_products_spec.rb
284
305
  - spec/bandwidth-iris/sip_peer_spec.rb
306
+ - spec/bandwidth-iris/sipcredential_spec.rb
285
307
  - spec/bandwidth-iris/site_spec.rb
286
308
  - spec/bandwidth-iris/subscription_spec.rb
287
309
  - spec/bandwidth-iris/tn_options_spec.rb