amorail 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/amorail/entities/company.rb +1 -1
- data/lib/amorail/entities/contact.rb +7 -2
- data/lib/amorail/entities/lead.rb +1 -1
- data/lib/amorail/entities/leadable.rb +9 -1
- data/lib/amorail/entities/task.rb +1 -1
- data/lib/amorail/entity/finders.rb +1 -1
- data/lib/amorail/entity/params.rb +1 -1
- data/lib/amorail/entity/persistance.rb +6 -1
- data/lib/amorail/entity.rb +1 -1
- data/lib/amorail/version.rb +1 -1
- data/spec/company_spec.rb +3 -1
- data/spec/contact_spec.rb +6 -2
- data/spec/entity_spec.rb +1 -1
- data/spec/lead_spec.rb +1 -1
- data/spec/support/leadable_example.rb +14 -0
- data/spec/task_spec.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 151952934c801a5cce9b699869f1e46bd88f4e6a
|
4
|
+
data.tar.gz: 9ed39010c5f080bd68c07d35fc3434edba549b4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a11232b9fbc2f0b93f87d90e14c8ac068dff7281e732727156229708e3cb8bb0f1406840922ad203f41cbd451bd0d926e75d46c1c37a3f2893ff20a65d100069
|
7
|
+
data.tar.gz: 0eba066877b078d2676e0c9896b5c36a6a9451cf5894c4cabe0b83377c2d65b528970e8bc5bfc2cdd7e2185d789136fb8db8ce0faa2034181b624bd03997dce8
|
@@ -2,16 +2,21 @@ require 'amorail/entities/leadable'
|
|
2
2
|
|
3
3
|
module Amorail
|
4
4
|
# AmoCRM contact entity
|
5
|
-
class
|
5
|
+
class Contact < Amorail::Entity
|
6
6
|
include Leadable
|
7
7
|
amo_names 'contacts'
|
8
8
|
|
9
|
-
amo_field :name, :company_name
|
9
|
+
amo_field :name, :company_name, :linked_company_id
|
10
10
|
|
11
11
|
amo_property :email, enum: 'WORK'
|
12
12
|
amo_property :phone, enum: 'MOB'
|
13
13
|
amo_property :position
|
14
14
|
|
15
15
|
validates :name, presence: true
|
16
|
+
|
17
|
+
def company
|
18
|
+
return if linked_company_id.nil?
|
19
|
+
@company ||= Amorail::Company.find(linked_company_id)
|
20
|
+
end
|
16
21
|
end
|
17
22
|
end
|
@@ -1,6 +1,14 @@
|
|
1
1
|
module Amorail
|
2
2
|
# Lead associations
|
3
3
|
module Leadable
|
4
|
-
|
4
|
+
def linked_leads_id
|
5
|
+
@linked_leads_id ||= []
|
6
|
+
end
|
7
|
+
|
8
|
+
def params
|
9
|
+
data = super
|
10
|
+
data[:linked_leads_id] = linked_leads_id unless linked_leads_id.empty?
|
11
|
+
data
|
12
|
+
end
|
5
13
|
end
|
6
14
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Amorail # :nodoc: all
|
2
|
-
class
|
2
|
+
class Entity
|
3
3
|
class InvalidRecord < ::Amorail::Error; end
|
4
4
|
class NotPersisted < ::Amorail::Error; end
|
5
5
|
|
@@ -38,6 +38,11 @@ module Amorail # :nodoc: all
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
def reload
|
42
|
+
fail NotPersisted if id.nil?
|
43
|
+
load_record(id)
|
44
|
+
end
|
45
|
+
|
41
46
|
private
|
42
47
|
|
43
48
|
def extract_data_add(response)
|
data/lib/amorail/entity.rb
CHANGED
data/lib/amorail/version.rb
CHANGED
data/spec/company_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe Amorail::
|
3
|
+
describe Amorail::Company do
|
4
4
|
before { mock_api }
|
5
5
|
|
6
6
|
describe "validations" do
|
@@ -65,6 +65,8 @@ describe Amorail::AmoCompany do
|
|
65
65
|
expect(prop).not_to be_nil
|
66
66
|
expect(prop[:values].first[:value]).to eq 'hoohle.com'
|
67
67
|
end
|
68
|
+
|
69
|
+
it_behaves_like 'leadable'
|
68
70
|
end
|
69
71
|
|
70
72
|
describe "#save" do
|
data/spec/contact_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe Amorail::
|
3
|
+
describe Amorail::Contact do
|
4
4
|
before { mock_api }
|
5
5
|
|
6
6
|
let(:contact) { described_class.new(name: "test") }
|
@@ -28,6 +28,7 @@ describe Amorail::AmoContact do
|
|
28
28
|
described_class.new(
|
29
29
|
name: 'Tester',
|
30
30
|
company_name: 'Test inc',
|
31
|
+
linked_company_id: 123,
|
31
32
|
phone: '12345678',
|
32
33
|
email: 'test@mala.ru',
|
33
34
|
position: 'CEO'
|
@@ -39,6 +40,7 @@ describe Amorail::AmoContact do
|
|
39
40
|
specify { is_expected.to include(:last_modified) }
|
40
41
|
specify { is_expected.to include(name: 'Tester') }
|
41
42
|
specify { is_expected.to include(company_name: 'Test inc') }
|
43
|
+
specify { is_expected.to include(linked_company_id: 123) }
|
42
44
|
|
43
45
|
it "contains email property" do
|
44
46
|
prop = subject[:custom_fields].detect { |p| p[:id] == "1460591" }
|
@@ -61,6 +63,8 @@ describe Amorail::AmoContact do
|
|
61
63
|
expect(prop).not_to be_nil
|
62
64
|
expect(prop[:values].first[:value]).to eq 'CEO'
|
63
65
|
end
|
66
|
+
|
67
|
+
it_behaves_like 'leadable'
|
64
68
|
end
|
65
69
|
|
66
70
|
describe ".find" do
|
@@ -83,7 +87,7 @@ describe Amorail::AmoContact do
|
|
83
87
|
|
84
88
|
it "raise error" do
|
85
89
|
expect { described_class.find!(102) }
|
86
|
-
.to raise_error(Amorail::
|
90
|
+
.to raise_error(Amorail::Entity::RecordNotFound)
|
87
91
|
end
|
88
92
|
end
|
89
93
|
|
data/spec/entity_spec.rb
CHANGED
data/spec/lead_spec.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'leadable' do
|
4
|
+
let(:leadable) { described_class.new }
|
5
|
+
subject { leadable.params }
|
6
|
+
|
7
|
+
specify { is_expected.not_to include(:linked_leads_id) }
|
8
|
+
|
9
|
+
context 'with leads' do
|
10
|
+
before { leadable.linked_leads_id << 100 }
|
11
|
+
specify { is_expected.to include(:linked_leads_id) }
|
12
|
+
specify { expect(subject.fetch(:linked_leads_id)).to include(100) }
|
13
|
+
end
|
14
|
+
end
|
data/spec/task_spec.rb
CHANGED
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.1.
|
4
|
+
version: 0.1.6
|
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: 2015-04-
|
12
|
+
date: 2015-04-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -219,6 +219,7 @@ files:
|
|
219
219
|
- spec/property_spec.rb
|
220
220
|
- spec/spec_helper.rb
|
221
221
|
- spec/support/entity_class_example.rb
|
222
|
+
- spec/support/leadable_example.rb
|
222
223
|
- spec/task_spec.rb
|
223
224
|
homepage: ''
|
224
225
|
licenses:
|
@@ -259,5 +260,6 @@ test_files:
|
|
259
260
|
- spec/property_spec.rb
|
260
261
|
- spec/spec_helper.rb
|
261
262
|
- spec/support/entity_class_example.rb
|
263
|
+
- spec/support/leadable_example.rb
|
262
264
|
- spec/task_spec.rb
|
263
265
|
has_rdoc:
|