lib/terminal/client.rb in cc-terminal-0.1.2 vs lib/terminal/client.rb in cc-terminal-0.1.4

- old
+ new

@@ -2,33 +2,33 @@ module Terminal class Client include Terminal::API API_VERSION = "v0.1" - API_URL = 'https://api.terminal.com' - API_PREFIX = API_URL + "/" + API_VERSION + "/" - attr_accessor :user_token, :access_token + attr_accessor :user_token, :access_token, :api_url, :api_prefix - def initialize( options = {}) + def initialize(options = {}) options.each do | k, v | if v.is_a?(Integer) raise Terminal::APIConfigurationError end send(:"#{k}=", v) end yield(self) if block_given? + + @api_prefix = options[:api_url] + "/" + API_VERSION + "/" end def post(path, params = {} ) request(:post, path, params) end private def connection(options = {} ) - @connection ||= Faraday.new(API_URL, options) do | conn | + @connection ||= Faraday.new(@api_url, options) do | conn | conn.request :encode_json conn.adapter :net_http # This ordering is important don't change conn.response :raise_error_from_json @@ -38,10 +38,10 @@ end def request(method, path, params = {}) auth = params.delete(:auth) params = params.merge(auth_params) if auth - connection.send(method.to_sym, API_PREFIX + path, params) + connection.send(method.to_sym, @api_prefix + path, params) rescue Faraday::Error::TimeoutError, Timeout::Error => error raise(Terminal::APITimeoutError.new(error)) end def auth_params