##
# This code was generated by
# \ / _    _  _|   _  _
#  | (_)\/(_)(_|\/| |(/_  v1.0.0
#       /       /       

module Twilio
  module REST
    ##
    # A client for accessing the Twilio API.
    class Client
      attr_accessor :http_client, :account_sid, :auth_token
      
      ##
      # Initializes the Twilio Client
      def initialize(account_sid, auth_token, http_client=Twilio::HTTP::Client.new)
        @account_sid = account_sid
        @auth_token = auth_token
        @auth = [@account_sid, @auth_token]
        @http_client = http_client
        
        # Domains
        @api = nil
        @ip_messaging = nil
        @lookups = nil
        @monitor = nil
        @notifications = nil
        @preview = nil
        @pricing = nil
        @taskrouter = nil
        @trunking = nil
      end
      
      ##
      # Makes a request to the Twilio API using the configured http client
      # Authentication information is automatically added if none is provided
      def request(host, port, method, uri, params={}, data={}, headers={}, auth=nil, timeout=nil)
        auth ||= @auth
        
        headers['User-Agent'] = "twilio-ruby/#{Twilio::VERSION}" +
                                " (#{RUBY_ENGINE}/#{RUBY_PLATFORM}" +
                                " #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL})"
        headers['Accept-Charset'] = 'utf-8'
        
        if method == 'POST' && !headers['Content-Type']
          headers['Content-Type'] = 'application/x-www-form-urlencoded'
        end
        
        unless headers['Accept']
          headers['Accept'] = 'application/json'
        end
        
        @http_client.request(
          host,
          port,
          method,
          uri,
          params,
          data,
          headers,
          auth,
          timeout
        )
      end
      
      ##
      # Access the Api Twilio Domain
      def api
        @api ||= Api.new self
      end
      
      ##
      # Access the IpMessaging Twilio Domain
      def ip_messaging
        @ip_messaging ||= IpMessaging.new self
      end
      
      ##
      # Access the Lookups Twilio Domain
      def lookups
        @lookups ||= Lookups.new self
      end
      
      ##
      # Access the Monitor Twilio Domain
      def monitor
        @monitor ||= Monitor.new self
      end
      
      ##
      # Access the Notifications Twilio Domain
      def notifications
        @notifications ||= Notifications.new self
      end
      
      ##
      # Access the Preview Twilio Domain
      def preview
        @preview ||= Preview.new self
      end
      
      ##
      # Access the Pricing Twilio Domain
      def pricing
        @pricing ||= Pricing.new self
      end
      
      ##
      # Access the Taskrouter Twilio Domain
      def taskrouter
        @taskrouter ||= Taskrouter.new self
      end
      
      ##
      # Access the Trunking Twilio Domain
      def trunking
        @trunking ||= Trunking.new self
      end
      
      def account
        return self.api.v2010.account
      end
      
      def accounts
        return self.api.v2010.accounts
      end
      
      def addresses
        return self.account.addresses
      end
      
      def applications
        return self.account.applications
      end
      
      def authorized_connect_apps
        return self.account.authorized_connect_apps
      end
      
      def available_phone_numbers
        return self.account.available_phone_numbers
      end
      
      def calls
        return self.account.calls
      end
      
      def conferences
        return self.account.conferences
      end
      
      def connect_apps
        return self.account.connect_apps
      end
      
      def incoming_phone_numbers
        return self.account.incoming_phone_numbers
      end
      
      def messages
        return self.account.messages
      end
      
      def outgoing_caller_ids
        return self.account.outgoing_caller_ids
      end
      
      def queues
        return self.account.queues
      end
      
      def recordings
        return self.account.recordings
      end
      
      def sandbox
        return self.account.sandbox
      end
      
      def sip
        return self.account.sip
      end
      
      def sms
        return self.account.sms
      end
      
      def tokens
        return self.account.tokens
      end
      
      def transcriptions
        return self.account.transcriptions
      end
      
      def usage
        return self.account.usage
      end
      
      def validation_requests
        return self.account.validation_requests
      end
      
      ##
      # Provide a user friendly representation
      def to_s
        "#<Twilio::REST::Client #{@account_sid}>"
      end
    end
  end
end