Class: Moysklad::Client
- Inherits:
-
Object
show all
- Defined in:
- lib/moysklad/client.rb,
lib/moysklad/client/errors.rb,
lib/moysklad/client/errors.rb
Defined Under Namespace
Classes: BadGatewayError, Error, Errors, HtmlParsedError, InternalServerError, JsonParsedError, MethodNotAllowedError, NoResourceFound, ParsedError, ParsingError, ResourceForbidden, UnauthorizedError, UnknownError
Constant Summary
collapse
- URL =
'https://online.moysklad.ru/api/remap/1.1/'
Instance Method Summary
collapse
Constructor Details
#initialize(login: nil, password: nil) ⇒ Client
Returns a new instance of Client.
10
11
12
13
|
# File 'lib/moysklad/client.rb', line 10
def initialize login: nil, password: nil
@client = Faraday.new URL
@client.basic_auth login, password
end
|
Instance Method Details
#delete(path) ⇒ Object
48
49
50
51
52
53
54
55
56
|
# File 'lib/moysklad/client.rb', line 48
def delete path
logger.debug "Client: DELETE #{path}"
result = client.delete do |req|
req.url path
req.['Content-Type'] = 'application/json'
req.['Accept'] = '*/*'
end
parse_response result
end
|
#download(path, filename) ⇒ Object
15
16
17
18
|
# File 'lib/moysklad/client.rb', line 15
def download(path, filename)
response = client.get path
File.open(filename, 'wb') { |fp| fp.write(response.body) }
end
|
#get(path, params = {}) ⇒ Object
20
21
22
23
|
# File 'lib/moysklad/client.rb', line 20
def get path, params={}
logger.debug "Client: GET #{path} #{params}"
parse_response client.get path, params
end
|
#post(path, data) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/moysklad/client.rb', line 25
def post path, data
logger.debug "Client: POST #{path}"
result = client.post do |req|
req.url path
req.['Content-Type'] = 'application/json'
req.['Accept'] = '*/*'
puts data
req.body = data
end
parse_response result
end
|
#put(path, data) ⇒ Object
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/moysklad/client.rb', line 37
def put path, data
logger.debug "Client: PUT #{path}"
result = client.put do |req|
req.url path
req.['Content-Type'] = 'application/json'
req.['Accept'] = '*/*'
req.body = data
end
parse_response result
end
|