retailcrm-api 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2712dc46e40f6b40a8b1e575fb265e6b916f032fa030a633bf7ec465fdcc55ed
4
- data.tar.gz: d5b8cbf0ebd40ee9fe2590351eb697aa2016b21cdb7f6220333f278e9d6d0bdb
3
+ metadata.gz: 19aca33fa8aabb3a4cd9acffaa7ed004cbd8be0a126ddb8f4c93b162fb60c50a
4
+ data.tar.gz: ea0d5c405d9c6073044a028eea147c207a0bc7ccbb784b02ddd6d6b108e40661
5
5
  SHA512:
6
- metadata.gz: 8a59a99080cfd637d0416e4c0185cca4e74c042df59486b01bcfa4fcbb8489361c9da4ba3a27f9b3b99debe0f225f459634212105927c8346d0da407ac304b77
7
- data.tar.gz: c097801cf4d5c919fd5f760751f9cbc70183ba356a5c0ffc995e2f6eebf3328679aa17c926f87ed66f58f0cf0817d32a03b2bc29ee7f3629c322ff61d296ec04
6
+ metadata.gz: a10e4ac6b8700f48597a3585a9a0cf5ef2aa646fedddec463fa02c7573f4c1b877335e2bbf6d8e99a76ae10675b4a0c00f858f050d924689774f732f9e45d3f8
7
+ data.tar.gz: 953ae085065c09ab797cef8bdd66cc4465500e43617d8ff1816305ec54755e63f2b47a55a2629eab5fca597d4ad3c200f07bbb2113d9b1418b8514b6ed296568
data/README.markdown CHANGED
@@ -70,15 +70,100 @@ RetailcrmApi::Request.logger = MyLogger.new
70
70
 
71
71
  ### [Получение списка расходов, удовлетворяющих заданному фильтру](https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#get--api-v5-costs)
72
72
  ```ruby
73
- RetailcrmApi::Request.costs.retrieve.body
73
+ params = {
74
+ filter: {
75
+ minSumm: 0
76
+ }
77
+ }
78
+ RetailcrmApi::Request.costs.retrieve(params: params).body
74
79
  # => {:success=>true, :pagination=>{:limit=>20, :totalCount=>296, :currentPage=>1, :totalPageCount=>15}, :costs=>[{:id=>296, :dateFrom=>"2021-07-29", :dateTo=>"2021-07-29", :summ=>13996, :costItem=>"products-purchase-price", :createdAt=>"2021-07-29 00:34:35", :order=>{:id=>36, :number=>"36C"}, :sites=>["b12-skillum-ru"]}]}
75
80
  ```
81
+ ### [Создание расхода](https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-costs-create)
82
+ ```ruby
83
+ body = {
84
+ site: "deppa-ru",
85
+ cost: {
86
+ summ: 100,
87
+ costItem: "office-expenses",
88
+ dateFrom: (DateTime.now - 1.day).strftime("%Y-%m-%d"),
89
+ dateTo: DateTime.now.strftime("%Y-%m-%d")
90
+ }
91
+ }
92
+ RetailcrmApi::Request.costs.create(body: body).body
93
+ # => {:success=>true, :id=>297}
94
+ ```
95
+ ### [Пакетное удаление расходов](https://docs.retailcrm.ru/Developers/APIhttps://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-costs-delete)
96
+ ```ruby
97
+ body = {
98
+ ids: [297]
99
+ }
100
+ RetailcrmApi::Request.costs.create(body: body, suffix: "delete").body
101
+ # => {:success=>true, :count=>1, :notRemovedIds=>[]}
102
+ ```
103
+ ### [Пакетная загрузка расходов](https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-costs-upload)
104
+ ```ruby
105
+ body = {
106
+ costs: [
107
+ {
108
+ sites: ["deppa-ru"],
109
+ summ: 100,
110
+ costItem: "office-expenses",
111
+ dateFrom: (DateTime.now - 1.day).strftime("%Y-%m-%d"),
112
+ dateTo: DateTime.now.strftime("%Y-%m-%d")
113
+ }
114
+ ]
115
+ }
116
+ RetailcrmApi::Request.costs.create(body: body, suffix: "upload").body
117
+ # => {:success=>true, :uploadedCosts=>[298]}
118
+ ```
119
+ ### [Получение информации о расходе](https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#get--api-v5-costs-id)
120
+ ```ruby
121
+ RetailcrmApi::Request.costs(298).retrieve.body
122
+ # => {:success=>true, :cost=>{:id=>298, :dateFrom=>"2021-08-02", :dateTo=>"2021-08-03", :summ=>100, :costItem=>"office-expenses", :createdAt=>"2021-08-03 22:12:34", :sites=>["deppa-ru"]}}
123
+ ```
124
+ ### [Редактирование расхода](https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-costs-id-edit)
125
+ ```ruby
126
+ body = {
127
+ site: "deppa-ru",
128
+ cost: {
129
+ summ: 200,
130
+ costItem: "office-expenses",
131
+ dateFrom: (DateTime.now - 1.day).strftime("%Y-%m-%d"),
132
+ dateTo: DateTime.now.strftime("%Y-%m-%d")
133
+ }
134
+ }
135
+ RetailcrmApi::Request.costs(298).update(body: body).body
136
+ # => {:success=>true, :id=>298}
137
+ ```
138
+ ### [Удаление расхода](https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-costs-id-delete)
139
+ ```ruby
140
+ RetailcrmApi::Request.costs(298).delete.body
141
+ # => {:success=>true}
142
+ ```
143
+
144
+ ## Пользовательские поля
145
+ ### [Получение списка пользовательских полей, удовлетворяющих заданному фильтру](https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#get--api-v5-custom-fields)
146
+ ```ruby
147
+ params = {
148
+ filter: {
149
+ type: "date"
150
+ }
151
+ }
152
+ RetailcrmApi::Request.custom_fields.retrieve(params: params).body
153
+ # =>{:success=>true, :pagination=>{:limit=>20, :totalCount=>0, :currentPage=>1, :totalPageCount=>0}, :customFields=>[]}
154
+ ```
76
155
 
