class Trell::Client
Constants
- CONVENIENCE_HEADERS
Public Class Methods
new(options = {})
click to toggle source
# File lib/trell/client.rb, line 26 def initialize(options = {}) Trell::Configurable.keys.each do |key| instance_variable_set(:"@#{key}", options[key] || Trell.instance_variable_get(:"@#{key}")) end end
Public Instance Methods
agent()
click to toggle source
# File lib/trell/client.rb, line 60 def agent @agent ||= Sawyer::Agent.new(api_endpoint, sawyer_options) do |http| http.headers[:accept] = media_type http.headers[:content_type] = media_type http.headers[:user_agent] = user_agent if basic_authenticated? http.basic_auth(@login, @password) elsif token_authenticated? http.authorization 'token', @access_token end end end
delete(url, options = {})
click to toggle source
# File lib/trell/client.rb, line 52 def delete(url, options = {}) request :delete, url, options end
get(url, options = {})
click to toggle source
# File lib/trell/client.rb, line 36 def get(url, options = {}) request :get, url, parse_query_and_convenience_headers(options) end
head(url, options = {})
click to toggle source
# File lib/trell/client.rb, line 56 def head(url, options = {}) request :head, url, parse_query_and_convenience_headers(options) end
patch(url, options = {})
click to toggle source
# File lib/trell/client.rb, line 48 def patch(url, options = {}) request :patch, url, options end
post(url, options = {})
click to toggle source
# File lib/trell/client.rb, line 40 def post(url, options = {}) request :post, url, options end
put(url, options = {})
click to toggle source
# File lib/trell/client.rb, line 44 def put(url, options = {}) request :put, url, options end
same_options?(opts)
click to toggle source
# File lib/trell/client.rb, line 32 def same_options?(opts) opts.hash == options.hash end
Private Instance Methods
boolean_from_response(method, path, options = {})
click to toggle source
# File lib/trell/client.rb, line 93 def boolean_from_response(method, path, options = {}) request(method, path, options) @last_response.status == 204 rescue Trell::NotFound false end
parse_query_and_convenience_headers(options)
click to toggle source
# File lib/trell/client.rb, line 112 def parse_query_and_convenience_headers(options) headers = options.fetch(:headers, {}) CONVENIENCE_HEADERS.each do |h| if header = options.delete(h) headers[h] = header end end query = options.delete(:query) opts = {:query => options} opts[:query].merge!(query) if query && query.is_a?(Hash) opts[:headers] = headers unless headers.empty? opts end
request(method, path, data, options = {})
click to toggle source
# File lib/trell/client.rb, line 76 def request(method, path, data, options = {}) if data.is_a?(Hash) options[:query] = data.delete(:query) || {} options[:headers] = data.delete(:headers) || {} if accept = data.delete(:accept) options[:headers][:accept] = accept end end if application_authenticated? options[:query].merge! application_authentication end @last_response = response = agent.call(method, URI::Parser.new.escape(path.to_s), data, options) response.data end
sawyer_options()
click to toggle source
# File lib/trell/client.rb, line 100 def sawyer_options opts = { :links_parser => Sawyer::LinkParsers::Simple.new } conn_opts = @connection_options conn_opts[:builder] = @middleware if @middleware conn_opts[:proxy] = @proxy if @proxy opts[:faraday] = Faraday.new(conn_opts) opts end