Sha256: a1dea844445d4cc93b0c5680c06ebfe2b6041fa6e869de2d088fd8db727d0a30
Contents?: true
Size: 1.3 KB
Versions: 1
Compression:
Stored size: 1.3 KB
Contents
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 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? end def post(path, params = {} ) request(:post, path, params) end private def connection(options = {} ) @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 conn.response :parse_json end 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) rescue Faraday::Error::TimeoutError, Timeout::Error => error raise(Terminal::APITimeoutError.new(error)) end def auth_params params = {} params[:access_token] = access_token params[:user_token] = user_token params end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cc-terminal-0.1.2 | lib/terminal/client.rb |