amorail 0.3.4 → 0.6.0
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 +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
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Amorail # :nodoc: all
|
2
4
|
class Entity
|
3
5
|
class InvalidRecord < ::Amorail::Error; end
|
@@ -13,6 +15,7 @@ module Amorail # :nodoc: all
|
|
13
15
|
|
14
16
|
def save
|
15
17
|
return false unless valid?
|
18
|
+
|
16
19
|
new_record? ? push('add') : push('update')
|
17
20
|
end
|
18
21
|
|
@@ -22,6 +25,7 @@ module Amorail # :nodoc: all
|
|
22
25
|
|
23
26
|
def update(attrs = {})
|
24
27
|
return false if new_record?
|
28
|
+
|
25
29
|
merge_params(attrs)
|
26
30
|
push('update')
|
27
31
|
end
|
@@ -32,6 +36,7 @@ module Amorail # :nodoc: all
|
|
32
36
|
|
33
37
|
def reload
|
34
38
|
fail NotPersisted if id.nil?
|
39
|
+
|
35
40
|
load_record(id)
|
36
41
|
end
|
37
42
|
|
@@ -40,5 +45,24 @@ module Amorail # :nodoc: all
|
|
40
45
|
def extract_data_add(response)
|
41
46
|
response.fetch('add').first
|
42
47
|
end
|
48
|
+
|
49
|
+
# Update response can have status 200 and contain errors.
|
50
|
+
# In case of errors "update" key in a response is a Hash with "errors" key.
|
51
|
+
# If there are no errors "update" key is an Array with entities attributes.
|
52
|
+
def extract_data_update(response)
|
53
|
+
case data = response.fetch('update')
|
54
|
+
when Array
|
55
|
+
data.first
|
56
|
+
when Hash
|
57
|
+
merge_errors(data)
|
58
|
+
raise(InvalidRecord)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def merge_errors(data)
|
63
|
+
data.fetch("errors").each do |_, message|
|
64
|
+
errors.add(:base, message)
|
65
|
+
end
|
66
|
+
end
|
43
67
|
end
|
44
68
|
end
|
data/lib/amorail/exceptions.rb
CHANGED
data/lib/amorail/property.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Amorail
|
2
4
|
# Return hash key as method call
|
3
5
|
module MethodMissing
|
@@ -8,6 +10,10 @@ module Amorail
|
|
8
10
|
super
|
9
11
|
end
|
10
12
|
end
|
13
|
+
|
14
|
+
def respond_to_missing?(method_sym, *args)
|
15
|
+
args.size.zero? && data.key?(method_sym.to_s)
|
16
|
+
end
|
11
17
|
end
|
12
18
|
|
13
19
|
class Property # :nodoc: all
|
@@ -22,6 +28,7 @@ module Amorail
|
|
22
28
|
data['custom_fields'].fetch(source_name, []).each do |contact|
|
23
29
|
identifier = contact['code'].presence || contact['name'].presence
|
24
30
|
next if identifier.nil?
|
31
|
+
|
25
32
|
hash[identifier.downcase] = PropertyItem.new(contact)
|
26
33
|
end
|
27
34
|
new hash
|
@@ -114,6 +121,7 @@ module Amorail
|
|
114
121
|
prop_item = PropertyItem.new(tt)
|
115
122
|
identifier = tt['code'].presence || tt['name'].presence
|
116
123
|
next if identifier.nil?
|
124
|
+
|
117
125
|
hash[identifier.downcase] = prop_item
|
118
126
|
hash[identifier] = prop_item
|
119
127
|
end
|
data/lib/amorail/railtie.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Amorail
|
4
|
+
# Add amorail rake tasks
|
2
5
|
class Railtie < Rails::Railtie
|
3
6
|
rake_tasks do
|
4
|
-
load File.expand_path('
|
7
|
+
load File.expand_path('../tasks/amorail.rake', __dir__)
|
5
8
|
end
|
6
9
|
end
|
7
10
|
end
|
data/lib/amorail/version.rb
CHANGED
data/lib/tasks/amorail.rake
CHANGED
data/spec/client_spec.rb
CHANGED
data/spec/company_spec.rb
CHANGED
data/spec/contact_link_spec.rb
CHANGED
data/spec/contact_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
describe Amorail::Contact do
|
@@ -136,6 +138,21 @@ describe Amorail::Contact do
|
|
136
138
|
end
|
137
139
|
end
|
138
140
|
|
141
|
+
describe ".where" do
|
142
|
+
before { contacts_where_stub(Amorail.config.api_endpoint, query: 'xxx', limit_rows: 10, limit_offset: 100) }
|
143
|
+
|
144
|
+
it "loads entities" do
|
145
|
+
res = described_class.where(query: 'xxx', limit_rows: 10, limit_offset: 100)
|
146
|
+
expect(res.size).to eq 2
|
147
|
+
expect(res.first.id).to eq 101
|
148
|
+
expect(res.last.id).to eq 102
|
149
|
+
expect(res.first.company_name).to eq "Foo Inc."
|
150
|
+
expect(res.last.email).to eq "foo2@tb.com"
|
151
|
+
expect(res.first.phone).to eq "1111 111 111"
|
152
|
+
expect(res.first.params[:id]).to eq 101
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
139
156
|
describe "#save" do
|
140
157
|
before { contact_create_stub(Amorail.config.api_endpoint) }
|
141
158
|
|
data/spec/entity_spec.rb
CHANGED
@@ -141,9 +141,9 @@
|
|
141
141
|
}
|
142
142
|
},
|
143
143
|
{
|
144
|
-
"id":
|
145
|
-
"name":
|
146
|
-
"multiple":
|
144
|
+
"id": "116302",
|
145
|
+
"name": "teachbase_id",
|
146
|
+
"multiple": "N",
|
147
147
|
"type_id": "8"
|
148
148
|
}
|
149
149
|
],
|
@@ -162,7 +162,7 @@
|
|
162
162
|
"multiple": "N",
|
163
163
|
"type_id": "3"
|
164
164
|
}
|
165
|
-
|
165
|
+
],
|
166
166
|
"companies": [
|
167
167
|
{
|
168
168
|
"id": "1460589",
|
@@ -341,4 +341,4 @@
|
|
341
341
|
},
|
342
342
|
"server_time": 1422442143
|
343
343
|
}
|
344
|
-
}
|
344
|
+
}
|
@@ -7,8 +7,7 @@
|
|
7
7
|
"account_id": "8195968",
|
8
8
|
"last_modified": 1423139130,
|
9
9
|
"company_name": "Foo Inc.",
|
10
|
-
"custom_fields":
|
11
|
-
[
|
10
|
+
"custom_fields": [
|
12
11
|
{
|
13
12
|
"id": "1460591",
|
14
13
|
"name": "Email",
|
@@ -39,8 +38,7 @@
|
|
39
38
|
"account_id": "8195968",
|
40
39
|
"last_modified": 1423139150,
|
41
40
|
"company_name": "Foo Inc.",
|
42
|
-
"custom_fields":
|
43
|
-
[
|
41
|
+
"custom_fields": [
|
44
42
|
{
|
45
43
|
"id": "1460591",
|
46
44
|
"name": "Email",
|
@@ -56,4 +54,4 @@
|
|
56
54
|
}
|
57
55
|
]
|
58
56
|
}
|
59
|
-
}
|
57
|
+
}
|
@@ -7,12 +7,11 @@
|
|
7
7
|
"account_id": "8195968",
|
8
8
|
"last_modified": 1423139130,
|
9
9
|
"company_name": "Foo Inc.",
|
10
|
-
"linked_leads_id":
|
11
|
-
|
12
|
-
|
10
|
+
"linked_leads_id": [
|
11
|
+
"1872746",
|
12
|
+
"1885024"
|
13
13
|
],
|
14
|
-
"custom_fields":
|
15
|
-
[
|
14
|
+
"custom_fields": [
|
16
15
|
{
|
17
16
|
"id": "1460591",
|
18
17
|
"name": "Email",
|
@@ -39,4 +38,4 @@
|
|
39
38
|
}
|
40
39
|
]
|
41
40
|
}
|
42
|
-
}
|
41
|
+
}
|
@@ -0,0 +1,73 @@
|
|
1
|
+
{
|
2
|
+
"response": {
|
3
|
+
"leads": [
|
4
|
+
{
|
5
|
+
"id": "1",
|
6
|
+
"name": "Research new technologies",
|
7
|
+
"last_modified": 1374656336,
|
8
|
+
"status_id": "7046196",
|
9
|
+
"pipeline_id": 683506,
|
10
|
+
"price": "500000",
|
11
|
+
"responsible_user_id": "103586",
|
12
|
+
"tags": [
|
13
|
+
{
|
14
|
+
"id": "960472",
|
15
|
+
"name": "USA"
|
16
|
+
},
|
17
|
+
{
|
18
|
+
"id": "960854",
|
19
|
+
"name": "Lead"
|
20
|
+
}
|
21
|
+
],
|
22
|
+
"date_create": 1386014400,
|
23
|
+
"account_id": "7046192",
|
24
|
+
"created_user_id": "4502311",
|
25
|
+
"custom_fields": [
|
26
|
+
{
|
27
|
+
"id": "484604",
|
28
|
+
"name": "field",
|
29
|
+
"values": [
|
30
|
+
{
|
31
|
+
"value": "text"
|
32
|
+
}
|
33
|
+
]
|
34
|
+
}
|
35
|
+
]
|
36
|
+
},
|
37
|
+
{
|
38
|
+
"id": "2",
|
39
|
+
"name": "Sell it!",
|
40
|
+
"last_modified": 1374656336,
|
41
|
+
"status_id": "7046196",
|
42
|
+
"pipeline_id": 683506,
|
43
|
+
"price": "100000",
|
44
|
+
"responsible_user_id": "103586",
|
45
|
+
"tags": [
|
46
|
+
{
|
47
|
+
"id": "960472",
|
48
|
+
"name": "USA"
|
49
|
+
},
|
50
|
+
{
|
51
|
+
"id": "960854",
|
52
|
+
"name": "Lead"
|
53
|
+
}
|
54
|
+
],
|
55
|
+
"date_create": 1386014400,
|
56
|
+
"account_id": "7046192",
|
57
|
+
"created_user_id": "4502311",
|
58
|
+
"custom_fields": [
|
59
|
+
{
|
60
|
+
"id": "484604",
|
61
|
+
"name": "field",
|
62
|
+
"values": [
|
63
|
+
{
|
64
|
+
"value": "text"
|
65
|
+
}
|
66
|
+
]
|
67
|
+
}
|
68
|
+
]
|
69
|
+
}
|
70
|
+
],
|
71
|
+
"server_time": 1374839787
|
72
|
+
}
|
73
|
+
}
|