amorail 0.3.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +19 -1
  3. data/README.md +7 -1
  4. data/Rakefile +7 -3
  5. data/amorail.gemspec +4 -3
  6. data/lib/amorail.rb +3 -0
  7. data/lib/amorail/client.rb +8 -4
  8. data/lib/amorail/config.rb +2 -0
  9. data/lib/amorail/entities/company.rb +2 -0
  10. data/lib/amorail/entities/contact.rb +3 -0
  11. data/lib/amorail/entities/contact_link.rb +2 -0
  12. data/lib/amorail/entities/elementable.rb +39 -0
  13. data/lib/amorail/entities/lead.rb +4 -1
  14. data/lib/amorail/entities/leadable.rb +3 -0
  15. data/lib/amorail/entities/note.rb +19 -0
  16. data/lib/amorail/entities/task.rb +11 -23
  17. data/lib/amorail/entities/webhook.rb +44 -0
  18. data/lib/amorail/entity.rb +17 -9
  19. data/lib/amorail/entity/finders.rb +19 -14
  20. data/lib/amorail/entity/params.rb +2 -0
  21. data/lib/amorail/entity/{persistance.rb → persistence.rb} +24 -0
  22. data/lib/amorail/exceptions.rb +2 -0
  23. data/lib/amorail/property.rb +8 -0
  24. data/lib/amorail/railtie.rb +4 -1
  25. data/lib/amorail/version.rb +3 -1
  26. data/lib/tasks/amorail.rake +2 -0
  27. data/spec/client_spec.rb +2 -0
  28. data/spec/company_spec.rb +2 -0
  29. data/spec/contact_link_spec.rb +2 -0
  30. data/spec/contact_spec.rb +17 -0
  31. data/spec/entity_spec.rb +2 -0
  32. data/spec/fixtures/{account_response.json → accounts/response_1.json} +5 -5
  33. data/spec/fixtures/{account2_response.json → accounts/response_2.json} +1 -1
  34. data/spec/fixtures/{contact_create.json → contacts/create.json} +1 -1
  35. data/spec/fixtures/{contact_find_query.json → contacts/find_many.json} +3 -5
  36. data/spec/fixtures/{contact_find.json → contacts/find_one.json} +5 -6
  37. data/spec/fixtures/contacts/links.json +16 -0
  38. data/spec/fixtures/{my_contact_find.json → contacts/my_contact_find.json} +2 -3
  39. data/spec/fixtures/contacts/update.json +13 -0
  40. data/spec/fixtures/leads/create.json +13 -0
  41. data/spec/fixtures/leads/find_many.json +73 -0
  42. data/spec/fixtures/leads/links.json +16 -0
  43. data/spec/fixtures/leads/update.json +13 -0
  44. data/spec/fixtures/leads/update_errors.json +12 -0
  45. data/spec/fixtures/webhooks/list.json +24 -0
  46. data/spec/fixtures/webhooks/subscribe.json +17 -0
  47. data/spec/fixtures/webhooks/unsubscribe.json +17 -0
  48. data/spec/helpers/webmock_helpers.rb +92 -13
  49. data/spec/lead_spec.rb +30 -0
  50. data/spec/my_contact_spec.rb +2 -0
  51. data/spec/note_spec.rb +28 -0
  52. data/spec/property_spec.rb +2 -0
  53. data/spec/spec_helper.rb +4 -2
  54. data/spec/support/elementable_example.rb +54 -0
  55. data/spec/support/entity_class_example.rb +2 -0
  56. data/spec/support/leadable_example.rb +2 -0
  57. data/spec/support/my_contact.rb +2 -0
  58. data/spec/support/my_entity.rb +2 -0
  59. data/spec/task_spec.rb +8 -28
  60. data/spec/webhook_spec.rb +61 -0
  61. metadata +60 -33
  62. data/.hound.yml +0 -12
  63. data/spec/fixtures/contact_update.json +0 -5
  64. data/spec/fixtures/contacts_links.json +0 -15
  65. data/spec/fixtures/leads.json +0 -69
  66. data/spec/fixtures/leads_links.json +0 -15
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class MyContact < Amorail::Contact # :nodoc:
2
4
  amo_property :teachbase_id
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # We only need this class to set Amo names for core Entity
2
4
  class MyEntity < Amorail::Entity # :nodoc:
3
5
  amo_names 'entity'
@@ -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 { 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) }
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.3.4
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: 2017-07-12 00:00:00.000000000 Z
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: anyway_config
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.3'
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.3'
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/persistance.rb
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/account2_response.json
215
- - spec/fixtures/account_response.json
224
+ - spec/fixtures/accounts/response_1.json
225
+ - spec/fixtures/accounts/response_2.json
216
226
  - spec/fixtures/amorail_test.yml
217
- - spec/fixtures/contact_create.json
218
- - spec/fixtures/contact_find.json
219
- - spec/fixtures/contact_find_query.json
220
- - spec/fixtures/contact_update.json
221
- - spec/fixtures/contacts_links.json
222
- - spec/fixtures/leads.json
223
- - spec/fixtures/leads_links.json
224
- - spec/fixtures/my_contact_find.json
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
- rubyforge_project:
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/account2_response.json
266
- - spec/fixtures/account_response.json
283
+ - spec/fixtures/accounts/response_1.json
284
+ - spec/fixtures/accounts/response_2.json
267
285
  - spec/fixtures/amorail_test.yml
268
- - spec/fixtures/contact_create.json
269
- - spec/fixtures/contact_find.json
270
- - spec/fixtures/contact_find_query.json
271
- - spec/fixtures/contact_update.json
272
- - spec/fixtures/contacts_links.json
273
- - spec/fixtures/leads.json
274
- - spec/fixtures/leads_links.json
275
- - spec/fixtures/my_contact_find.json
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
@@ -1,12 +0,0 @@
1
- ruby:
2
- enabled: true
3
- config_file: .rubocop.yml
4
-
5
- javascript:
6
- enabled: false
7
-
8
- coffeescript:
9
- enabled: false
10
-
11
- sass:
12
- enabled: false
@@ -1,5 +0,0 @@
1
- {
2
- "response": {
3
- "contacts": null
4
- }
5
- }
@@ -1,15 +0,0 @@
1
- {
2
- "response": {
3
- "links": [
4
- {
5
- "contact_id": "101",
6
- "lead_id": "1",
7
- "last_modified": 1374741830
8
- },
9
- {
10
- "contact_id": "101",
11
- "lead_id": "2",
12
- "last_modified": 1374839942
13
- }]
14
- }
15
- }
@@ -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
- }
@@ -1,15 +0,0 @@
1
- {
2
- "response": {
3
- "links": [
4
- {
5
- "contact_id": "101",
6
- "lead_id": "2",
7
- "last_modified": 1374839942
8
- },
9
- {
10
- "contact_id": "102",
11
- "lead_id": "2",
12
- "last_modified": 1374839942
13
- }]
14
- }
15
- }