amorail 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,322 @@
1
+ {
2
+ "response": {
3
+ "account": {
4
+ "id": "8195968",
5
+ "name": "База клиентов",
6
+ "subdomain": "test",
7
+ "currency": "RUB",
8
+ "paid_from": false,
9
+ "paid_till": false,
10
+ "timezone": "Europe/Moscow",
11
+ "language": "ru",
12
+ "date_pattern": "d.m.Y H:i",
13
+ "limits": {
14
+ "users_count": false,
15
+ "contacts_count": false,
16
+ "active_deals_count": false
17
+ },
18
+ "users": [
19
+ {
20
+ "id": "337914",
21
+ "name": "sergey",
22
+ "last_name": null,
23
+ "login": "alekseenkoss@gmail.com",
24
+ "group_id": 0,
25
+ "rights_lead_add": "A",
26
+ "rights_lead_view": "A",
27
+ "rights_lead_edit": "A",
28
+ "rights_lead_delete": "A",
29
+ "rights_lead_export": "A",
30
+ "rights_contact_add": "A",
31
+ "rights_contact_view": "A",
32
+ "rights_contact_edit": "A",
33
+ "rights_contact_delete": "A",
34
+ "rights_contact_export": "A",
35
+ "rights_company_add": "A",
36
+ "rights_company_view": "A",
37
+ "rights_company_edit": "A",
38
+ "rights_company_delete": "A",
39
+ "rights_company_export": "A",
40
+ "is_admin": "Y"
41
+ }
42
+ ],
43
+ "groups": [],
44
+ "leads_statuses": [
45
+ {
46
+ "name": "Первичный контакт",
47
+ "id": "8195972",
48
+ "color": "#99CCFF",
49
+ "editable": "Y",
50
+ "sort": "10"
51
+ },
52
+ {
53
+ "name": "Переговоры",
54
+ "id": "8195974",
55
+ "color": "#FFFF99",
56
+ "editable": "Y",
57
+ "sort": "20"
58
+ },
59
+ {
60
+ "name": "Принимают решение",
61
+ "id": "8195976",
62
+ "color": "#FFCC66",
63
+ "editable": "Y",
64
+ "sort": "30"
65
+ },
66
+ {
67
+ "name": "Согласование договора",
68
+ "id": "8195978",
69
+ "color": "#FFCCCC",
70
+ "editable": "Y",
71
+ "sort": "40"
72
+ },
73
+ {
74
+ "name": "Успешно реализовано",
75
+ "id": "142",
76
+ "color": "#CCFF66",
77
+ "editable": "N",
78
+ "sort": "600"
79
+ },
80
+ {
81
+ "name": "Закрыто и не реализовано",
82
+ "id": "143",
83
+ "color": "#D5D8DB",
84
+ "editable": "N",
85
+ "sort": "700"
86
+ }
87
+ ],
88
+ "custom_fields": {
89
+ "contacts": [
90
+ {
91
+ "id": "1460587",
92
+ "name": "Должность",
93
+ "code": "POSITION",
94
+ "multiple": "N",
95
+ "type_id": "1",
96
+ "disabled": "0"
97
+ },
98
+ {
99
+ "id": "1460589",
100
+ "name": "Телефон",
101
+ "code": "PHONE",
102
+ "multiple": "Y",
103
+ "type_id": "8",
104
+ "disabled": "0",
105
+ "enums": {
106
+ "3392086": "WORK",
107
+ "3392088": "WORKDD",
108
+ "3392090": "MOB",
109
+ "3392092": "FAX",
110
+ "3392094": "HOME",
111
+ "3392096": "OTHER"
112
+ }
113
+ },
114
+ {
115
+ "id": "1460591",
116
+ "name": "Email",
117
+ "code": "EMAIL",
118
+ "multiple": "Y",
119
+ "type_id": "8",
120
+ "disabled": "0",
121
+ "enums": {
122
+ "3392098": "WORK",
123
+ "3392100": "PRIV",
124
+ "3392102": "OTHER"
125
+ }
126
+ },
127
+ {
128
+ "id": "1460595",
129
+ "name": "Мгн. сообщения",
130
+ "code": "IM",
131
+ "multiple": "Y",
132
+ "type_id": "8",
133
+ "disabled": "0",
134
+ "enums": {
135
+ "3392104": "SKYPE",
136
+ "3392106": "ICQ",
137
+ "3392108": "JABBER",
138
+ "3392110": "GTALK",
139
+ "3392112": "MSN",
140
+ "3392114": "OTHER"
141
+ }
142
+ }
143
+ ],
144
+ "companies": [
145
+ {
146
+ "id": "1460589",
147
+ "name": "Телефон",
148
+ "code": "PHONE",
149
+ "multiple": "Y",
150
+ "type_id": "8",
151
+ "disabled": "0",
152
+ "enums": {
153
+ "3392086": "WORK",
154
+ "3392088": "WORKDD",
155
+ "3392090": "MOB",
156
+ "3392092": "FAX",
157
+ "3392094": "HOME",
158
+ "3392096": "OTHER"
159
+ }
160
+ },
161
+ {
162
+ "id": "1460591",
163
+ "name": "Email",
164
+ "code": "EMAIL",
165
+ "multiple": "Y",
166
+ "type_id": "8",
167
+ "disabled": "0",
168
+ "enums": {
169
+ "3392098": "WORK",
170
+ "3392100": "PRIV",
171
+ "3392102": "OTHER"
172
+ }
173
+ },
174
+ {
175
+ "id": "1460593",
176
+ "name": "Web",
177
+ "code": "WEB",
178
+ "multiple": "N",
179
+ "type_id": "7",
180
+ "disabled": "0"
181
+ },
182
+ {
183
+ "id": "1460597",
184
+ "name": "Адрес",
185
+ "code": "ADDRESS",
186
+ "multiple": "N",
187
+ "type_id": "9",
188
+ "disabled": "0"
189
+ }
190
+ ]
191
+ },
192
+ "note_types": [
193
+ {
194
+ "id": 1,
195
+ "name": "",
196
+ "code": "DEAL_CREATED",
197
+ "editable": "N"
198
+ },
199
+ {
200
+ "id": 2,
201
+ "name": "",
202
+ "code": "CONTACT_CREATED",
203
+ "editable": "N"
204
+ },
205
+ {
206
+ "id": 3,
207
+ "name": "",
208
+ "code": "DEAL_STATUS_CHANGED",
209
+ "editable": "N"
210
+ },
211
+ {
212
+ "id": 4,
213
+ "name": "",
214
+ "code": "COMMON",
215
+ "editable": "Y"
216
+ },
217
+ {
218
+ "id": 5,
219
+ "name": "",
220
+ "code": "ATTACHEMENT",
221
+ "editable": "N"
222
+ },
223
+ {
224
+ "id": 6,
225
+ "name": "",
226
+ "code": "CALL",
227
+ "editable": "N"
228
+ },
229
+ {
230
+ "id": 7,
231
+ "name": "",
232
+ "code": "MAIL_MESSAGE",
233
+ "editable": "N"
234
+ },
235
+ {
236
+ "id": 8,
237
+ "name": "",
238
+ "code": "MAIL_MESSAGE_ATTACHMENT",
239
+ "editable": "N"
240
+ },
241
+ {
242
+ "id": 9,
243
+ "name": "",
244
+ "code": "EXTERNAL_ATTACH",
245
+ "editable": "N"
246
+ },
247
+ {
248
+ "id": 10,
249
+ "name": "",
250
+ "code": "CALL_IN",
251
+ "editable": "N"
252
+ },
253
+ {
254
+ "id": 11,
255
+ "name": "",
256
+ "code": "CALL_OUT",
257
+ "editable": "N"
258
+ },
259
+ {
260
+ "id": 12,
261
+ "name": "",
262
+ "code": "COMPANY_CREATED",
263
+ "editable": "N"
264
+ },
265
+ {
266
+ "id": 13,
267
+ "name": "",
268
+ "code": "TASK_RESULT",
269
+ "editable": "N"
270
+ },
271
+ {
272
+ "id": 99,
273
+ "name": "",
274
+ "code": "MAX_SYSTEM",
275
+ "editable": "N"
276
+ },
277
+ {
278
+ "id": 101,
279
+ "name": "Ссылка",
280
+ "code": "DROPBOX",
281
+ "editable": "N"
282
+ },
283
+ {
284
+ "id": 102,
285
+ "name": "Входящее",
286
+ "code": "SMS_IN",
287
+ "editable": "N"
288
+ },
289
+ {
290
+ "id": 103,
291
+ "name": "Исходящее",
292
+ "code": "SMS_OUT",
293
+ "editable": "N"
294
+ }
295
+ ],
296
+ "task_types": [
297
+ {
298
+ "id": 1,
299
+ "name": "Q_TASKS_CLASS_FOLLOW_UP",
300
+ "code": "FOLLOW_UP"
301
+ },
302
+ {
303
+ "id": 1,
304
+ "name": "Звонок",
305
+ "code": "CALL"
306
+ },
307
+ {
308
+ "id": 2,
309
+ "name": "Встреча",
310
+ "code": "MEETING"
311
+ },
312
+ {
313
+ "id": 3,
314
+ "name": "Письмо",
315
+ "code": "LETTER"
316
+ }
317
+ ],
318
+ "timezoneoffset": "+03:00"
319
+ },
320
+ "server_time": 1422442143
321
+ }
322
+ }
@@ -0,0 +1,3 @@
1
+ usermail: 'amorail@test.com'
2
+ api_key: '75742b166417fe32ae132282ce178cf6'
3
+ api_endpoint: 'https://test.amocrm.ru'
@@ -0,0 +1,13 @@
1
+ {
2
+ "response": {
3
+ "contacts": {
4
+ "add": [
5
+ {
6
+ "id": 101,
7
+ "request_id": 0
8
+ }
9
+ ]
10
+ },
11
+ "server_time": 1423139130
12
+ }
13
+ }
@@ -0,0 +1,38 @@
1
+ {
2
+ "response": {
3
+ "contacts": [
4
+ {
5
+ "id": 101,
6
+ "name": "Foo bar",
7
+ "account_id": "8195968",
8
+ "last_modified": 1423139130,
9
+ "company_name": "Foo Inc.",
10
+ "custom_fields":
11
+ [
12
+ {
13
+ "id": "1460591",
14
+ "name": "Email",
15
+ "code": "EMAIL",
16
+ "values": [
17
+ {
18
+ "value": "foo@tb.com",
19
+ "enum": "3392098"
20
+ }
21
+ ]
22
+ },
23
+ {
24
+ "id": "1460589",
25
+ "name": "Телефон",
26
+ "code": "PHONE",
27
+ "values": [
28
+ {
29
+ "value": "1111 111 111",
30
+ "enum": "3392086"
31
+ }
32
+ ]
33
+ }
34
+ ]
35
+ }
36
+ ]
37
+ }
38
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "response": {
3
+ "contacts": null
4
+ }
5
+ }
@@ -0,0 +1,64 @@
1
+ def mock_api
2
+ authorize_stub(Amorail.config.api_endpoint,
3
+ Amorail.config.usermail,
4
+ Amorail.config.api_key)
5
+
6
+ account_info_stub(Amorail.config.api_endpoint)
7
+ end
8
+
9
+ def authorize_stub(endpoint, usermail, api_key)
10
+ stub_request(:post, "#{endpoint}/private/api/auth.php?type=json").
11
+ with(:body => "{\"USER_LOGIN\":\"#{usermail}\",\"USER_HASH\":\"#{api_key}\"}",
12
+ :headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.9.1'}).
13
+ to_return(:status => 200, :body => "", :headers => {'Set-Cookie' => 'PHPSESSID=58vorte6dd4t7h6mtuig9l0p50; path=/; domain=amocrm.ru'})
14
+ end
15
+
16
+ def account_info_stub(endpoint)
17
+ stub_request(:get, endpoint + '/private/api/v2/json/accounts/current').to_return(
18
+ :body => File.read('./spec/fixtures/account_response.json'), headers: {'Content-Type'=>'application/json'}, status: 200
19
+ )
20
+ end
21
+
22
+ def unauthorized_account_info_stub(endpoint)
23
+ stub_request(:get, endpoint + '/private/api/v2/json/accounts/current').to_return(
24
+ :body => "", status: 401
25
+ )
26
+ end
27
+
28
+ def bad_req_account_info_stub(endpoint)
29
+ stub_request(:post, endpoint + '/private/api/v2/json/accounts/current').with(:body => "{}",
30
+ :headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.9.1'}).to_return(
31
+ :body => "", status: 400
32
+ )
33
+ end
34
+
35
+ def contact_create_stub(endpoint)
36
+ stub_request(:post, endpoint + '/private/api/v2/json/contacts/set').with(
37
+ :headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.9.1'}).to_return(
38
+ :body => File.read('./spec/fixtures/contact_create.json'), headers: {'Content-Type'=>'application/json'}, status: 200
39
+ )
40
+ end
41
+
42
+ def contact_update_stub(endpoint)
43
+ stub_request(:post, endpoint + '/private/api/v2/json/contacts/set').with(
44
+ :headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.9.1'}).to_return(
45
+ :body => File.read('./spec/fixtures/contact_update.json'), headers: {'Content-Type'=>'application/json'}, status: 200
46
+ )
47
+ end
48
+
49
+ def contact_find_stub(endpoint, id, success = true)
50
+ if success
51
+ stub_request(:get, "#{endpoint}/private/api/v2/json/contacts/list?id=#{id}").to_return(
52
+ :body => File.read('./spec/fixtures/contact_find.json'), headers: {'Content-Type'=>'application/json'}, status: 200
53
+ )
54
+ else
55
+ stub_request(:get, "#{endpoint}/private/api/v2/json/contacts/list?id=#{id}").to_return(body: nil, status: 204)
56
+ end
57
+ end
58
+
59
+ def company_create_stub(endpoint)
60
+ stub_request(:post, endpoint + '/private/api/v2/json/company/set').with(
61
+ :headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.9.1'}).to_return(
62
+ :body => File.read('./spec/fixtures/contact_create.json'), headers: {'Content-Type'=>'application/json'}, status: 200
63
+ )
64
+ end
data/spec/lead_spec.rb ADDED
@@ -0,0 +1,28 @@
1
+ require "spec_helper"
2
+
3
+ describe Amorail::AmoLead do
4
+ before { mock_api }
5
+
6
+ describe "validations" do
7
+ it { should validate_presence_of(:name)}
8
+ it { should validate_presence_of(:status_id)}
9
+ end
10
+
11
+ describe "#params" do
12
+ let(:lead) do
13
+ Amorail::AmoLead.new(
14
+ name: 'Test',
15
+ price: 100,
16
+ status_id: 2,
17
+ tags: 'test lead'
18
+ )
19
+ end
20
+
21
+ subject { lead.params }
22
+
23
+ specify { is_expected.to include(name: 'Test') }
24
+ specify { is_expected.to include(price: 100) }
25
+ specify { is_expected.to include(status_id: 2) }
26
+ specify { is_expected.to include(tags: 'test lead') }
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'rspec'
5
+ require 'amorail'
6
+ require 'pry-byebug'
7
+ require 'webmock/rspec'
8
+ require 'shoulda/matchers'
9
+ require 'helpers/webmock_helpers'
10
+
11
+ ENV["AMORAIL_CONF"] = File.expand_path("../fixtures/amorail_test.yml", __FILE__)
12
+
13
+ Dir[File.expand_path("../support/**/*.rb",__FILE__)].each {|f| require f}
14
+
15
+ RSpec.configure do |config|
16
+ config.mock_with :rspec
17
+ end
data/spec/task_spec.rb ADDED
@@ -0,0 +1,52 @@
1
+ require "spec_helper"
2
+
3
+ describe Amorail::AmoTask do
4
+ before { mock_api }
5
+
6
+ describe "validations" do
7
+ it { should validate_presence_of(:element_id) }
8
+ it { should validate_presence_of(:element_type) }
9
+ it { should validate_inclusion_of(:element_type).in_range(1..2) }
10
+ it { should validate_presence_of(:text) }
11
+ it { should validate_presence_of(:task_type) }
12
+ it { should validate_presence_of(:complete_till) }
13
+ end
14
+
15
+ describe "contact and lead" do
16
+ let(:task) { Amorail::AmoTask.new }
17
+ it "set element_type on initialize" do
18
+ expect(Amorail::AmoTask.new(lead: true).element_type).to eq 2
19
+ expect(Amorail::AmoTask.new(contact: true).contact?).to be_truthy
20
+ expect(Amorail::AmoTask.new(lead: false).element_type).to be_nil
21
+ end
22
+
23
+ it "set element_type with bang method" do
24
+ task.contact!
25
+ expect(task.element_type).to eq 1
26
+ task.lead!
27
+ expect(task.element_type).to eq 2
28
+ end
29
+ end
30
+
31
+ describe "#params" do
32
+ let(:task) do
33
+ Amorail::AmoTask.new(
34
+ element_id: 1,
35
+ element_type: 1,
36
+ text: 'Win the war',
37
+ task_type: 'test',
38
+ complete_till: '2015-05-09 12:00:00'
39
+ )
40
+ end
41
+
42
+ subject { task.params }
43
+
44
+ specify { is_expected.to include(element_id: 1) }
45
+ specify { is_expected.to include(element_type: 1) }
46
+ specify { is_expected.to include(text: 'Win the war') }
47
+ specify { is_expected.to include(task_type: 'test') }
48
+ specify {
49
+ is_expected.to include(complete_till: Time.local(2015, 5, 9, 12, 0, 0).to_i)
50
+ }
51
+ end
52
+ end