twilio_mock 0.3.0 → 0.4.0
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/lib/rest.rb +16 -28
- data/lib/twilio_extensions.rb +29 -0
- data/lib/twilio_mock/lookup_mocker.rb +0 -1
- data/lib/twilio_mock/mocker.rb +9 -11
- data/lib/twilio_mock/twilify.rb +17 -0
- data/lib/twilio_mock.rb +1 -0
- metadata +8 -6
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 6a05cb105815e32d33c2d0009cb25386237db3fd
         | 
| 4 | 
            +
              data.tar.gz: db93df91d08525b98908d535e98ba326843bf53f
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 87d6406e5bf963ae0fe39bc17961c10aa8df25e18ff8d967cde2e39a22d7de742d3a4841f4c6637b2aa10da56b2ec00eb3f9d499ee80362e1934dae7c95c763e
         | 
| 7 | 
            +
              data.tar.gz: 68ec49c5c7d230b79566cc72de70eeb0f059ecf83614a3eb2905b1957b4899a16ec0a025a7f1f0157a74fa10c0af9d85c3294eb50618d3a41c267df13ae623d0
         | 
    
        data/lib/rest.rb
    CHANGED
    
    | @@ -1,40 +1,28 @@ | |
| 1 1 | 
             
            require 'twilio-ruby'
         | 
| 2 | 
            +
            require 'twilio_extensions'
         | 
| 2 3 |  | 
| 3 4 | 
             
            module Twilio
         | 
| 4 5 | 
             
              module REST
         | 
| 5 | 
            -
                class  | 
| 6 | 
            -
                   | 
| 7 | 
            -
                     | 
| 8 | 
            -
             | 
| 9 | 
            -
                  end
         | 
| 10 | 
            -
                end
         | 
| 11 | 
            -
             | 
| 12 | 
            -
                class IncomingPhoneNumbers < ListResource
         | 
| 13 | 
            -
                  def create(attrs)
         | 
| 14 | 
            -
                    TwilioMock::Mocker.new.buy_number(attrs) if TwilioMock::Testing.enabled?
         | 
| 15 | 
            -
                    super(attrs)
         | 
| 16 | 
            -
                  end
         | 
| 17 | 
            -
                end
         | 
| 6 | 
            +
                class Api < Domain
         | 
| 7 | 
            +
                  class V2010 < Version
         | 
| 8 | 
            +
                    class AccountContext < InstanceContext
         | 
| 9 | 
            +
                      prepend TwilioExtensions::AccountContext
         | 
| 18 10 |  | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
                    super(sid)
         | 
| 23 | 
            -
                  end
         | 
| 24 | 
            -
                end
         | 
| 11 | 
            +
                      class MessageList < ListResource
         | 
| 12 | 
            +
                        prepend TwilioExtensions::Messages
         | 
| 13 | 
            +
                      end
         | 
| 25 14 |  | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
                     | 
| 15 | 
            +
                      class IncomingPhoneNumberList < ListResource
         | 
| 16 | 
            +
                        prepend TwilioExtensions::IncomingPhoneNumbers
         | 
| 17 | 
            +
                      end
         | 
| 18 | 
            +
                    end
         | 
| 30 19 | 
             
                  end
         | 
| 31 20 | 
             
                end
         | 
| 32 21 |  | 
| 33 | 
            -
                 | 
| 34 | 
            -
                  class  | 
| 35 | 
            -
                     | 
| 36 | 
            -
                       | 
| 37 | 
            -
                      super(number)
         | 
| 22 | 
            +
                class Lookups
         | 
| 23 | 
            +
                  class V1 < Version
         | 
| 24 | 
            +
                    class PhoneNumberContext < InstanceContext
         | 
| 25 | 
            +
                      prepend TwilioExtensions::Lookups
         | 
| 38 26 | 
             
                    end
         | 
| 39 27 | 
             
                  end
         | 
| 40 28 | 
             
                end
         | 
| @@ -0,0 +1,29 @@ | |
| 1 | 
            +
            module TwilioExtensions
         | 
| 2 | 
            +
              module AccountContext
         | 
| 3 | 
            +
                def available_phone_numbers(country_code=:unset)
         | 
