class AmoCRM::Client
Constants
- PREFIX_PATH
- SESSION_TIMEOUT
Attributes
connection[R]
Public Class Methods
new(url: @connection = Faraday.new url)
click to toggle source
# File lib/amo_crm/client.rb, line 12 def initialize url: @connection = Faraday.new url # 'private/api/v2/json/' # connection.use :cookie_jar # connection.response :logger connection.request :url_encoded end
Public Instance Methods
delete(path)
click to toggle source
# File lib/amo_crm/client.rb, line 66 def delete path check_authorization! validate connection.delete PREFIX_PATH path end
get(path, params={})
click to toggle source
# File lib/amo_crm/client.rb, line 46 def get path, params={} logger.debug "Client: GET #{path} #{params}" check_authorization! validate connection.get PREFIX_PATH + path, params, { Cookie: cookie } end
post(path, data=nil)
click to toggle source
# File lib/amo_crm/client.rb, line 52 def post path, data=nil data = JSON.generate data.as_json logger.debug "Client: POST #{path}: #{data}" check_authorization! validate connection.post PREFIX_PATH + path, data, { 'Content-Type' => 'application/json', Cookie: cookie } end
put(path, data)
click to toggle source
# File lib/amo_crm/client.rb, line 59 def put path, data data = JSON.generate data.as_json logger.debug "Client: PUT #{path}: #{data}" check_authorization! validate connection.put PREFIX_PATH + path, data, { 'Content-Type' => 'application/json', Cookie: cookie } end
Private Instance Methods
logger()
click to toggle source
# File lib/amo_crm/client.rb, line 88 def logger AmoCRM.logger end
session_expired?()
click to toggle source
# File lib/amo_crm/client.rb, line 84 def session_expired? return !cookie || !@authorized_at || @authorized_at + SESSION_TIMEOUT <= Time.zone.now end
validate(res)
click to toggle source
# File lib/amo_crm/client.rb, line 92 def validate res AmoCRM::Client::Errors.build res unless res.status == 200 data = JSON.parse(res.body)['response'] Hashie::Mash.new data end