lib/totter/client.rb in totter-0.4.0 vs lib/totter/client.rb in totter-0.4.1

- old
+ new

@@ -1,6 +1,7 @@ require 'totter/transport' +require 'uri' module Totter # API client for interacting with the Seesaw API class Client Dir[File.expand_path('../client/*.rb', __FILE__)].each { |f| require f } @@ -48,13 +49,20 @@ yield options end # Initialize a new client. # - # @param options [Hash] optionally specify `:access_token`, `:api_scheme`, `:api_host`, `:api_version`, `:client_token`, or `:transport`. + # @param options [Hash] optionally specify `:access_token`, `:api_scheme`, `:api_host`, ':api_url', `:api_version`, `:client_token`, or `:transport`. def initialize(options = {}) options = { :access_token => options } if options.is_a? String options = self.class.options.merge(options) + + # Parse `api_url` option + if url = options.delete(:api_url) + uri = URI.parse(url) + options[:api_scheme] = uri.scheme + options[:api_host] = uri.host + (uri.port != 80 && uri.port != 443 ? ":#{uri.port}" : '') + end @access_token = options[:access_token] if options[:access_token] @api_scheme = options[:api_scheme] @api_host = options[:api_host] @api_version = options[:api_version]