Skip to content

Commit

Permalink
Merge remote-tracking branch 'github-private/lookups'
Browse files Browse the repository at this point in the history
  • Loading branch information
skimbrel committed Mar 31, 2015
2 parents 134154e + b17b4f5 commit 9728242
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/twilio-ruby.rb
Expand Up @@ -49,6 +49,7 @@
require 'twilio-ruby/rest/task_router/workflows'
require 'twilio-ruby/rest/task_router/workspaces'
require 'twilio-ruby/rest/task_router/workspace_statistics'
require 'twilio-ruby/rest/lookups/phone_numbers'
require 'twilio-ruby/rest/media'
require 'twilio-ruby/rest/messages'
require 'twilio-ruby/rest/applications'
Expand Down Expand Up @@ -79,6 +80,7 @@
require 'twilio-ruby/rest/addresses/dependent_phone_numbers'
require 'twilio-ruby/rest/client'
require 'twilio-ruby/rest/task_router_client'
require 'twilio-ruby/rest/lookups_client'
require 'rack/twilio_webhook_authentication'

module Twilio
Expand Down
8 changes: 8 additions & 0 deletions lib/twilio-ruby/rest/lookups/phone_numbers.rb
@@ -0,0 +1,8 @@
module Twilio
module REST
module Lookups
class PhoneNumbers < Twilio::REST::NextGenListResource; end
class PhoneNumber < InstanceResource; end
end
end
end
117 changes: 117 additions & 0 deletions lib/twilio-ruby/rest/lookups_client.rb
@@ -0,0 +1,117 @@
require 'twilio-ruby/rest/base_client'
module Twilio
module REST
class LookupsClient < BaseClient
API_VERSION = 'v1'

DEFAULTS = {
host: 'lookups.twilio.com',
port: 443,
use_ssl: true,
ssl_verify_peer: true,
ssl_ca_file: File.dirname(__FILE__) + '/../../../conf/cacert.pem',
timeout: 30,
proxy_addr: nil,
proxy_port: nil,
proxy_user: nil,
proxy_pass: nil,
retry_limit: 1
}

attr_reader :phone_numbers

##
# Instantiate a new HTTP Lookups client to talk to Twilio. The parameters
# +account_sid+, +auth_token+ and +workspace_sid are required, unless you
# have configured them already using the block configure syntax, and used
# to generate the HTTP basic auth header in each request. The +options+
# parameter is a hash of connection configuration options. the following
# keys are supported:
#
# === <tt>host: 'lookups.twilio.com'</tt>
#
# The domain to which you'd like the client to make HTTP requests. Useful
# for testing. Defaults to 'lookups.twilio.com'.
#
# === <tt>port: 443</tt>
#
# The port on which to connect to the above domain. Defaults to 443 and
# should be left that way except in testing environments.
#
# === <tt>use_ssl: true</tt>
#
# Declare whether ssl should be used for connections to the above domain.
# Defaults to true and should be left alone except when testing.
#
# === <tt>ssl_verify_peer: true</tt>
#
# Declare whether to verify the host's ssl cert when setting up the
# connection to the above domain. Defaults to true, but can be turned off
# to avoid ssl certificate verification failures in environments without
# the necessary ca certificates.
#
# === <tt>ssl_ca_file: '/path/to/ca/file'</tt>
#
# Specify the path to the certificate authority bundle you'd like to use
# to verify Twilio's SSL certificate on each request. If not specified, a
# certificate bundle extraced from Firefox is packaged with the gem and
# used by default.
#
# === <tt>timeout: 30</tt>
#
# Set the time in seconds to wait before timing out the HTTP request.
# Defaults to 30 seconds. If you aren't fetching giant pages of call or
# SMS logs you can safely decrease this to something like 3 seconds or
# lower. In paricular if you are sending SMS you can set this to 1 second
# or less and swallow the exception if you don't care about the response.
#
# === <tt>proxy_addr: 'proxy.host.domain'</tt>
#
# The domain of a proxy through which you'd like the client to make HTTP
# requests. Defaults to nil.
#
# === <tt>proxy_port: 3128</tt>
#
# The port on which to connect to the above proxy. Defaults to nil.
#
# === <tt>proxy_user: 'username'</tt>
#
# The user name to use for authentication with the proxy. Defaults to nil.
#
# === <tt>proxy_pass: 'password'</tt>
#
# The password to use for authentication with the proxy. Defaults to nil.
#
# === <tt>retry_limit: 1</tt>
#
# The number of times to retry a request that has failed before throwing
# an exception. Defaults to one.
def inspect # :nodoc:
"<Twilio::REST::LookupsClient @account_sid=#{@account_sid}>"
end

protected

##
# Get the default config values.
def get_defaults
DEFAULTS
end

##
# Set up +phone_numbers+ attribute.
def set_up_subresources # :doc:
@phone_numbers = Twilio::REST::Lookups::PhoneNumbers.new "/#{API_VERSION}/PhoneNumbers", self
end

##
# Builds up full request path
def build_full_path(path, params, method)
path = path.dup
path << "?#{url_encode(params)}" if method == :get && !params.empty?
path
end

end
end
end
8 changes: 8 additions & 0 deletions spec/rest/lookups/phone_number_spec.rb
@@ -0,0 +1,8 @@
require 'spec_helper'

describe Twilio::REST::Lookups::PhoneNumbers do
it 'creates a phone_number object' do
client = Twilio::REST::LookupsClient.new 'otherSid', 'otherToken'
expect(client).to respond_to(:phone_numbers)
end
end

0 comments on commit 9728242

Please sign in to comment.