nexmos 0.2 → 0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +17 -0
- data/.travis.yml +11 -2
- data/Appraisals +15 -0
- data/Gemfile +15 -4
- data/Guardfile +20 -0
- data/Rakefile +2 -2
- data/defaults.reek +11 -0
- data/gemfiles/activesupport_3.2.gemfile +23 -0
- data/gemfiles/activesupport_4.0.gemfile +23 -0
- data/gemfiles/activesupport_4.1.gemfile +23 -0
- data/gemfiles/activesupport_4.2.gemfile +23 -0
- data/lib/faraday_middleware/response/mashrashify.rb +19 -0
- data/lib/hashie/mash/rash.rb +41 -0
- data/lib/nexmos.rb +1 -0
- data/lib/nexmos/account.rb +2 -2
- data/lib/nexmos/base.rb +25 -29
- data/lib/nexmos/message.rb +2 -2
- data/lib/nexmos/number.rb +2 -2
- data/lib/nexmos/railties.rb +1 -1
- data/lib/nexmos/search.rb +2 -2
- data/lib/nexmos/text_to_speech.rb +2 -2
- data/lib/nexmos/version.rb +1 -1
- data/nexmos.gemspec +3 -3
- data/spec/nexmos/account_spec.rb +46 -40
- data/spec/nexmos/base_spec.rb +71 -60
- data/spec/nexmos/number_spec.rb +66 -64
- data/spec/nexmos_spec.rb +26 -11
- data/spec/spec_helper.rb +11 -16
- metadata +43 -29
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
    
        data/lib/nexmos/railties.rb
    CHANGED
    
    
    
        data/lib/nexmos/search.rb
    CHANGED
    
    
    
        data/lib/nexmos/version.rb
    CHANGED
    
    
    
        data/nexmos.gemspec
    CHANGED
    
    | @@ -15,10 +15,10 @@ Gem::Specification.new do |gem| | |
| 15 15 | 
             
              gem.executables   = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
         | 
| 16 16 | 
             
              gem.test_files    = gem.files.grep(%r{^(test|spec|features)/})
         | 
| 17 17 | 
             
              gem.require_paths = ["lib"]
         | 
| 18 | 
            -
              gem.add_dependency(' | 
| 18 | 
            +
              gem.add_dependency('hashie', '>= 2.1.0')
         | 
| 19 19 | 
             
              gem.add_dependency('faraday')
         | 
| 20 20 | 
             
              gem.add_dependency('faraday_middleware')
         | 
| 21 | 
            -
              gem.add_dependency('activesupport', '>= 3.0.0')
         | 
| 22 | 
            -
              gem.add_development_dependency('rspec')
         | 
| 21 | 
            +
              gem.add_dependency('activesupport', '>= 3.0', '<= 5.0')
         | 
| 22 | 
            +
              gem.add_development_dependency('rspec', '>= 3.0')
         | 
| 23 23 | 
             
              gem.add_development_dependency('webmock')
         | 
| 24 24 | 
             
            end
         | 
    
        data/spec/nexmos/account_spec.rb
    CHANGED
    
    | @@ -45,7 +45,7 @@ describe ::Nexmos::Account do | |
| 45 45 | 
             
                          "ranges" => ["35846", "35850"],
         | 
| 46 46 | 
             
                          "mtPrice" => "0.05000000"}],
         | 
| 47 47 | 
             
                    "name" => "Finland"
         | 
| 48 | 
            -
                }
         | 
| 48 | 
            +
                }.to_json
         | 
| 49 49 | 
             
              end
         | 
| 50 50 |  | 
| 51 51 | 
             
              let(:prefix_prices) do
         | 
| @@ -80,7 +80,7 @@ describe ::Nexmos::Account do | |
| 80 80 | 
             
                         "ranges" => nil,
         | 
| 81 81 | 
             
                         "mtPrice" => "0.05000000"}],
         | 
| 82 82 | 
             
                     "name" => "Finland"}],
         | 
| 83 | 
            -
                 }
         | 
| 83 | 
            +
                 }.to_json
         | 
| 84 84 | 
             
              end
         | 
| 85 85 |  | 
| 86 86 | 
             
              before(:each) do
         | 
