class Closeio::Client
Attributes
Public Class Methods
Source
# File lib/closeio/client.rb, line 37 def initialize(api_key, logger = true, ca_file = nil, errors = false, utc_offset: 0) @api_key = api_key @logger = logger @ca_file = ca_file @errors = errors @utc_offset = utc_offset end
Public Instance Methods
Source
# File lib/closeio/client.rb, line 60 def delete(path, options = {}) connection.delete(path, options).body end
Source
# File lib/closeio/client.rb, line 45 def get(path, options = {}) connection.get(path, options).body end
Source
# File lib/closeio/client.rb, line 64 def paginate(path, options = {}) results = [] skip = 0 begin res = get(path, options.merge!(_skip: skip)) unless res['data'].nil? || res['data'].empty? results.push res['data'] skip += res['data'].count end end while res['has_more'] { has_more: false, total_results: res['total_results'], data: results.flatten } end
Source
# File lib/closeio/client.rb, line 49 def post(path, req_body) connection.post do |req| req.url(path) req.body = req_body end.body end
Source
# File lib/closeio/client.rb, line 56 def put(path, options = {}) connection.put(path, options).body end
Private Instance Methods
Source
# File lib/closeio/client.rb, line 80 def assemble_list_query(query, options) options[:query] = if query.respond_to? :map query.map { |k, v| "#{k}:\"#{v}\"" }.join(' ') else query end options end
Source
# File lib/closeio/client.rb, line 90 def connection Faraday.new( url: 'https://api.close.com/api/v1', headers: { accept: 'application/json', 'User-Agent' => "closeio-ruby-gem/v#{Closeio::VERSION}", 'X-TZ-Offset' => utc_offset.to_s }, ssl: { ca_file: ca_file } ) do |conn| conn.request :authorization, :basic, api_key, '' conn.request :json conn.response :logger if logger conn.response :json conn.use FaradayMiddleware::CloseioErrorHandler if errors conn.adapter Faraday.default_adapter end end