amorail 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/amorail/entity/params.rb +11 -2
- data/lib/amorail/entity.rb +8 -2
- data/lib/amorail/version.rb +1 -1
- data/spec/contact_spec.rb +2 -0
- data/spec/fixtures/contacts/my_contact_find.json +4 -0
- data/spec/my_contact_spec.rb +3 -2
- data/spec/support/my_contact.rb +1 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbc85a53892ba746e91fb6b52a9d86dedfa4c2885bc550760797cea6b6c1077a
|
4
|
+
data.tar.gz: ef947d63cdb4556d3d37934bf7ff6a4298c529b3692ee2617b207737f460b9ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92801120cb72d28e30df5d41ee23cf2f89681eec639f6837d75302204ab0b49d0b1bfffdd2ea544fad88a6e57939b2bfc8ddd1305c439ab4ff4c31b8206f998c
|
7
|
+
data.tar.gz: 532f646b965c0f92f7a4e6174932a97e1c0fb023fbfa4d4b2fea1d3d348361e3885ef671fbd0e165c00c274c136fe6d39dc628904e6487cd447375e576782db7
|
data/CHANGELOG.md
CHANGED
@@ -23,8 +23,17 @@ module Amorail # :nodoc: all
|
|
23
23
|
custom_fields = []
|
24
24
|
self.class.properties.each do |k, v|
|
25
25
|
prop_id = props.send(k).id
|
26
|
-
|
27
|
-
|
26
|
+
prop_values = send(v.fetch(:method_name, k))
|
27
|
+
|
28
|
+
if prop_values.is_a?(Array)
|
29
|
+
prop_val = prop_values.map do |value|
|
30
|
+
{ value: value }.merge(v)
|
31
|
+
end
|
32
|
+
else
|
33
|
+
prop_val = [{ value: prop_values }.merge(v)]
|
34
|
+
end
|
35
|
+
|
36
|
+
custom_fields << { id: prop_id, values: prop_val }
|
28
37
|
end
|
29
38
|
|
30
39
|
custom_fields
|
data/lib/amorail/entity.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'active_model'
|
4
|
+
require 'active_support/core_ext/array'
|
4
5
|
|
5
6
|
module Amorail
|
6
7
|
# Core class for all Amo entities (company, contact, etc)
|
@@ -34,7 +35,12 @@ module Amorail
|
|
34
35
|
|
35
36
|
def amo_property(name, options = {})
|
36
37
|
properties[name] = options
|
37
|
-
|
38
|
+
var_name = options.fetch(:method_name, name)
|
39
|
+
define_method "#{var_name}=" do |value|
|
40
|
+
var_value = options[:multiple] ? Array.wrap(value) : Array.wrap(value).first
|
41
|
+
instance_variable_set("@#{var_name}", var_value)
|
42
|
+
end
|
43
|
+
attr_reader(var_name)
|
38
44
|
end
|
39
45
|
|
40
46
|
def attributes
|
@@ -93,7 +99,7 @@ module Amorail
|
|
93
99
|
next if fname.nil?
|
94
100
|
|
95
101
|
fname = "#{fname.downcase}="
|
96
|
-
fval = f.fetch('values').
|
102
|
+
fval = f.fetch('values').pluck('value')
|
97
103
|
send(fname, fval) if respond_to?(fname)
|
98
104
|
end
|
99
105
|
end
|
data/lib/amorail/version.rb
CHANGED
data/spec/contact_spec.rb
CHANGED
@@ -168,10 +168,12 @@ describe Amorail::Contact do
|
|
168
168
|
it "update params" do
|
169
169
|
contact.save!
|
170
170
|
contact.name = "foo"
|
171
|
+
contact.phone = "123456789"
|
171
172
|
|
172
173
|
contact_update_stub(Amorail.config.api_endpoint)
|
173
174
|
expect(contact.save!).to be_truthy
|
174
175
|
expect(contact.name).to eq "foo"
|
176
|
+
expect(contact.phone).to eq "123456789"
|
175
177
|
end
|
176
178
|
|
177
179
|
it "raise error if id is blank?" do
|
data/spec/my_contact_spec.rb
CHANGED
@@ -14,7 +14,7 @@ describe MyContact do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
describe "#params" do
|
17
|
-
let(:
|
17
|
+
let(:contact) do
|
18
18
|
described_class.new(
|
19
19
|
name: 'Test inc',
|
20
20
|
phone: '12345678',
|
@@ -23,7 +23,7 @@ describe MyContact do
|
|
23
23
|
)
|
24
24
|
end
|
25
25
|
|
26
|
-
subject {
|
26
|
+
subject { contact.params }
|
27
27
|
|
28
28
|
specify { is_expected.to include(:last_modified) }
|
29
29
|
specify { is_expected.to include(name: 'Test inc') }
|
@@ -43,6 +43,7 @@ describe MyContact do
|
|
43
43
|
expect(obj.id).to eq 11
|
44
44
|
expect(obj.company_name).to eq "Foo Inc."
|
45
45
|
expect(obj.email).to eq "foo@tb.com"
|
46
|
+
expect(obj.phone).to eq ["1111 111 111", "2222 222 222"]
|
46
47
|
expect(obj.teachbase_id).to eq 1123
|
47
48
|
expect(obj.params[:id]).to eq 11
|
48
49
|
end
|
data/spec/support/my_contact.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.7.
|
4
|
+
version: 0.7.1
|
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: 2021-
|
12
|
+
date: 2021-09-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -295,7 +295,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
295
295
|
- !ruby/object:Gem::Version
|
296
296
|
version: '0'
|
297
297
|
requirements: []
|
298
|
-
rubygems_version: 3.
|
298
|
+
rubygems_version: 3.2.22
|
299
299
|
signing_key:
|
300
300
|
specification_version: 4
|
301
301
|
summary: Ruby API client for AmoCRM
|