| @@ -97,11 +97,11 @@ describe ::Nexmos::Account do | |
| 97 97 |  | 
| 98 98 | 
             
                it 'should return value' do
         | 
| 99 99 | 
             
                  request = stub_request(:get, "https://rest.nexmo.com/account/get-balance?api_key=default_key&api_secret=default_secret").
         | 
| 100 | 
            -
                      with(webmock_default_headers).to_return(:status => 200, :body => {"value" => 4.107}, : | 
| 100 | 
            +
                      with(webmock_default_headers).to_return(:status => 200, :body => {"value" => 4.107}.to_json, headers: {'Content-Type' => 'application/json'})
         | 
| 101 101 | 
             
                  res = subject.get_balance
         | 
| 102 | 
            -
                  res. | 
| 103 | 
            -
                  res.value. | 
| 104 | 
            -
                  request. | 
| 102 | 
            +
                  expect(res).to be_kind_of(::Hash)
         | 
| 103 | 
            +
                  expect(res.value).to eq(4.107)
         | 
| 104 | 
            +
                  expect(request).to have_been_made.once
         | 
| 105 105 | 
             
                end
         | 
| 106 106 | 
             
              end
         | 
| 107 107 |  | 
| @@ -112,15 +112,15 @@ describe ::Nexmos::Account do | |
| 112 112 |  | 
| 113 113 | 
             
                it 'should be success' do
         | 
| 114 114 | 
             
                  request = stub_request(:get, "https://rest.nexmo.com/account/get-pricing/outbound?api_key=default_key&api_secret=default_secret&country=FI").
         | 
| 115 | 
            -
                      with(webmock_default_headers).to_return(:status => 200, :body => finland_prices, :headers => {})
         | 
| 115 | 
            +
                      with(webmock_default_headers).to_return(:status => 200, :body => finland_prices, :headers => {'Content-Type' => 'application/json'})
         | 
| 116 116 | 
             
                  res = subject.get_pricing(:country => 'FI')
         | 
| 117 | 
            -
                  res. | 
| 118 | 
            -
                  res.success | 
| 119 | 
            -
                  res.country. | 
| 120 | 
            -
                  res.keys.sort. | 
| 121 | 
            -
                  res.networks. | 
| 122 | 
            -
                  res.networks[0].keys.sort. | 
| 123 | 
            -
                  request. | 
| 117 | 
            +
                  expect(res).to be_kind_of(::Hash)
         | 
| 118 | 
            +
                  expect(res.success?).to be_truthy
         | 
| 119 | 
            +
                  expect(res.country).to eq('FI')
         | 
| 120 | 
            +
                  expect(res.keys.sort).to eq(%w(country name prefix mt networks success?).sort)
         | 
| 121 | 
            +
                  expect(res.networks).to be_kind_of(::Array)
         | 
| 122 | 
            +
                  expect(res.networks[0].keys.sort).to eq(%w(code network mt_price ranges).sort)
         | 
| 123 | 
            +
                  expect(request).to have_been_made.once
         | 
| 124 124 | 
             
                end
         | 
| 125 125 | 
             
              end
         | 
| 126 126 |  | 
| @@ -131,41 +131,47 @@ describe ::Nexmos::Account do | |
| 131 131 |  | 
| 132 132 | 
             
                it 'should be success' do
         | 
| 133 133 | 
             
                  request = stub_request(:get, "https://rest.nexmo.com/account/get-prefix-pricing/outbound?api_key=default_key&api_secret=default_secret&prefix=358").
         | 
| 134 | 
            -
                      with(webmock_default_headers).to_return(:status => 200, :body => prefix_prices, :headers => {})
         | 
| 134 | 
            +
                      with(webmock_default_headers).to_return(:status => 200, :body => prefix_prices, :headers => {'Content-Type' => 'application/json'})
         | 
| 135 135 | 
             
                  res = subject.get_prefix_pricing(:prefix => '358')
         | 
| 136 | 
            -
                  res. | 
| 137 | 
            -
                  res.success | 
| 138 | 
            -
                  res.keys.sort. | 
| 139 | 
            -
                  res.prices. | 
| 140 | 
            -
                  res.prices[0].keys.sort. | 
| 141 | 
            -
                  res.prices[0].networks. | 
| 142 | 
            -
                  res.prices[0].networks[0].keys.sort. | 
| 143 | 
            -
                  request. | 
| 136 | 
            +
                  expect(res).to be_kind_of(::Hash)
         | 
| 137 | 
            +
                  expect(res.success?).to be_truthy
         | 
| 138 | 
            +
                  expect(res.keys.sort).to eq(%w(count prices success?).sort)
         | 
| 139 | 
            +
                  expect(res.prices).to be_kind_of(::Array)
         | 
| 140 | 
            +
                  expect(res.prices[0].keys.sort).to eq(%w(country name prefix mt networks).sort)
         | 
| 141 | 
            +
                  expect(res.prices[0].networks).to be_kind_of(::Array)
         | 
| 142 | 
            +
                  expect(res.prices[0].networks[0].keys.sort).to eq(%w(code network mt_price ranges).sort)
         | 
| 143 | 
            +
                  expect(request).to have_been_made.once
         | 
| 144 144 | 
             
                end
         | 
| 145 145 | 
             
              end
         | 
| 146 146 |  | 
| 147 147 | 
             
              context '#get_numbers' do
         | 
| 148 148 | 
             
                it 'should return only count on empty numbers' do
         | 
| 149 149 | 
             
                  request = stub_request(:get, "https://rest.nexmo.com/account/numbers?api_key=default_key&api_secret=default_secret").
         | 
| 150 | 
            -
                      with(webmock_default_headers).to_return(:status => 200, :body => {:count => 0}, :headers => {})
         | 
| 150 | 
            +
                      with(webmock_default_headers).to_return(:status => 200, :body => {:count => 0}.to_json, :headers => {'Content-Type' => 'application/json'})
         | 
| 151 151 | 
             
                  res = subject.get_numbers
         | 
| 152 | 
            -
                  res. | 
| 153 | 
            -
                  res.success | 
| 154 | 
            -
                  res['count']. | 
| 155 | 
            -
                  request. | 
| 152 | 
            +
                  expect(res).to be_kind_of(::Hash)
         | 
| 153 | 
            +
                  expect(res.success?).to be_truthy
         | 
| 154 | 
            +
                  expect(res['count']).to eq(0)
         | 
| 155 | 
            +
                  expect(request).to have_been_made.once
         | 
| 156 156 | 
             
                end
         | 
| 157 157 |  | 
| 158 158 | 
             
                it 'should return numbers array' do
         | 
| 159 159 | 
             
                  request = stub_request(:get, "https://rest.nexmo.com/account/numbers?api_key=default_key&api_secret=default_secret").
         | 
| 160 | 
            -
                      with(webmock_default_headers).to_return(:status => 200, | 
| 160 | 
            +
                      with(webmock_default_headers).to_return(:status => 200,
         | 
| 161 | 
            +
                                                              :body => {
         | 
| 162 | 
            +
                                                                "count" => 1,
         | 
| 163 | 
            +
                                                                "numbers" => [
         | 
| 164 | 
            +
                                                                  {"country" => "ES","msisdn" => "34911067000","type" => "landline"}
         | 
| 165 | 
            +
                                                                ]
         | 
| 166 | 
            +
                                                              }.to_json, :headers => {'Content-Type' => 'application/json'})
         | 
| 161 167 | 
             
                  res = subject.get_numbers
         | 
| 162 | 
            -
                  res. | 
| 163 | 
            -
                  res.success | 
| 164 | 
            -
                  res['count']. | 
| 165 | 
            -
                  res['numbers']. | 
| 166 | 
            -
                  res['numbers'].first. | 
| 167 | 
            -
                  res['numbers'].first. | 
| 168 | 
            -
                  request. | 
| 168 | 
            +
                  expect(res).to be_kind_of(::Hash)
         | 
| 169 | 
            +
                  expect(res.success?).to be_truthy
         | 
| 170 | 
            +
                  expect(res['count']).to eq(1)
         | 
| 171 | 
            +
                  expect(res['numbers']).to be_kind_of(::Array)
         | 
| 172 | 
            +
                  expect(res['numbers'].first).to be_kind_of(::Hash)
         | 
| 173 | 
            +
                  expect(res['numbers'].first).to eq({"country" => "ES","msisdn" => "34911067000","type" => "landline"})
         | 
| 174 | 
            +
                  expect(request).to have_been_made.once
         | 
| 169 175 | 
             
                end
         | 
| 170 176 | 
             
              end
         | 
| 171 177 |  | 
| @@ -176,11 +182,11 @@ describe ::Nexmos::Account do | |
| 176 182 |  | 
| 177 183 | 
             
                it 'should success top up' do
         | 
| 178 184 | 
             
                  request = stub_request(:get, "https://rest.nexmo.com/account/top-up?api_key=default_key&api_secret=default_secret&trx=test_trx").
         | 
| 179 | 
            -
                      with(webmock_default_headers).to_return(:status => 200, :body => '', :headers => {})
         | 
| 185 | 
            +
                      with(webmock_default_headers).to_return(:status => 200, :body => '', :headers => {'Content-Type' => 'application/json'})
         | 
| 180 186 | 
             
                  res = subject.top_up :trx => 'test_trx'
         | 
| 181 | 
            -
                  res. | 
| 182 | 
            -
                  res.success | 
| 183 | 
            -
                  request. | 
| 187 | 
            +
                  expect(res).to be_kind_of(::Hash)
         | 
| 188 | 
            +
                  expect(res.success?).to be_truthy
         | 
| 189 | 
            +
                  expect(request).to have_been_made.once
         | 
| 184 190 | 
             
                end
         | 
| 185 191 |  | 
| 186 192 | 
             
              end
         | 
    
        data/spec/nexmos/base_spec.rb
    CHANGED
    
    | @@ -4,9 +4,9 @@ describe ::Nexmos::Base do | |
| 4 4 | 
             
              let(:webmock_default_headers) do
         | 
| 5 5 | 
             
                {
         | 
| 6 6 | 
             
                  :headers => {
         | 
| 7 | 
            -
                    'Accept'=>'application/json',
         | 
| 8 | 
            -
                    'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
         | 
| 9 | 
            -
                    'User-Agent'=> ::Nexmos.user_agent
         | 
| 7 | 
            +
                    'Accept'          => 'application/json',
         | 
| 8 | 
            +
                    'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
         | 
| 9 | 
            +
                    'User-Agent'      => ::Nexmos.user_agent
         | 
| 10 10 | 
             
                  }
         | 
| 11 11 | 
             
                }
         | 
| 12 12 | 
             
              end
         | 
| @@ -14,20 +14,28 @@ describe ::Nexmos::Base do | |
| 14 14 | 
             
              before(:each) do
         | 
| 15 15 | 
             
                ::Nexmos.reset!
         | 
| 16 16 | 
             
              end
         | 
| 17 | 
            +
             | 
| 17 18 | 
             
              context 'class' do
         | 
| 18 | 
            -
                subject {  | 
| 19 | 
            +
                subject { described_class }
         | 
| 19 20 | 
             
                let(:default_faraday_options) do
         | 
| 20 21 | 
             
                  {
         | 
| 21 | 
            -
                    :url | 
| 22 | 
            +
                    :url     => 'https://rest.nexmo.com',
         | 
| 22 23 | 
             
                    :headers => {
         | 
| 23 | 
            -
                      :accept  | 
| 24 | 
            +
                      :accept     => 'application/json',
         | 
| 24 25 | 
             
                      :user_agent => ::Nexmos.user_agent
         | 
| 25 26 | 
             
                    }
         | 
| 26 27 | 
             
                  }
         | 
| 27 28 | 
             
                end
         | 
| 28 29 |  | 
| 29 | 
            -
                 | 
| 30 | 
            -
             | 
| 30 | 
            +
                describe '#faraday_options' do
         | 
| 31 | 
            +
                  subject { super().faraday_options }
         | 
| 32 | 
            +
                  it { is_expected.to eq(default_faraday_options) }
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                describe '#connection' do
         | 
| 36 | 
            +
                  subject { super().connection }
         | 
| 37 | 
            +
                  it { is_expected.to be_kind_of(::Faraday::Connection) }
         | 
| 38 | 
            +
                end
         | 
| 31 39 |  | 
| 32 40 | 
             
                context 'faraday_options' do
         | 
| 33 41 | 
             
                  it 'should have custom user agent' do
         | 
| @@ -35,14 +43,14 @@ describe ::Nexmos::Base do | |
| 35 43 | 
             
                      c.user_agent = 'test user agent'
         | 
| 36 44 | 
             
                    end
         | 
| 37 45 | 
             
                    default_faraday_options[:headers][:user_agent] = 'test user agent'
         | 
| 38 | 
            -
                    subject.faraday_options. | 
| 46 | 
            +
                    expect(subject.faraday_options).to eq(default_faraday_options)
         | 
| 39 47 | 
             
                  end
         | 
| 40 48 | 
             
                end
         | 
| 41 49 |  | 
| 42 50 | 
             
                context 'define_api_calls' do
         | 
| 43 51 | 
             
                  it 'should call define_method' do
         | 
| 44 52 | 
             
                    ::Nexmos.apis[:account].keys.each do |k|
         | 
| 45 | 
            -
                      subject. | 
| 53 | 
            +
                      expect(subject).to receive(:define_method).with(k)
         | 
| 46 54 | 
             
                    end
         | 
| 47 55 | 
             
                    subject.define_api_calls(:account)
         | 
| 48 56 | 
             
                  end
         | 
| @@ -50,7 +58,7 @@ describe ::Nexmos::Base do | |
| 50 58 | 
             
                  it 'should define dynamic method and call make_api_call inside' do
         | 
| 51 59 | 
             
                    subject.define_api_calls(:account)
         | 
| 52 60 | 
             
                    instance = subject.new('test_key', 'test_secret')
         | 
| 53 | 
            -
                    instance. | 
| 61 | 
            +
                    expect(instance).to receive(:make_api_call).with(::Nexmos.apis[:account][:get_balance], {})
         | 
| 54 62 | 
             
                    instance.get_balance
         | 
| 55 63 | 
             
                  end
         | 
| 56 64 | 
             
                end
         | 
| @@ -61,140 +69,143 @@ describe ::Nexmos::Base do | |
| 61 69 | 
             
                subject { ::Nexmos::Base.new('test_api', 'test_secret') }
         | 
| 62 70 | 
             
                context 'new' do
         | 
| 63 71 | 
             
                  it 'should raise on empty api_key' do
         | 
| 64 | 
            -
                    expect {::Nexmos::Base.new('', 'test_secret')}.to raise_error('api_key should be set')
         | 
| 72 | 
            +
                    expect { ::Nexmos::Base.new('', 'test_secret') }.to raise_error('api_key should be set')
         | 
| 65 73 | 
             
                  end
         | 
| 66 74 | 
             
                  it 'should raise on empty api_secret' do
         | 
| 67 | 
            -
                    expect {::Nexmos::Base.new('test_key', '')}.to raise_error('api_secret should be set')
         | 
| 75 | 
            +
                    expect { ::Nexmos::Base.new('test_key', '') }.to raise_error('api_secret should be set')
         | 
| 68 76 | 
             
                  end
         | 
| 69 77 | 
             
                  it 'should set default_params with values from ::Nexmos module' do
         | 
| 70 78 | 
             
                    ::Nexmos.setup do |c|
         | 
| 71 | 
            -
                      c.api_key | 
| 79 | 
            +
                      c.api_key    = 'default_key'
         | 
| 72 80 | 
             
                      c.api_secret = 'default_secret'
         | 
| 73 81 | 
             
                    end
         | 
| 74 82 | 
             
                    instance = ::Nexmos::Base.new
         | 
| 75 | 
            -
                    instance.instance_variable_get('@default_params'). | 
| 83 | 
            +
                    expect(instance.instance_variable_get('@default_params')).to eq({ 'api_key' => 'default_key', 'api_secret' => 'default_secret' })
         | 
| 76 84 | 
             
                  end
         | 
| 77 85 | 
             
                  it 'should set default_params with custom api key and secret' do
         | 
| 78 86 | 
             
                    instance = ::Nexmos::Base.new('test_key', 'test_secret')
         | 
| 79 | 
            -
                    instance.instance_variable_get('@default_params'). | 
| 87 | 
            +
                    expect(instance.instance_variable_get('@default_params')).to eq({ 'api_key' => 'test_key', 'api_secret' => 'test_secret' })
         | 
| 80 88 | 
             
                  end
         | 
| 81 89 | 
             
                end
         | 
| 82 90 |  | 
| 83 | 
            -
                 | 
| 91 | 
            +
                describe '#connection' do
         | 
| 92 | 
            +
                  subject { super().connection }
         | 
| 93 | 
            +
                  it { is_expected.to be_kind_of(::Faraday::Connection) }
         | 
| 94 | 
            +
                end
         | 
| 84 95 |  | 
| 85 96 | 
             
                context 'make_api_call' do
         | 
| 86 97 |  | 
| 87 98 | 
             
                  before(:each) do
         | 
| 88 99 | 
             
                    stub_request(:get, "https://rest.nexmo.com/test/url?api_key=test_api&api_secret=test_secret").
         | 
| 89 | 
            -
             | 
| 90 | 
            -
             | 
| 100 | 
            +
                      with(:headers => { 'Accept' => 'application/json', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => ::Nexmos.user_agent }).
         | 
| 101 | 
            +
                      to_return(:status => 200, :body => { 'key' => 'value' }.to_json, :headers => { 'Content-Type' => 'application/json' })
         | 
| 91 102 | 
             
                  end
         | 
| 92 103 |  | 
| 93 104 | 
             
                  let(:api_params_without_required) do
         | 
| 94 105 | 
             
                    {
         | 
| 95 106 | 
             
                      :method => :get,
         | 
| 96 | 
            -
                      :url | 
| 107 | 
            +
                      :url    => '/test/url'
         | 
| 97 108 | 
             
                    }
         | 
| 98 109 | 
             
                  end
         | 
| 99 110 |  | 
| 100 111 | 
             
                  let(:api_params_with_required) do
         | 
| 101 112 | 
             
                    {
         | 
| 102 | 
            -
                      :method | 
| 103 | 
            -
                      :url | 
| 113 | 
            +
                      :method   => :get,
         | 
| 114 | 
            +
                      :url      => '/test/url',
         | 
| 104 115 | 
             
                      :required => %w(key1 key2)
         | 
| 105 116 | 
             
                    }
         | 
| 106 117 | 
             
                  end
         | 
| 107 118 |  | 
| 108 119 | 
             
                  it 'should call check_required_params' do
         | 
| 109 | 
            -
                    subject. | 
| 120 | 
            +
                    expect(subject).to receive(:check_required_params)
         | 
| 110 121 | 
             
                    subject.make_api_call(api_params_with_required)
         | 
| 111 122 | 
             
                  end
         | 
| 112 123 |  | 
| 113 124 | 
             
                  it 'should raise if all required params missing' do
         | 
| 114 | 
            -
                    expect{subject.make_api_call(api_params_with_required)}.to raise_error('key1,key2 params required')
         | 
| 125 | 
            +
                    expect { subject.make_api_call(api_params_with_required) }.to raise_error('key1,key2 params required')
         | 
| 115 126 | 
             
                  end
         | 
| 116 127 |  | 
| 117 128 | 
             
                  it 'should raise if some required params missing' do
         | 
| 118 | 
            -
                    expect{subject.make_api_call(api_params_with_required,{:key1 => 'val'})}.to raise_error('key2 params required')
         | 
| 129 | 
            +
                    expect { subject.make_api_call(api_params_with_required, { :key1 => 'val' }) }.to raise_error('key2 params required')
         | 
| 119 130 | 
             
                  end
         | 
| 120 131 |  | 
| 121 132 | 
             
                  it 'should call normalize_params' do
         | 
| 122 | 
            -
                    subject. | 
| 133 | 
            +
                    expect(subject).to receive(:normalize_params).and_call_original
         | 
| 123 134 | 
             
                    subject.make_api_call(api_params_without_required)
         | 
| 124 135 | 
             
                  end
         | 
| 125 136 |  | 
| 126 137 | 
             
                  it 'should not call camelize_params' do
         | 
| 127 138 | 
             
                    stub_request(:get, "https://rest.nexmo.com/test/url?api_key=test_api&api_secret=test_secret&test_call=value").
         | 
| 128 | 
            -
             | 
| 129 | 
            -
             | 
| 130 | 
            -
                    subject. | 
| 131 | 
            -
                    subject.make_api_call(api_params_without_required, {'test_call' => 'value'})
         | 
| 139 | 
            +
                      with(webmock_default_headers).
         | 
| 140 | 
            +
                      to_return(:status => 200, :body => {}.to_json, :headers => { 'Content-Type' => 'application/json' })
         | 
| 141 | 
            +
                    expect(subject).not_to receive(:camelize_params)
         | 
| 142 | 
            +
                    subject.make_api_call(api_params_without_required, { 'test_call' => 'value' })
         | 
| 132 143 | 
             
                  end
         | 
| 133 144 |  | 
| 134 145 | 
             
                  it 'should call camelize_params' do
         | 
| 135 146 | 
             
                    stub_request(:get, "https://rest.nexmo.com/test/url?api_key=test_api&api_secret=test_secret&testCall=value").
         | 
| 136 | 
            -
             | 
| 137 | 
            -
             | 
| 138 | 
            -
                    subject. | 
| 139 | 
            -
                    subject.make_api_call(api_params_without_required.merge(:camelize => true), {'test_call' => 'value'})
         | 
| 147 | 
            +
                      with(webmock_default_headers).
         | 
| 148 | 
            +
                      to_return(:status => 200, :body => {}.to_json, :headers => { 'Content-Type' => 'application/json' })
         | 
| 149 | 
            +
                    expect(subject).to receive(:camelize_params).and_call_original
         | 
| 150 | 
            +
                    subject.make_api_call(api_params_without_required.merge(:camelize => true), { 'test_call' => 'value' })
         | 
| 140 151 | 
             
                  end
         | 
| 141 152 |  | 
| 142 153 | 
             
                  it 'should call get_response' do
         | 
| 143 154 | 
             
                    stub_request(:get, "https://rest.nexmo.com/test/url?api_key=test_api&api_secret=test_secret").
         | 
| 144 | 
            -
             | 
| 145 | 
            -
             | 
| 146 | 
            -
                    subject. | 
| 155 | 
            +
                      with(webmock_default_headers).
         | 
| 156 | 
            +
                      to_return(:status => 200, :body => {}.to_json, :headers => { 'Content-Type' => 'application/json' })
         | 
| 157 | 
            +
                    expect(subject).to receive(:get_response).and_call_original
         | 
| 147 158 | 
             
                    subject.make_api_call(api_params_without_required)
         | 
| 148 159 | 
             
                  end
         | 
| 149 160 |  | 
| 150 161 | 
             
                  it 'should return hash' do
         | 
| 151 | 
            -
                    subject.make_api_call(api_params_without_required). | 
| 162 | 
            +
                    expect(subject.make_api_call(api_params_without_required)).to be_a_kind_of(::Hash)
         | 
| 152 163 | 
             
                  end
         | 
| 153 164 |  | 
| 154 165 | 
             
                  it 'should return Hashie::Mash' do
         | 
| 155 | 
            -
                    subject.make_api_call(api_params_without_required). | 
| 166 | 
            +
                    expect(subject.make_api_call(api_params_without_required)).to be_a_kind_of(::Hashie::Mash)
         | 
| 156 167 | 
             
                  end
         | 
| 157 168 |  | 
| 158 169 | 
             
                  it 'should respond to success? method in result' do
         | 
| 159 | 
            -
                    subject.make_api_call(api_params_without_required). | 
| 170 | 
            +
                    expect(subject.make_api_call(api_params_without_required)).to respond_to(:success?)
         | 
| 160 171 | 
             
                  end
         | 
| 161 172 |  | 
| 162 173 | 
             
                  it 'should have success? key in hash' do
         | 
| 163 | 
            -
                    subject.make_api_call(api_params_without_required)[:success?]. | 
| 174 | 
            +
                    expect(subject.make_api_call(api_params_without_required)[:success?]).to be
         | 
| 164 175 | 
             
                  end
         | 
| 165 176 |  | 
| 166 177 | 
             
                  it 'should have success? == true' do
         | 
| 167 | 
            -
                    subject.make_api_call(api_params_without_required)[:success?]. | 
| 178 | 
            +
                    expect(subject.make_api_call(api_params_without_required)[:success?]).to be_truthy
         | 
| 168 179 | 
             
                  end
         | 
| 169 180 |  | 
| 170 181 | 
             
                  it 'should have success? == false on response with status != 200' do
         | 
| 171 182 | 
             
                    stub_request(:get, "https://rest.nexmo.com/test/url?api_key=test_api&api_secret=test_secret&testCall=value").
         | 
| 172 | 
            -
             | 
| 173 | 
            -
             | 
| 174 | 
            -
                    res = subject.make_api_call(api_params_without_required.merge(:camelize => true), {'test_call' => 'value'})
         | 
| 175 | 
            -
                    res[:success?]. | 
| 176 | 
            -
                    res[:failed?]. | 
| 177 | 
            -
                    res[:not_authorized?]. | 
| 183 | 
            +
                      with(webmock_default_headers).
         | 
| 184 | 
            +
                      to_return(:status => 410, :body => {}.to_json, :headers => { 'Content-Type' => 'application/json' })
         | 
| 185 | 
            +
                    res = subject.make_api_call(api_params_without_required.merge(:camelize => true), { 'test_call' => 'value' })
         | 
| 186 | 
            +
                    expect(res[:success?]).to be_falsey
         | 
| 187 | 
            +
                    expect(res[:failed?]).to be_falsey
         | 
| 188 | 
            +
                    expect(res[:not_authorized?]).to be_falsey
         | 
| 178 189 | 
             
                  end
         | 
| 179 190 |  | 
| 180 191 | 
             
                  it 'should have not_authorized? == true' do
         | 
| 181 192 | 
             
                    stub_request(:get, "https://rest.nexmo.com/test/url?api_key=test_api&api_secret=test_secret&testCall=value").
         | 
| 182 | 
            -
             | 
| 183 | 
            -
             | 
| 184 | 
            -
                    res = subject.make_api_call(api_params_without_required.merge(:camelize => true), {'test_call' => 'value'})
         | 
| 185 | 
            -
                    res[:success?]. | 
| 186 | 
            -
                    res[:not_authorized?]. | 
| 187 | 
            -
                    res[:failed?]. | 
| 193 | 
            +
                      with(webmock_default_headers).
         | 
| 194 | 
            +
                      to_return(:status => 401, :body => {}.to_json, :headers => { 'Content-Type' => 'application/json' })
         | 
| 195 | 
            +
                    res = subject.make_api_call(api_params_without_required.merge(:camelize => true), { 'test_call' => 'value' })
         | 
| 196 | 
            +
                    expect(res[:success?]).to be_falsey
         | 
| 197 | 
            +
                    expect(res[:not_authorized?]).to be_truthy
         | 
| 198 | 
            +
                    expect(res[:failed?]).to be_falsey
         | 
| 188 199 | 
             
                  end
         | 
| 189 200 |  | 
| 190 201 | 
             
                  it 'should have failed? == true' do
         | 
| 191 202 | 
             
                    stub_request(:get, "https://rest.nexmo.com/test/url?api_key=test_api&api_secret=test_secret&testCall=value").
         | 
| 192 | 
            -
             | 
| 193 | 
            -
             | 
| 194 | 
            -
                    res = subject.make_api_call(api_params_without_required.merge(:camelize => true), {'test_call' => 'value'})
         | 
| 195 | 
            -
                    res[:success?]. | 
| 196 | 
            -
                    res[:not_authorized?]. | 
| 197 | 
            -
                    res[:failed?]. | 
| 203 | 
            +
                      with(webmock_default_headers).
         | 
| 204 | 
            +
                      to_return(:status => 420, :body => {}.to_json, :headers => { 'Content-Type' => 'application/json' })
         | 
| 205 | 
            +
                    res = subject.make_api_call(api_params_without_required.merge(:camelize => true), { 'test_call' => 'value' })
         | 
| 206 | 
            +
                    expect(res[:success?]).to be_falsey
         | 
| 207 | 
            +
                    expect(res[:not_authorized?]).to be_falsey
         | 
| 208 | 
            +
                    expect(res[:failed?]).to be_truthy
         | 
| 198 209 | 
             
                  end
         | 
| 199 210 |  | 
| 200 211 | 
             
                end
         |