| 4 | 
            +
                  TwilioMock::Mocker.new.available_number if TwilioMock::Testing.enabled?
         | 
| 5 | 
            +
                  super(country_code)
         | 
| 6 | 
            +
                end
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              module Messages
         | 
| 10 | 
            +
                def create(attrs)
         | 
| 11 | 
            +
                  TwilioMock::Mocker.new.create_message(attrs) if TwilioMock::Testing.enabled?
         | 
| 12 | 
            +
                  super(attrs)
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              module IncomingPhoneNumbers
         | 
| 17 | 
            +
                def create(attrs)
         | 
| 18 | 
            +
                  TwilioMock::Mocker.new.buy_number(attrs) if TwilioMock::Testing.enabled?
         | 
| 19 | 
            +
                  super(attrs)
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              module Lookups
         | 
| 24 | 
            +
                def fetch(*)
         | 
| 25 | 
            +
                  TwilioMock::LookupMocker.new.lookup(@solution[:phone_number]) if TwilioMock::Testing.enabled?
         | 
| 26 | 
            +
                  super
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
            end
         | 
    
        data/lib/twilio_mock/mocker.rb
    CHANGED
    
    | @@ -2,11 +2,10 @@ require 'twilio-ruby' | |
| 2 2 | 
             
            require 'webmock'
         | 
| 3 3 | 
             
            require_relative 'number_generator'
         | 
| 4 4 | 
             
            require 'ostruct'
         | 
| 5 | 
            +
            require_relative 'twilify'
         | 
| 5 6 |  | 
| 6 7 | 
             
            module TwilioMock
         | 
| 7 8 | 
             
              class Mocker
         | 
| 8 | 
            -
                include Twilio::REST::Utils
         | 
| 9 | 
            -
             | 
| 10 9 | 
             
                API_VERSION = '2010-04-01'.freeze
         | 
| 11 10 | 
             
                HOST = 'api.twilio.com'.freeze
         | 
| 12 11 |  | 
| @@ -21,9 +20,9 @@ module TwilioMock | |
| 21 20 | 
             
                end
         | 
| 22 21 |  | 
| 23 22 | 
             
                def available_number(number = nil, params = nil)
         | 
| 24 | 
            -
                  query_string = params && params.any? ?  | 
| 23 | 
            +
                  query_string = params && params.any? ? Twilify.process(params).to_h.to_query : ''
         | 
| 25 24 | 
             
                  stub_request(:get, "#{base_twilio_url}/AvailablePhoneNumbers/US/Local.json?#{query_string}")
         | 
| 26 | 
            -
                    .with( | 
| 25 | 
            +
                    .with(basic_auth: basic_auth)
         | 
| 27 26 | 
             
                    .to_return(status: 200, body: available_number_response(number), headers: {})
         | 
| 28 27 | 
             
                end
         | 
| 29 28 |  | 
| @@ -48,10 +47,6 @@ module TwilioMock | |
| 48 47 | 
             
                  }.to_json
         | 
| 49 48 | 
             
                end
         | 
| 50 49 |  | 
| 51 | 
            -
                def headers
         | 
| 52 | 
            -
                  Twilio::REST::Client::HTTP_HEADERS
         | 
| 53 | 
            -
                end
         | 
| 54 | 
            -
             | 
| 55 50 | 
             
                def basic_auth
         | 
| 56 51 | 
             
                  [@username, @token]
         | 
| 57 52 | 
             
                end
         | 
| @@ -65,9 +60,9 @@ module TwilioMock | |
| 65 60 | 
             
                end
         | 
| 66 61 |  | 
| 67 62 | 
             
                def prepare_stub(attrs, path)
         | 
| 68 | 
            -
                  body =  | 
| 63 | 
            +
                  body = Twilify.process(attrs).map { |k, val| [k, val.to_s] }.to_h
         | 
| 69 64 | 
             
                  stub_request(:post, "#{base_twilio_url}/#{path}")
         | 
