lib/moysklad/client.rb in moysklad-0.3.0 vs lib/moysklad/client.rb in moysklad-0.3.1

- old
+ new

@@ -6,12 +6,13 @@ # URL = 'https://online.moysklad.ru' URL ='https://online.moysklad.ru/api/remap/1.1/' def initialize login: nil, password: nil - @client = Faraday.new URL - @client.basic_auth login, password + @client = Faraday.new URL do |conn| + conn.request(:authorization, :basic, login, password) + end end def download(path, filename) response = client.get path File.open(filename, 'wb') { |fp| fp.write(response.body) } @@ -26,11 +27,10 @@ logger.debug "Client: POST #{path}" result = client.post do |req| req.url path req.headers['Content-Type'] = 'application/json' req.headers['Accept'] = '*/*' - puts data req.body = data end parse_response result end @@ -62,11 +62,12 @@ def logger Moysklad.logger end def parse_response res + Moysklad.logger.debug "Response [#{res.status}]: #{res.body}" + if res.status == 200 - Moysklad.logger.info "Response: #{res.body}" return if res.body.blank? JSON.parse res.body else Moysklad::Client::Errors.build res end