77
156
  ## Клиенты
78
157
  ### [Получение списка клиентов, удовлетворяющих заданному фильтру](https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#get--api-v5-customers)
79
158
  ```ruby
80
- RetailcrmApi::Request.customers.retrieve.body
81
- #=> {:success=>true, :pagination=>{:limit=>20, :totalCount=>0, :currentPage=>1, :totalPageCount=>0}, :customers=>[]}
159
+ params = {
160
+ limit: 100,
161
+ filter: {
162
+ sex: "male"
163
+ }
164
+ }
165
+ RetailcrmApi::Request.customers.retrieve(params: params).body
166
+ #=> {:success=>true, :pagination=>{:limit=>100, :totalCount=>0, :currentPage=>1, :totalPageCount=>0}, :customers=>[]}
82
167
  ```
83
168
  ### [Создание клиента](https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-customers-create)
84
169
  ```ruby
@@ -5,20 +5,24 @@ module RetailcrmApi
5
5
  @request_builder = builder
6
6
  end
7
7
 
8
- def post(params: nil, headers: nil, suffix: nil, body: {})
8
+ def post(params: nil, headers: nil, suffix: nil, body: {}, first_time: true)
9
9
  validate_api_key
10
10
  begin
11
11
  response = self.rest_client(suffix).post do |request|
12
12
  configure_request(request: request, params: params, headers: headers, body: body)
13
13
  end
14
- #parse_response(response)
15
- response
14
+ parse_response(response)
16
15
  rescue => e
17
- handle_error(e)
16
+ if e.response.dig(:status) == 403 && first_time
17
+ sleep(0.3.second)
18
+ self.post(params: params, headers: headers, suffix: suffix, body: body, first_time: false)
19
+ else
20
+ handle_error(e)
21
+ end
18
22
  end
19
23
  end
20
24
 
21
- def get(params: nil, headers: nil)
25
+ def get(params: nil, headers: nil, first_time: true)
22
26
  validate_api_key
23
27
 
24
28
  begin
@@ -27,7 +31,12 @@ module RetailcrmApi
27
31
  end
28
32
  parse_response(response)
29
33
  rescue => e
30
- handle_error(e)
34
+ if e.response.dig(:status) == 403 && first_time
35
+ sleep(0.3.second)
36
+ self.get(params: params, headers: headers, first_time: false)
37
+ else
38
+ handle_error(e)
39
+ end
31
40
  end
32
41
  end
33
42
 
@@ -52,7 +52,7 @@ module RetailcrmApi
52
52
  end
53
53
 
54
54
  def update(params: nil, headers: nil, body: {})
55
- APIRequest.new(builder: self).post(params: params, headers: headers, suffix: 'update', body: body)
55
+ APIRequest.new(builder: self).post(params: params, headers: headers, suffix: 'edit', body: body)
56
56
  ensure
57
57
  reset
58
58
  end
@@ -63,8 +63,8 @@ module RetailcrmApi
63
63
  reset
64
64
  end
65
65
 
66
- def delete(params: nil, headers: nil, suffix: 'delete')
67
- APIRequest.new(builder: self).post(params: params, headers: headers)
66
+ def delete(params: nil, headers: nil)
67
+ APIRequest.new(builder: self).post(params: params, headers: headers, suffix: 'delete')
68
68
  ensure
69
69
  reset
70
70
  end
@@ -1,3 +1,3 @@
1
1
  module RetailcrmApi
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: retailcrm-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Osetrov