amorail 0.1.5 → 0.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d0fe2be0f031e806dd9eac0da0ac09ee4a9b5d79
4
- data.tar.gz: ae1153aee232f6d0b30190a68e0e2b2e9d15cdd7
3
+ metadata.gz: 151952934c801a5cce9b699869f1e46bd88f4e6a
4
+ data.tar.gz: 9ed39010c5f080bd68c07d35fc3434edba549b4d
5
5
  SHA512:
6
- metadata.gz: 32b9fb3a98d3ac82dd40e9c7fd4f9aeb079d8f942a72f98428de7bf13712a1edea8d2b7562e16974d8ddadd4e80024e5119ca79d3e6cb6a7118535367922e312
7
- data.tar.gz: 224079bf6eb4bb040a72386fd589b0f4aca5bb76df7a1c69ba9e6cd923e9064db53ab3c8d7be3f941f891df2bfb0932b0e56499ba64b9c7637977eafedf2558c
6
+ metadata.gz: a11232b9fbc2f0b93f87d90e14c8ac068dff7281e732727156229708e3cb8bb0f1406840922ad203f41cbd451bd0d926e75d46c1c37a3f2893ff20a65d100069
7
+ data.tar.gz: 0eba066877b078d2676e0c9896b5c36a6a9451cf5894c4cabe0b83377c2d65b528970e8bc5bfc2cdd7e2185d789136fb8db8ce0faa2034181b624bd03997dce8
@@ -2,7 +2,7 @@ require 'amorail/entities/leadable'
2
2
 
3
3
  module Amorail
4
4
  # AmoCRM company entity
5
- class AmoCompany < Amorail::AmoEntity
5
+ class Company < Amorail::Entity
6
6
  include Leadable
7
7
  amo_names 'company', 'contacts'
8
8
 
@@ -2,16 +2,21 @@ require 'amorail/entities/leadable'
2
2
 
3
3
  module Amorail
4
4
  # AmoCRM contact entity
5
- class AmoContact < Amorail::AmoEntity
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,6 @@
1
1
  module Amorail
2
2
  # AmoCRM lead entity
3
- class AmoLead < Amorail::AmoEntity
3
+ class Lead < Amorail::Entity
4
4
  amo_names "leads"
5
5
 
6
6
  amo_field :name, :price, :status_id, :tags
@@ -1,6 +1,14 @@
1
1
  module Amorail
2
2
  # Lead associations
3
3
  module Leadable
4
- # TODO: !!!
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,6 +1,6 @@
1
1
  module Amorail
2
2
  # AmoCRM task entity
3
- class AmoTask < Amorail::AmoEntity
3
+ class Task < Amorail::Entity
4
4
  amo_names "tasks"
5
5
 
6
6
  amo_field :element_id, :element_type, :text,
@@ -1,5 +1,5 @@
1
1
  module Amorail # :nodoc: all
2
- class AmoEntity
2
+ class Entity
3
3
  class << self
4
4
  def find(id)
5
5
  new.load_record(id)
@@ -1,5 +1,5 @@
1
1
  module Amorail # :nodoc: all
2
- class AmoEntity
2
+ class Entity
3
3
  def params
4
4
  data = {}
5
5
  self.class.attributes.each do |k, v|
@@ -1,5 +1,5 @@
1
1
  module Amorail # :nodoc: all
2
- class AmoEntity
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)
@@ -2,7 +2,7 @@ require 'active_model'
2
2
 
3
3
  module Amorail
4
4
  # Core class for all Amo entities (company, contact, etc)
5
- class AmoEntity
5
+ class Entity
6
6
  include ActiveModel::Model
7
7
  include ActiveModel::AttributeMethods
8
8
  include ActiveModel::Validations
@@ -1,4 +1,4 @@
1
1
  # Amorail version
2
2
  module Amorail
3
- VERSION = "0.1.5"
3
+ VERSION = "0.1.6"
4
4
  end
data/spec/company_spec.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- describe Amorail::AmoCompany do
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::AmoContact do
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::AmoEntity::RecordNotFound)
90
+ .to raise_error(Amorail::Entity::RecordNotFound)
87
91
  end
88
92
  end
89
93
 
data/spec/entity_spec.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- describe Amorail::AmoEntity do
3
+ describe Amorail::Entity do
4
4
  before { mock_api }
5
5
 
6
6
  let(:entity) { described_class.new }
data/spec/lead_spec.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- describe Amorail::AmoLead do
3
+ describe Amorail::Lead do
4
4
  before { mock_api }
5
5
 
6
6
  describe "validations" do
@@ -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
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- describe Amorail::AmoTask do
3
+ describe Amorail::Task do
4
4
  before { mock_api }
5
5
 
6
6
  describe "validations" do
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.5
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-22 00:00:00.000000000 Z
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: