Class: Twilio::REST::BaseClient
- Inherits:
-
Object
- Object
- Twilio::REST::BaseClient
- Defined in:
- lib/twilio-ruby/rest/base_client.rb
Direct Known Subclasses
Client, LookupsClient, MonitorClient, PricingClient, TaskRouterClient
Constant Summary collapse
- HTTP_HEADERS =
{ 'Accept' => 'application/json', 'Accept-Charset' => 'utf-8', 'User-Agent' => "twilio-ruby/#{Twilio::VERSION}" \ " (#{RUBY_ENGINE}/#{RUBY_PLATFORM}" \ " #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL})" }
Instance Attribute Summary collapse
-
#account_sid ⇒ Object
readonly
Returns the value of attribute account_sid.
-
#last_request ⇒ Object
readonly
Returns the value of attribute last_request.
-
#last_response ⇒ Object
readonly
Returns the value of attribute last_response.
Class Method Summary collapse
-
.host(host = nil) ⇒ Object
Override the default host for a REST Client (api.twilio.com).
Instance Method Summary collapse
-
#initialize(*args) ⇒ BaseClient
constructor
A new instance of BaseClient.
-
#method ⇒ Object
Define #get, #put, #post and #delete helper methods for sending HTTP requests to Twilio.
Methods included from Utils
Methods included from Util
Constructor Details
#initialize(*args) ⇒ BaseClient
Returns a new instance of BaseClient.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/twilio-ruby/rest/base_client.rb', line 24 def initialize(*args) = args.last.is_a?(Hash) ? args.pop : {} [:host] ||= self.class.host @config = Twilio::Util::ClientConfig.new @account_sid = args[0] || Twilio.account_sid @auth_token = args[1] || Twilio.auth_token if @account_sid.nil? || @auth_token.nil? raise ArgumentError, 'Account SID and auth token are required' end set_up_connection set_up_subresources end |
Instance Attribute Details
#account_sid ⇒ Object (readonly)
Returns the value of attribute account_sid.
22 23 24 |
# File 'lib/twilio-ruby/rest/base_client.rb', line 22 def account_sid @account_sid end |
#last_request ⇒ Object (readonly)
Returns the value of attribute last_request.
22 23 24 |
# File 'lib/twilio-ruby/rest/base_client.rb', line 22 def last_request @last_request end |
#last_response ⇒ Object (readonly)
Returns the value of attribute last_response.
22 23 24 |
# File 'lib/twilio-ruby/rest/base_client.rb', line 22 def last_response @last_response end |
Class Method Details
.host(host = nil) ⇒ Object
Override the default host for a REST Client (api.twilio.com)
17 18 19 20 |
# File 'lib/twilio-ruby/rest/base_client.rb', line 17 def self.host(host=nil) return @host unless host @host = host end |
Instance Method Details
#method ⇒ Object
Define #get, #put, #post and #delete helper methods for sending HTTP requests to Twilio. You shouldn’t need to use these methods directly, but they can be useful for debugging. Each method returns a hash obtained from parsing the JSON object in the response body.
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/twilio-ruby/rest/base_client.rb', line 44 [:get, :put, :post, :delete].each do |method| method_class = Net::HTTP.const_get method.to_s.capitalize define_method method do |path, *args| params = twilify(args[0]) params = {} if params.empty? # build the full path unless already given path = build_full_path(path, params, method) unless args[1] request = method_class.new(path, HTTP_HEADERS) request.basic_auth(@account_sid, @auth_token) request.form_data = params if [:post, :put].include?(method) connect_and_send(request) end end |