| 70 | 
            -
                    .with(body: body,  | 
| 65 | 
            +
                    .with(body: body, basic_auth: basic_auth)
         | 
| 71 66 | 
             
                    .to_return(status: 200, body: response, headers: {})
         | 
| 72 67 | 
             
                end
         | 
| 73 68 |  | 
| @@ -75,7 +70,10 @@ module TwilioMock | |
| 75 70 | 
             
                  number ||= number_generator.generate
         | 
| 76 71 | 
             
                  {
         | 
| 77 72 | 
             
                    sid: @username,
         | 
| 78 | 
            -
                    available_phone_numbers: [{ ' | 
| 73 | 
            +
                    available_phone_numbers: [{ 'phone_number' => number }],
         | 
| 74 | 
            +
                    meta: {
         | 
| 75 | 
            +
                      key: 'available_phone_numbers'
         | 
| 76 | 
            +
                    }
         | 
| 79 77 | 
             
                  }.to_json
         | 
| 80 78 | 
             
                end
         | 
| 81 79 |  | 
| @@ -0,0 +1,17 @@ | |
| 1 | 
            +
            module Twilify
         | 
| 2 | 
            +
              module_function
         | 
| 3 | 
            +
             | 
| 4 | 
            +
              # extracted from the deprecated Twilio::REST::Utils
         | 
| 5 | 
            +
              def process(something)
         | 
| 6 | 
            +
                if something.is_a? Hash
         | 
| 7 | 
            +
                  something = something.to_a
         | 
| 8 | 
            +
                  something = something.map { |pair| [process(pair[0]).to_sym, pair[1]] }
         | 
| 9 | 
            +
                  something = something.flatten(1)
         | 
| 10 | 
            +
                  Hash[*something]
         | 
| 11 | 
            +
                else
         | 
| 12 | 
            +
                  something.to_s.split('_').map! do |s|
         | 
| 13 | 
            +
                    [s[0,1].capitalize, s[1..-1]].join
         | 
| 14 | 
            +
                  end.join
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
            end
         | 
    
        data/lib/twilio_mock.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: twilio_mock
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.4.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Maicol Bentancor
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2017-10- | 
| 11 | 
            +
            date: 2017-10-09 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: twilio-ruby
         | 
| @@ -16,20 +16,20 @@ dependencies: | |
| 16 16 | 
             
                requirements:
         | 
| 17 17 | 
             
                - - "~>"
         | 
| 18 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            -
                    version:  | 
| 19 | 
            +
                    version: 5.2.3
         | 
| 20 20 | 
             
                - - ">="
         | 
| 21 21 | 
             
                  - !ruby/object:Gem::Version
         | 
| 22 | 
            -
                    version: ' | 
| 22 | 
            +
                    version: '5'
         | 
| 23 23 | 
             
              type: :runtime
         | 
| 24 24 | 
             
              prerelease: false
         | 
| 25 25 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 26 26 | 
             
                requirements:
         | 
| 27 27 | 
             
                - - "~>"
         | 
| 28 28 | 
             
                  - !ruby/object:Gem::Version
         | 
| 29 | 
            -
                    version:  | 
| 29 | 
            +
                    version: 5.2.3
         | 
| 30 30 | 
             
                - - ">="
         | 
| 31 31 | 
             
                  - !ruby/object:Gem::Version
         | 
| 32 | 
            -
                    version: ' | 
| 32 | 
            +
                    version: '5'
         | 
| 33 33 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 34 34 | 
             
              name: webmock
         | 
| 35 35 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -57,12 +57,14 @@ extensions: [] | |
| 57 57 | 
             
            extra_rdoc_files: []
         | 
| 58 58 | 
             
            files:
         | 
| 59 59 | 
             
            - lib/rest.rb
         | 
| 60 | 
            +
            - lib/twilio_extensions.rb
         | 
| 60 61 | 
             
            - lib/twilio_mock.rb
         | 
| 61 62 | 
             
            - lib/twilio_mock/lookup_mocker.rb
         | 
| 62 63 | 
             
            - lib/twilio_mock/messages_queue.rb
         | 
| 63 64 | 
             
            - lib/twilio_mock/mocker.rb
         | 
| 64 65 | 
             
            - lib/twilio_mock/number_generator.rb
         | 
| 65 66 | 
             
            - lib/twilio_mock/testing.rb
         | 
| 67 | 
            +
            - lib/twilio_mock/twilify.rb
         | 
| 66 68 | 
             
            homepage: 
         | 
| 67 69 | 
             
            licenses:
         | 
| 68 70 | 
             
            - MIT
         |