lib/moysklad/client.rb in moysklad-0.3.4 vs lib/moysklad/client.rb in moysklad-0.4.0
- old
+ new
@@ -1,16 +1,22 @@
require 'faraday'
+require 'faraday/detailed_logger'
+require 'faraday_curl'
require_relative 'client/errors'
class Moysklad::Client
+ URL ='https://api.moysklad.ru/api/remap/1.2/'
- # URL = 'https://online.moysklad.ru'
- URL ='https://online.moysklad.ru/api/remap/1.1/'
-
- def initialize login: nil, password: nil
+ def initialize login: nil, password: nil, logger: nil
@client = Faraday.new URL do |conn|
+ unless logger.nil?
+ binding.pry
+ conn.response :detailed_logger, logger
+ conn.request :curl, logger, :info
+ end
+
conn.options.timeout = ENV.fetch('MOYSKLAD_HTTP_TIMEOUT', 120)
if Faraday::VERSION.split('.').first.to_i < 2
conn.request(:basic_auth, login, password)
else
conn.request(:authorization, :basic, login, password)
@@ -32,10 +38,11 @@
logger.debug "Client: POST #{path}"
result = client.post do |req|
req.url path
req.headers['Content-Type'] = 'application/json'
req.headers['Accept'] = '*/*'
+ req.headers['Accept-Encoding'] = 'gzip'
req.body = data
end
parse_response result
end
@@ -43,10 +50,11 @@
logger.debug "Client: PUT #{path}"
result = client.put do |req|
req.url path
req.headers['Content-Type'] = 'application/json'
req.headers['Accept'] = '*/*'
+ req.headers['Accept-Encoding'] = 'gzip'
req.body = data
end
parse_response result
end
@@ -54,9 +62,10 @@
logger.debug "Client: DELETE #{path}"
result = client.delete do |req|
req.url path
req.headers['Content-Type'] = 'application/json'
req.headers['Accept'] = '*/*'
+ req.headers['Accept-Encoding'] = 'gzip'
end
parse_response result
end
private