require 'totter/transport' module Totter # API client for interacting with the Seesaw API class Client Dir[File.expand_path('../client/*.rb', __FILE__)].each { |f| require f } include Totter::Client::Avatars include Totter::Client::Choices include Totter::Client::Comments include Totter::Client::Configuration include Totter::Client::Decisions include Totter::Client::Slugs include Totter::Client::Stickers include Totter::Client::Timelines include Totter::Client::Users include Totter::Client::Votes attr_reader :access_token attr_reader :api_scheme attr_reader :api_host attr_reader :api_version attr_reader :transport # global stubbing toggle for use in tests @@stubbed = false # Initialize a new client. # # @param options [Hash] optionally specify `:access_token`, `:api_scheme`, `:api_host`, `:api_version`, `:client_token`, or `:transport`. def initialize(options = {}) options = { access_token: options } if options.is_a? String @access_token = options[:access_token] if options[:access_token] @api_scheme = (options[:api_scheme] or 'https') @api_host = (options[:api_host] or 'api.seesaw.co') @api_version = (options[:api_version] or 1) @client_token = options[:client_token] if options[:client_token] @transport = (options[:transport] or :http) # Include transport transport_module = Totter::Transport::TRANSPORT_MAP[@transport] raise 'Invalid transport' unless transport_module self.extend transport_module end # API base URL. # # @return [String] API base URL def base_url "#{@api_scheme}://#{@api_host}/v#{@api_version}/" end # Is the client has an access token. # # @return [Boolean] true if it is using one and false if it is not def authenticated? @access_token != nil and @access_token.length > 0 end # Is the client using SSL. # # @return [Boolean] true if it is using SSL and false if it is not def ssl? @api_scheme == 'https' end def self.stub! @@stubbed = true end def self.unstub! @@stubbed = false end def self.stubbed? @@stubbed end end end