amocrm-rails 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.markdown +67 -89
- data/lib/amocrm-rails/api_request.rb +16 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 821326c22e09b61100c31682f36c961405092c121bc7494b953c1d489edb67ef
|
4
|
+
data.tar.gz: 95b9dbef8840288e57d5e6bff62a64227138e274a333311a3d4d3fb691fc57f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56140e67a5b9b810ca5700489d55de7d106f9a31bd0f8c4baf7118b8cdb858efad091930e6bdaf0372dee5a4c7ffc1b9a0a24be22f2a8343b7a59e5b7c6d259d
|
7
|
+
data.tar.gz: 3140e7134820e313f417313b4b17083ebdf54eff76b655ce8eb0fc851429920d4fb226b78b9fc76d28d474faad66d3c8f6a86327c5f78a2357385396151770f0
|
data/README.markdown
CHANGED
@@ -15,128 +15,106 @@
|
|
15
15
|
Вы можете изменять `timeout`, `open_timeout`, `faraday_adapter`, `proxy`, `symbolize_keys`, `logger`, и `debug`:
|
16
16
|
|
17
17
|
```ruby
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
AmocrmRails::Request.timeout = 15
|
19
|
+
AmocrmRails::Request.open_timeout = 15
|
20
|
+
AmocrmRails::Request.symbolize_keys = true
|
21
|
+
AmocrmRails::Request.debug = false
|
22
22
|
```
|
23
23
|
в файле `config/initializers/amocrm.rb`
|
24
24
|
|
25
|
-
##
|
26
|
-
|
27
|
-
### Добавление, обновление и удаление списков
|
28
|
-
#### Добавление
|
25
|
+
## Параметры аккаунта
|
29
26
|
```ruby
|
30
|
-
|
31
|
-
|
32
|
-
name: "Товары"
|
33
|
-
}
|
34
|
-
]
|
35
|
-
body = {
|
36
|
-
add: items
|
37
|
-
}
|
38
|
-
response = AmocrmRails::Request.catalogs.create(body: body)
|
39
|
-
items.map!.with_index { |item, index| item.merge(response.body[:_embedded][:items][index]) }
|
40
|
-
```
|
41
|
-
#### Обновление
|
42
|
-
```
|
43
|
-
items.each do |item|
|
44
|
-
item[:name].insert(-1, ' updated')
|
45
|
-
item.delete(:_links)
|
46
|
-
end
|
47
|
-
|
48
|
-
body = {
|
49
|
-
update: items
|
27
|
+
params = {
|
28
|
+
with: 'amojo_id,amojo_rights,users_groups,task_types,version,entity_names,datetime_settings'
|
50
29
|
}
|
51
|
-
response = AmocrmRails::Request.
|
52
|
-
|
30
|
+
response = AmocrmRails::Request.account.retrieve(params: params)
|
31
|
+
p(response.body)
|
53
32
|
```
|
54
33
|
|
55
|
-
|
56
|
-
|
57
|
-
🤦🤦🤦
|
58
|
-
body = "{\"delete\": [{#{item_ids.join(',')}]}"
|
59
|
-
AmocrmRails::Request.catalogs.create(body: body)
|
60
|
-
```
|
34
|
+
## Сделки
|
35
|
+
### [Список сделок](https://www.amocrm.ru/developers/content/crm_platform/leads-api)
|
61
36
|
|
62
|
-
### Перечень списков
|
63
37
|
```ruby
|
64
|
-
|
38
|
+
params = {
|
39
|
+
with: 'catalog_elements',
|
40
|
+
page: 0,
|
41
|
+
limit: 10
|
42
|
+
}
|
43
|
+
response = AmocrmRails::Request.leads.retrieve(params: params)
|
65
44
|
p(response.body)
|
66
|
-
|
45
|
+
leads = response.body[:_embedded][:leads]
|
46
|
+
lead_id = leads.first[:id]
|
67
47
|
```
|
48
|
+
### [Получение сделки по ID](https://www.amocrm.ru/developers/content/crm_platform/leads-api#lead-detail)
|
68
49
|
|
69
|
-
## Методы элементов списка
|
70
|
-
|
71
|
-
### Добавление, обновление и удаление элементов списка
|
72
|
-
|
73
|
-
#### Добавление элементов
|
74
50
|
```ruby
|
75
|
-
|
76
|
-
|
77
|
-
{
|
78
|
-
catalog_id: item_ids.first,
|
79
|
-
name: "Карандаш"
|
80
|
-
}
|
81
|
-
]
|
51
|
+
params = {
|
52
|
+
with: 'catalog_elements'
|
82
53
|
}
|
83
|
-
response = AmocrmRails::Request.
|
54
|
+
response = AmocrmRails::Request.leads(lead_id).retrieve(params: params)
|
84
55
|
p(response.body)
|
85
|
-
catalog_element_ids = response.body[:_embedded][:items].map{|item| item[:id]}
|
86
56
|
```
|
57
|
+
### [Добавление сделок](https://www.amocrm.ru/developers/content/crm_platform/leads-api#leads-add)
|
87
58
|
|
88
|
-
#### Обновление элементов
|
89
59
|
```ruby
|
90
|
-
body =
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
60
|
+
body = [
|
61
|
+
{
|
62
|
+
"name": "Сделка для примера 1",
|
63
|
+
"created_by": 0,
|
64
|
+
"price": 20000
|
65
|
+
},
|
66
|
+
{
|
67
|
+
"name": "Сделка для примера 2",
|
68
|
+
"price": 10000
|
69
|
+
}
|
70
|
+
]
|
71
|
+
response = AmocrmRails::Request.leads.create(body: body)
|
100
72
|
p(response.body)
|
73
|
+
leads = response.body[:_embedded][:leads]
|
101
74
|
```
|
102
75
|
|
103
|
-
|
76
|
+
### [Комплексное добавление сделок с контактом и компанией](https://www.amocrm.ru/developers/content/crm_platform/leads-api#leads-complex-add)
|
104
77
|
|
105
78
|
```ruby
|
106
|
-
body =
|
107
|
-
|
108
|
-
|
109
|
-
|
79
|
+
body = [
|
80
|
+
{
|
81
|
+
name: "Название сделки",
|
82
|
+
price: 3422,
|
83
|
+
created_at: 1608905348
|
84
|
+
},
|
85
|
+
{
|
86
|
+
name: "Название сделки",
|
87
|
+
price: 3422
|
88
|
+
}
|
89
|
+
]
|
90
|
+
response = AmocrmRails::Request.leads.complex.create(body: body)
|
110
91
|
p(response.body)
|
111
92
|
```
|
112
93
|
|
113
|
-
###
|
114
|
-
|
94
|
+
### [Редактирование сделок](https://www.amocrm.ru/developers/content/crm_platform/leads-api#leads-edit)
|
115
95
|
```ruby
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
96
|
+
body = [
|
97
|
+
{
|
98
|
+
id: 666749,
|
99
|
+
closed_at: 1589297221
|
100
|
+
},
|
101
|
+
{
|
102
|
+
id: 666753,
|
103
|
+
price: 50000
|
104
|
+
}
|
105
|
+
]
|
106
|
+
response = AmocrmRails::Request.leads.update(body: body)
|
120
107
|
p(response.body)
|
121
|
-
|
108
|
+
leads = response.body[:_embedded][:leads]
|
122
109
|
```
|
123
110
|
|
124
|
-
|
125
|
-
|
126
|
-
### Включение функционала
|
111
|
+
### [Редактирование сделки](https://www.amocrm.ru/developers/content/crm_platform/leads-api#leads-edit)
|
127
112
|
|
128
113
|
```ruby
|
129
114
|
body = {
|
130
|
-
|
115
|
+
closed_at: 1589297221
|
131
116
|
}
|
132
|
-
response = AmocrmRails::Request.
|
117
|
+
response = AmocrmRails::Request.leads(666749).update(body: body)
|
133
118
|
p(response.body)
|
134
|
-
|
119
|
+
leads = response.body[:_embedded][:leads]
|
135
120
|
```
|
136
|
-
|
137
|
-
### Статус активности функционала
|
138
|
-
|
139
|
-
```ruby
|
140
|
-
response = AmocrmRails::Request.products_settings.retrieve
|
141
|
-
p(response.body)
|
142
|
-
```
|
@@ -17,6 +17,9 @@ module AmocrmRails
|
|
17
17
|
if e.response.try(:code) == 401 && first_time
|
18
18
|
AmocrmRails.generate_access_token
|
19
19
|
self.post(params: params, headers: headers, body: body, first_time: false)
|
20
|
+
elsif e.response.try(:code) == 429
|
21
|
+
sleep(1.second)
|
22
|
+
self.post(params: params, headers: headers, body: body, first_time: false)
|
20
23
|
else
|
21
24
|
handle_error(e)
|
22
25
|
end
|
@@ -35,6 +38,9 @@ module AmocrmRails
|
|
35
38
|
if e.response.try(:code) == 401 && first_time
|
36
39
|
AmocrmRails.generate_access_token
|
37
40
|
self.patch(params: params, headers: headers, body: body, first_time: false)
|
41
|
+
elsif e.response.try(:code) == 429
|
42
|
+
sleep(1.second)
|
43
|
+
self.patch(params: params, headers: headers, body: body, first_time: false)
|
38
44
|
else
|
39
45
|
handle_error(e)
|
40
46
|
end
|
@@ -53,6 +59,9 @@ module AmocrmRails
|
|
53
59
|
if e.response.try(:code) == 401 && first_time
|
54
60
|
AmocrmRails.generate_access_token
|
55
61
|
self.put(params: params, headers: headers, body: body, first_time: false)
|
62
|
+
elsif e.response.try(:code) == 429
|
63
|
+
sleep(1.second)
|
64
|
+
self.put(params: params, headers: headers, body: body, first_time: false)
|
56
65
|
else
|
57
66
|
handle_error(e)
|
58
67
|
end
|
@@ -71,6 +80,9 @@ module AmocrmRails
|
|
71
80
|
if e.response.try(:code) == 401 && first_time
|
72
81
|
AmocrmRails.generate_access_token
|
73
82
|
self.get(params: params, headers: headers, first_time: false)
|
83
|
+
elsif e.response.try(:code) == 429
|
84
|
+
sleep(1.second)
|
85
|
+
self.get(params: params, headers: headers, body: body, first_time: false)
|
74
86
|
else
|
75
87
|
handle_error(e)
|
76
88
|
end
|
@@ -89,6 +101,9 @@ module AmocrmRails
|
|
89
101
|
if e.response.try(:code) == 401 && first_time
|
90
102
|
AmocrmRails.generate_access_token
|
91
103
|
self.delete(params: params, headers: headers, first_time: false)
|
104
|
+
elsif e.response.try(:code) == 429
|
105
|
+
sleep(1.second)
|
106
|
+
self.delete(params: params, headers: headers, body: body, first_time: false)
|
92
107
|
else
|
93
108
|
handle_error(e)
|
94
109
|
end
|
@@ -211,7 +226,7 @@ module AmocrmRails
|
|
211
226
|
end
|
212
227
|
|
213
228
|
def base_api_url
|
214
|
-
"#{AmocrmRails.api_endpoint}/api/
|
229
|
+
"#{AmocrmRails.api_endpoint}/api/v4/"
|
215
230
|
end
|
216
231
|
end
|
217
232
|
end
|