amorail 0.3.4 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +19 -1
- data/README.md +7 -1
- data/Rakefile +7 -3
- data/amorail.gemspec +4 -3
- data/lib/amorail.rb +3 -0
- data/lib/amorail/client.rb +8 -4
- data/lib/amorail/config.rb +2 -0
- data/lib/amorail/entities/company.rb +2 -0
- data/lib/amorail/entities/contact.rb +3 -0
- data/lib/amorail/entities/contact_link.rb +2 -0
- data/lib/amorail/entities/elementable.rb +39 -0
- data/lib/amorail/entities/lead.rb +4 -1
- data/lib/amorail/entities/leadable.rb +3 -0
- data/lib/amorail/entities/note.rb +19 -0
- data/lib/amorail/entities/task.rb +11 -23
- data/lib/amorail/entities/webhook.rb +44 -0
- data/lib/amorail/entity.rb +17 -9
- data/lib/amorail/entity/finders.rb +19 -14
- data/lib/amorail/entity/params.rb +2 -0
- data/lib/amorail/entity/{persistance.rb → persistence.rb} +24 -0
- data/lib/amorail/exceptions.rb +2 -0
- data/lib/amorail/property.rb +8 -0
- data/lib/amorail/railtie.rb +4 -1
- data/lib/amorail/version.rb +3 -1
- data/lib/tasks/amorail.rake +2 -0
- data/spec/client_spec.rb +2 -0
- data/spec/company_spec.rb +2 -0
- data/spec/contact_link_spec.rb +2 -0
- data/spec/contact_spec.rb +17 -0
- data/spec/entity_spec.rb +2 -0
- data/spec/fixtures/{account_response.json → accounts/response_1.json} +5 -5
- data/spec/fixtures/{account2_response.json → accounts/response_2.json} +1 -1
- data/spec/fixtures/{contact_create.json → contacts/create.json} +1 -1
- data/spec/fixtures/{contact_find_query.json → contacts/find_many.json} +3 -5
- data/spec/fixtures/{contact_find.json → contacts/find_one.json} +5 -6
- data/spec/fixtures/contacts/links.json +16 -0
- data/spec/fixtures/{my_contact_find.json → contacts/my_contact_find.json} +2 -3
- data/spec/fixtures/contacts/update.json +13 -0
- data/spec/fixtures/leads/create.json +13 -0
- data/spec/fixtures/leads/find_many.json +73 -0
- data/spec/fixtures/leads/links.json +16 -0
- data/spec/fixtures/leads/update.json +13 -0
- data/spec/fixtures/leads/update_errors.json +12 -0
- data/spec/fixtures/webhooks/list.json +24 -0
- data/spec/fixtures/webhooks/subscribe.json +17 -0
- data/spec/fixtures/webhooks/unsubscribe.json +17 -0
- data/spec/helpers/webmock_helpers.rb +92 -13
- data/spec/lead_spec.rb +30 -0
- data/spec/my_contact_spec.rb +2 -0
- data/spec/note_spec.rb +28 -0
- data/spec/property_spec.rb +2 -0
- data/spec/spec_helper.rb +4 -2
- data/spec/support/elementable_example.rb +54 -0
- data/spec/support/entity_class_example.rb +2 -0
- data/spec/support/leadable_example.rb +2 -0
- data/spec/support/my_contact.rb +2 -0
- data/spec/support/my_entity.rb +2 -0
- data/spec/task_spec.rb +8 -28
- data/spec/webhook_spec.rb +61 -0
- metadata +60 -33
- data/.hound.yml +0 -12
- data/spec/fixtures/contact_update.json +0 -5
- data/spec/fixtures/contacts_links.json +0 -15
- data/spec/fixtures/leads.json +0 -69
- data/spec/fixtures/leads_links.json +0 -15
data/spec/support/my_contact.rb
CHANGED
data/spec/support/my_entity.rb
CHANGED
data/spec/task_spec.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
describe Amorail::Task do
|
4
6
|
before { mock_api }
|
5
7
|
|
8
|
+
it_behaves_like 'elementable'
|
9
|
+
|
6
10
|
describe "validations" do
|
7
|
-
it {
|
8
|
-
it {
|
9
|
-
it {
|
10
|
-
it {
|
11
|
-
it { should validate_presence_of(:task_type) }
|
12
|
-
it { should validate_presence_of(:complete_till) }
|
11
|
+
it { is_expected.to validate_presence_of(:text) }
|
12
|
+
it { is_expected.to validate_presence_of(:task_type) }
|
13
|
+
it { is_expected.to validate_presence_of(:complete_till) }
|
14
|
+
it { is_expected.to validate_inclusion_of(:element_type).in_range(1..3) }
|
13
15
|
end
|
14
16
|
|
15
17
|
describe ".attributes" do
|
@@ -19,8 +21,6 @@ describe Amorail::Task do
|
|
19
21
|
|
20
22
|
specify do
|
21
23
|
is_expected.to include(
|
22
|
-
:element_type,
|
23
|
-
:element_id,
|
24
24
|
:text,
|
25
25
|
:task_type,
|
26
26
|
:complete_till
|
@@ -28,27 +28,9 @@ describe Amorail::Task do
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
describe "contact and lead" do
|
32
|
-
let(:task) { described_class.new }
|
33
|
-
it "set element_type on initialize" do
|
34
|
-
expect(described_class.new(lead: true).element_type).to eq 2
|
35
|
-
expect(described_class.new(contact: true).contact?).to be_truthy
|
36
|
-
expect(described_class.new(lead: false).element_type).to be_nil
|
37
|
-
end
|
38
|
-
|
39
|
-
it "set element_type with bang method" do
|
40
|
-
task.contact!
|
41
|
-
expect(task.element_type).to eq 1
|
42
|
-
task.lead!
|
43
|
-
expect(task.element_type).to eq 2
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
31
|
describe "#params" do
|
48
32
|
let(:task) do
|
49
33
|
described_class.new(
|
50
|
-
element_id: 1,
|
51
|
-
element_type: 1,
|
52
34
|
text: 'Win the war',
|
53
35
|
task_type: 'test',
|
54
36
|
complete_till: '2015-05-09 12:00:00'
|
@@ -58,8 +40,6 @@ describe Amorail::Task do
|
|
58
40
|
subject { task.params }
|
59
41
|
|
60
42
|
specify { is_expected.to include(:last_modified) }
|
61
|
-
specify { is_expected.to include(element_id: 1) }
|
62
|
-
specify { is_expected.to include(element_type: 1) }
|
63
43
|
specify { is_expected.to include(text: 'Win the war') }
|
64
44
|
specify { is_expected.to include(task_type: 'test') }
|
65
45
|
specify {
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Amorail::Webhook do
|
6
|
+
before { mock_api }
|
7
|
+
|
8
|
+
describe '.list' do
|
9
|
+
context 'there are some webhooks' do
|
10
|
+
before { webhooks_list_stub(Amorail.config.api_endpoint) }
|
11
|
+
|
12
|
+
it 'loads webhooks' do
|
13
|
+
res = described_class.list
|
14
|
+
expect(res.size).to eq 2
|
15
|
+
expect(res.first.id).to eq '1'
|
16
|
+
expect(res.first.url).to eq 'http://example.org'
|
17
|
+
expect(res.first.events).to eq ['add_contact']
|
18
|
+
expect(res.first.disabled).to eq false
|
19
|
+
expect(res.last.id).to eq '2'
|
20
|
+
expect(res.last.url).to eq 'http://example.com'
|
21
|
+
expect(res.last.events).to eq ['add_contact', 'add_company']
|
22
|
+
expect(res.last.disabled).to eq true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'there are not any webhooks' do
|
27
|
+
before { webhooks_list_stub(Amorail.config.api_endpoint, empty: true) }
|
28
|
+
|
29
|
+
it 'returns an empty array' do
|
30
|
+
res = described_class.list
|
31
|
+
expect(res).to eq []
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '.subscribe' do
|
37
|
+
it 'creates webhooks' do
|
38
|
+
webhooks = [
|
39
|
+
{ url: 'http://example.org', events: ['add_contact'] },
|
40
|
+
{ url: 'http://example.com', events: ['add_contact', 'add_company'] }
|
41
|
+
]
|
42
|
+
stub = webhooks_subscribe_stub(Amorail.config.api_endpoint, webhooks)
|
43
|
+
res = described_class.subscribe(webhooks)
|
44
|
+
expect(stub).to have_been_requested
|
45
|
+
expect(res.first.url).to eq 'http://example.org'
|
46
|
+
expect(res.last.url).to eq 'http://example.com'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '.unsubscribe' do
|
51
|
+
it 'removes webhooks' do
|
52
|
+
webhooks = [
|
53
|
+
{ url: 'http://example.org', events: ['add_contact'] },
|
54
|
+
{ url: 'http://example.com', events: ['add_contact', 'add_company'] }
|
55
|
+
]
|
56
|
+
stub = webhooks_unsubscribe_stub(Amorail.config.api_endpoint, webhooks)
|
57
|
+
described_class.unsubscribe(webhooks)
|
58
|
+
expect(stub).to have_been_requested
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amorail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alekseenkoss
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2019-11-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -96,25 +96,33 @@ dependencies:
|
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '2.0'
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
|
-
name:
|
99
|
+
name: rubocop
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
102
|
- - "~>"
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version: '0'
|
104
|
+
version: '0.49'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0.49'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: anyway_config
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
105
116
|
- - ">="
|
106
117
|
- !ruby/object:Gem::Version
|
107
|
-
version: '0
|
118
|
+
version: '1.0'
|
108
119
|
type: :runtime
|
109
120
|
prerelease: false
|
110
121
|
version_requirements: !ruby/object:Gem::Requirement
|
111
122
|
requirements:
|
112
|
-
- - "~>"
|
113
|
-
- !ruby/object:Gem::Version
|
114
|
-
version: '0'
|
115
123
|
- - ">="
|
116
124
|
- !ruby/object:Gem::Version
|
117
|
-
version: '0
|
125
|
+
version: '1.0'
|
118
126
|
- !ruby/object:Gem::Dependency
|
119
127
|
name: faraday
|
120
128
|
requirement: !ruby/object:Gem::Requirement
|
@@ -180,7 +188,6 @@ extensions: []
|
|
180
188
|
extra_rdoc_files: []
|
181
189
|
files:
|
182
190
|
- ".gitignore"
|
183
|
-
- ".hound.yml"
|
184
191
|
- ".rubocop.yml"
|
185
192
|
- ".travis.yml"
|
186
193
|
- Gemfile
|
@@ -194,13 +201,16 @@ files:
|
|
194
201
|
- lib/amorail/entities/company.rb
|
195
202
|
- lib/amorail/entities/contact.rb
|
196
203
|
- lib/amorail/entities/contact_link.rb
|
204
|
+
- lib/amorail/entities/elementable.rb
|
197
205
|
- lib/amorail/entities/lead.rb
|
198
206
|
- lib/amorail/entities/leadable.rb
|
207
|
+
- lib/amorail/entities/note.rb
|
199
208
|
- lib/amorail/entities/task.rb
|
209
|
+
- lib/amorail/entities/webhook.rb
|
200
210
|
- lib/amorail/entity.rb
|
201
211
|
- lib/amorail/entity/finders.rb
|
202
212
|
- lib/amorail/entity/params.rb
|
203
|
-
- lib/amorail/entity/
|
213
|
+
- lib/amorail/entity/persistence.rb
|
204
214
|
- lib/amorail/exceptions.rb
|
205
215
|
- lib/amorail/property.rb
|
206
216
|
- lib/amorail/railtie.rb
|
@@ -211,27 +221,36 @@ files:
|
|
211
221
|
- spec/contact_link_spec.rb
|
212
222
|
- spec/contact_spec.rb
|
213
223
|
- spec/entity_spec.rb
|
214
|
-
- spec/fixtures/
|
215
|
-
- spec/fixtures/
|
224
|
+
- spec/fixtures/accounts/response_1.json
|
225
|
+
- spec/fixtures/accounts/response_2.json
|
216
226
|
- spec/fixtures/amorail_test.yml
|
217
|
-
- spec/fixtures/
|
218
|
-
- spec/fixtures/
|
219
|
-
- spec/fixtures/
|
220
|
-
- spec/fixtures/
|
221
|
-
- spec/fixtures/
|
222
|
-
- spec/fixtures/
|
223
|
-
- spec/fixtures/
|
224
|
-
- spec/fixtures/
|
227
|
+
- spec/fixtures/contacts/create.json
|
228
|
+
- spec/fixtures/contacts/find_many.json
|
229
|
+
- spec/fixtures/contacts/find_one.json
|
230
|
+
- spec/fixtures/contacts/links.json
|
231
|
+
- spec/fixtures/contacts/my_contact_find.json
|
232
|
+
- spec/fixtures/contacts/update.json
|
233
|
+
- spec/fixtures/leads/create.json
|
234
|
+
- spec/fixtures/leads/find_many.json
|
235
|
+
- spec/fixtures/leads/links.json
|
236
|
+
- spec/fixtures/leads/update.json
|
237
|
+
- spec/fixtures/leads/update_errors.json
|
238
|
+
- spec/fixtures/webhooks/list.json
|
239
|
+
- spec/fixtures/webhooks/subscribe.json
|
240
|
+
- spec/fixtures/webhooks/unsubscribe.json
|
225
241
|
- spec/helpers/webmock_helpers.rb
|
226
242
|
- spec/lead_spec.rb
|
227
243
|
- spec/my_contact_spec.rb
|
244
|
+
- spec/note_spec.rb
|
228
245
|
- spec/property_spec.rb
|
229
246
|
- spec/spec_helper.rb
|
247
|
+
- spec/support/elementable_example.rb
|
230
248
|
- spec/support/entity_class_example.rb
|
231
249
|
- spec/support/leadable_example.rb
|
232
250
|
- spec/support/my_contact.rb
|
233
251
|
- spec/support/my_entity.rb
|
234
252
|
- spec/task_spec.rb
|
253
|
+
- spec/webhook_spec.rb
|
235
254
|
homepage: ''
|
236
255
|
licenses:
|
237
256
|
- MIT
|
@@ -251,8 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
251
270
|
- !ruby/object:Gem::Version
|
252
271
|
version: '0'
|
253
272
|
requirements: []
|
254
|
-
|
255
|
-
rubygems_version: 2.6.11
|
273
|
+
rubygems_version: 3.0.4
|
256
274
|
signing_key:
|
257
275
|
specification_version: 4
|
258
276
|
summary: Ruby API client for AmoCRM
|
@@ -262,24 +280,33 @@ test_files:
|
|
262
280
|
- spec/contact_link_spec.rb
|
263
281
|
- spec/contact_spec.rb
|
264
282
|
- spec/entity_spec.rb
|
265
|
-
- spec/fixtures/
|
266
|
-
- spec/fixtures/
|
283
|
+
- spec/fixtures/accounts/response_1.json
|
284
|
+
- spec/fixtures/accounts/response_2.json
|
267
285
|
- spec/fixtures/amorail_test.yml
|
268
|
-
- spec/fixtures/
|
269
|
-
- spec/fixtures/
|
270
|
-
- spec/fixtures/
|
271
|
-
- spec/fixtures/
|
272
|
-
- spec/fixtures/
|
273
|
-
- spec/fixtures/
|
274
|
-
- spec/fixtures/
|
275
|
-
- spec/fixtures/
|
286
|
+
- spec/fixtures/contacts/create.json
|
287
|
+
- spec/fixtures/contacts/find_many.json
|
288
|
+
- spec/fixtures/contacts/find_one.json
|
289
|
+
- spec/fixtures/contacts/links.json
|
290
|
+
- spec/fixtures/contacts/my_contact_find.json
|
291
|
+
- spec/fixtures/contacts/update.json
|
292
|
+
- spec/fixtures/leads/create.json
|
293
|
+
- spec/fixtures/leads/find_many.json
|
294
|
+
- spec/fixtures/leads/links.json
|
295
|
+
- spec/fixtures/leads/update.json
|
296
|
+
- spec/fixtures/leads/update_errors.json
|
297
|
+
- spec/fixtures/webhooks/list.json
|
298
|
+
- spec/fixtures/webhooks/subscribe.json
|
299
|
+
- spec/fixtures/webhooks/unsubscribe.json
|
276
300
|
- spec/helpers/webmock_helpers.rb
|
277
301
|
- spec/lead_spec.rb
|
278
302
|
- spec/my_contact_spec.rb
|
303
|
+
- spec/note_spec.rb
|
279
304
|
- spec/property_spec.rb
|
280
305
|
- spec/spec_helper.rb
|
306
|
+
- spec/support/elementable_example.rb
|
281
307
|
- spec/support/entity_class_example.rb
|
282
308
|
- spec/support/leadable_example.rb
|
283
309
|
- spec/support/my_contact.rb
|
284
310
|
- spec/support/my_entity.rb
|
285
311
|
- spec/task_spec.rb
|
312
|
+
- spec/webhook_spec.rb
|
data/.hound.yml
DELETED
data/spec/fixtures/leads.json
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"response": {
|
3
|
-
"leads": [
|
4
|
-
{
|
5
|
-
"id": "1",
|
6
|
-
"name": "Research new technologies",
|
7
|
-
"last_modified": 1374656336,
|
8
|
-
"status_id": "7046196",
|
9
|
-
"price": "500000",
|
10
|
-
"responsible_user_id": "103586",
|
11
|
-
"tags":[
|
12
|
-
{
|
13
|
-
"id": "960472",
|
14
|
-
"name": "USA"},
|
15
|
-
{
|
16
|
-
"id": "960854",
|
17
|
-
"name": "Lead"
|
18
|
-
}
|
19
|
-
],
|
20
|
-
"date_create": 1386014400,
|
21
|
-
"account_id": "7046192",
|
22
|
-
"created_user_id": "4502311",
|
23
|
-
"custom_fields": [
|
24
|
-
{
|
25
|
-
"id": "484604",
|
26
|
-
"name": "field",
|
27
|
-
"values": [
|
28
|
-
{
|
29
|
-
"value": "text"
|
30
|
-
}
|
31
|
-
]
|
32
|
-
}
|
33
|
-
]
|
34
|
-
},
|
35
|
-
{
|
36
|
-
"id": "2",
|
37
|
-
"name": "Sell it!",
|
38
|
-
"last_modified": 1374656336,
|
39
|
-
"status_id": "7046196",
|
40
|
-
"price": "100000",
|
41
|
-
"responsible_user_id": "103586",
|
42
|
-
"tags":[
|
43
|
-
{
|
44
|
-
"id": "960472",
|
45
|
-
"name": "USA"},
|
46
|
-
{
|
47
|
-
"id": "960854",
|
48
|
-
"name": "Lead"
|
49
|
-
}
|
50
|
-
],
|
51
|
-
"date_create": 1386014400,
|
52
|
-
"account_id": "7046192",
|
53
|
-
"created_user_id": "4502311",
|
54
|
-
"custom_fields": [
|
55
|
-
{
|
56
|
-
"id": "484604",
|
57
|
-
"name": "field",
|
58
|
-
"values": [
|
59
|
-
{
|
60
|
-
"value": "text"
|
61
|
-
}
|
62
|
-
]
|
63
|
-
}
|
64
|
-
]
|
65
|
-
}
|
66
|
-
],
|
67
|
-
"server_time": 1374839787
|
68
|
-
}
|
69
|
-
}
|