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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b18605e272eb7a0c72af69e2d017f54753ff715d474d79cc9071791a036cd6d
4
- data.tar.gz: d77fee259b877786fd18a044aaa52aff432be6936834095b5d8ab2d857d0df11
3
+ metadata.gz: bbc85a53892ba746e91fb6b52a9d86dedfa4c2885bc550760797cea6b6c1077a
4
+ data.tar.gz: ef947d63cdb4556d3d37934bf7ff6a4298c529b3692ee2617b207737f460b9ad
5
5
  SHA512:
6
- metadata.gz: ab1e1221b40f406909ed76f4b444b7f7f7805d8f04c1e386030563471172175149ff718438bb4ee97d9bee28f2a3d9b9a78733828f8ab2d7b62edca6f631f56e
7
- data.tar.gz: 4034fbcc9fea9004e159e62ac910ce9bfbe301ea76013f7d62d05a26cae8df2084c2836a4e4c65707cc4451fc8380fc163c5afe580068bdb8c4a40f79f632ff3
6
+ metadata.gz: 92801120cb72d28e30df5d41ee23cf2f89681eec639f6837d75302204ab0b49d0b1bfffdd2ea544fad88a6e57939b2bfc8ddd1305c439ab4ff4c31b8206f998c
7
+ data.tar.gz: 532f646b965c0f92f7a4e6174932a97e1c0fb023fbfa4d4b2fea1d3d348361e3885ef671fbd0e165c00c274c136fe6d39dc628904e6487cd447375e576782db7
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 0.7.1 (2021-09-25)
6
+
7
+ ### Features
8
+
9
+ - Adds multiple option to property ([@lHydra][])
10
+
11
+ See spec/support/my_contact.rb and spec/my_contact_spec.rb
12
+
5
13
  ## 0.7.0 (2021-07-16)
6
14
 
7
15
  ### Features
@@ -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
- prop_val = { value: send(v.fetch(:method_name, k)) }.merge(v)
27
- custom_fields << { id: prop_id, values: [prop_val] }
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
@@ -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
- attr_accessor(options.fetch(:method_name, name))
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').first.fetch('value')
102
+ fval = f.fetch('values').pluck('value')
97
103
  send(fname, fval) if respond_to?(fname)
98
104
  end
99
105
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Amorail version
4
4
  module Amorail
5
- VERSION = '0.7.0'
5
+ VERSION = '0.7.1'
6
6
  end
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
@@ -27,6 +27,10 @@
27
27
  {
28
28
  "value": "1111 111 111",
29
29
  "enum": "3392086"
30
+ },
31
+ {
32
+ "value": "2222 222 222",
33
+ "enum": "3392086"
30
34
  }
31
35
  ]
32
36
  },
@@ -14,7 +14,7 @@ describe MyContact do
14
14
  end
15
15
 
16
16
  describe "#params" do
17
- let(:company) do
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 { company.params }
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
@@ -2,4 +2,5 @@
2
2
 
3
3
  class MyContact < Amorail::Contact # :nodoc:
4
4
  amo_property :teachbase_id
5
+ amo_property :phone, enum: 'MOB', multiple: true
5
6
  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.7.0
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-07-16 00:00:00.000000000 Z
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.0.8
298
+ rubygems_version: 3.2.22
299
299
  signing_key:
300
300
  specification_version: 4
301
301
  summary: Ruby API client for AmoCRM