infopark-crm-helpers 1.1.2 → 1.2.0

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
  SHA1:
3
- metadata.gz: bb63ae5a4590645428d46a6ac235889da495c0b1
4
- data.tar.gz: a8611eca47ea064477f006463292432c5dae81b1
3
+ metadata.gz: 86190b91f7620b14f27ce65893bfe4b110f9f154
4
+ data.tar.gz: c0f1b7f4bac3159d72d01965d3c4068b56fe6480
5
5
  SHA512:
6
- metadata.gz: 0a7137e219dcd868f70b1eecaf1fb30bfae7a8c6cd431e458efff73263189198ff085946cead4e7e59417868e50c56fe6ab588c3a4afe4ab00c8a4abde8cf494
7
- data.tar.gz: f8cafd1a3bf633720296f088c039c374a252683914f3a4f56ed8d253dade1a338c77a9de6a2ef1e10ea64633b99c8166ceae87fd298dbf9af18a3d05b8caf66f
6
+ metadata.gz: e50253841239385681318330017c7a402aa2b5a213bceedc7687317746e767dc925b5043b71c1eebe10bb489a62d98ec70f8cf184e78a05b457f2fe61986fa31
7
+ data.tar.gz: 486d0b1e84a220edd6cbbae00d58e474e90446e8a0b30747341a57656c05316d8f6949ac330d13afe38ec54a4a0a0a528b0f128f645c5c5b61f2f7341951bc2a
data/.travis.yml CHANGED
@@ -16,6 +16,7 @@ env:
16
16
  - secure: "dRGHULKMHj8/9Y7L1JMc+RwjD6c+djCBvQsewVGII+a5loiRQFV72zb5Td0JBPzGI2K1t3EXc2F8X8D+1QR+jpb0SFFSAUHzb2mvWU+FPixHfTxAPpktfiT+qAHFPkeaQMY86ktosE50+J555ke8YbtRKIBsqDbvZU+vnr3N6Ui4JhomCPMyCmnuFFATHoGBdhcrvWc1vY1Z7gK/qd0nhgyDb+sfOnbLinz7qR4oEI2nbGA6z5AzwfbD4JkXqagPirQy2tUJGAY71QVpDevg3qjfV2Hb9Ow1ESW9M0DsZZjFXXx6VJ4z9xikaqdauUMcJSCNMXtSK6OIUiy7Ln+WQKjDuGLxOLpG5oUxV7FrKEp63cQX9+6BDEPRuilwumZMBP0goE0kMFZmjai1bm3sMCddm08i05w9NraswxRHElBlPQxAXCDtiEQR2PKkI0G9j1/OheTvxn73GK0owPA6aOpOn52Jp+nwt8llZzPCLMvax4CmECESRvIJ7MN+ye1yre4IopXnbdZhHo/eoeGO0WTZL/t3qrmjGPyTljTkwGgp3LI+NxIoZG6UjOo2WJb6A3D8eZRbmMphZns1j7zcSUrCRNmpS6UmPsG1jExz+65LMSbScMs5xvCEtyW1X7qznf1NKLsfJxQUF3LlLSUrp/LoSTaDsrcR0E9qU9xt7/c="
17
17
 
18
18
  matrix:
19
+ - 'RAILS_VERSION=5.0.0'
19
20
  - 'RAILS_VERSION=4.2.0'
20
21
  - 'RAILS_VERSION=4.1.0'
21
22
  - 'RAILS_VERSION=4.0.0'
data/changelog.md CHANGED
@@ -1,3 +1,8 @@
1
+ ### 1.2.0
2
+
3
+ - `.find` (from `Crm::Helpers::Finders`) is capable of fetching multiple CRM objects for multiple CRM ids.
4
+ - Added support for Rails 5.0.x.
5
+
1
6
  ### 1.1.2
2
7
 
3
8
  - Use `valid_values` of a `language` attribute provided by `Crm::Type#standard_attribute_definitions`, now that the `valid_values` array contains the correct values.
@@ -5,7 +5,7 @@ require 'crm/helpers/version'
5
5
 
6
6
  rails_version = ENV['RAILS_VERSION'] || 'default'
7
7
  rails = case rails_version
8
- when 'default' then '~> 4.0'
8
+ when 'default' then '~> 5.0'
9
9
  else "~> #{rails_version}"
10
10
  end
11
11
 
@@ -5,11 +5,19 @@ module Crm
5
5
  base.extend self
6
6
  end
7
7
 
8
- def find(id)
9
- crm_object = crm_class.find(id)
10
- return nil if crm_object.blank?
8
+ def find(*args)
9
+ wants_array = args.first.is_a?(Array)
10
+ ids = args.flatten
11
11
 
12
- new(crm_object.attributes)
12
+ case ids.size
13
+ when 0
14
+ raise ArgumentError.new('Requires one or more IDs as argument.')
15
+ when 1
16
+ crm_object = find_one(ids.first)
17
+ wants_array ? [crm_object].compact : crm_object
18
+ else
19
+ find_many(ids)
20
+ end
13
21
  end
14
22
 
15
23
  def find_by_query(query, options = {})
@@ -20,6 +28,25 @@ module Crm
20
28
  new(crm_object.attributes)
21
29
  end
22
30
  end
31
+
32
+ protected
33
+
34
+ def find_one(id)
35
+ crm_object = crm_class.find(id)
36
+ return nil if crm_object.blank?
37
+
38
+ new(crm_object.attributes)
39
+ end
40
+
41
+ def find_many(ids)
42
+ crm_objects = Crm.find(ids).select do |crm_object|
43
+ crm_object.is_a?(crm_class)
44
+ end
45
+ unknown_ids = ids - crm_objects.map(&:id)
46
+ raise Errors::ResourceNotFound.new('Items could not be found.', unknown_ids) if unknown_ids.present?
47
+
48
+ crm_objects.map { |crm_object| new(crm_object.attributes) }
49
+ end
23
50
  end
24
51
  end
25
52
  end
@@ -1,5 +1,5 @@
1
1
  module Crm
2
2
  module Helpers
3
- VERSION = '1.1.2'.freeze
3
+ VERSION = '1.2.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infopark-crm-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Huy Dinh
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-02 00:00:00.000000000 Z
11
+ date: 2016-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: '5.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '4.0'
26
+ version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activemodel
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '4.0'
33
+ version: '5.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '4.0'
40
+ version: '5.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: infopark_webcrm_sdk
43
43
  requirement: !ruby/object:Gem::Requirement