restforce-db 4.0.5 → 4.1.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: 2080427a96e971dd5a7e51f37f1f92a37dfd67cc
4
- data.tar.gz: 3bcb63d050a559cf47ffdc6ad782487b660be949
3
+ metadata.gz: 1dafd9fbdfa3ef1b8095e136a0491bca01cf3d73
4
+ data.tar.gz: 4d7c41b6ea229020fcc3886400053381bae6ba6f
5
5
  SHA512:
6
- metadata.gz: 27e915cb12532a8c2734b932fca192f01187ecea0ea762fe67795784bf927a975f6c657fe1c9dff5586e7029b333dbbe22aa07983fa69bf55889290ad82f817d
7
- data.tar.gz: 5683584abd9d6942b6b247f17210ffc00b651c38ca1afdecde053600fba506a821f85a0c64be9c06cee8389b2348f4e9dc55d7552fdb82fe2ee9782a16811092
6
+ metadata.gz: 38730782a910cc7fe92e45ea09d7dab57ac3b648246ff8a707ab84c5694394226bf32366f9250a386f3607a39a5d2813304ce3a79983949bcbc6ecd336db1f26
7
+ data.tar.gz: fc09fefbbe68a85c3a17bcd0967e657dcffec5d899d786127397909417e2c40596c9a3ca3de63368b87b6bcf75b2eb09a26f636900a26c85ef592eb5c4fb837b
data/lib/restforce/db.rb CHANGED
@@ -54,6 +54,10 @@ module Restforce
54
54
  # by the other classes in this library.
55
55
  module DB
56
56
 
57
+ # Internal: A String containing the valid suffix Hash values for a
58
+ # Salesforce ID.
59
+ HASH_DICTIONARY = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345".freeze
60
+
57
61
  class << self
58
62
 
59
63
  attr_accessor :last_run
@@ -140,6 +144,28 @@ module Restforce
140
144
  @last_run = nil
141
145
  end
142
146
 
147
+ # Public: Get the hashed version of the passed salesforce ID. This will
148
+ # converts 15-digit Salesforce IDs to their corresponding 18-digit version.
149
+ # Returns any passed 18-digit IDs back, untouched.
150
+ #
151
+ # Returns a String.
152
+ # Raises an ArgumentError if the passed String is not 15 characters.
153
+ def self.hashed_id(salesforce_id)
154
+ return salesforce_id if salesforce_id.length == 18
155
+ raise ArgumentError, "The passed Salesforce ID must be 15 or 18 characters" unless salesforce_id.length == 15
156
+
157
+ suffixes = salesforce_id.scan(/.{5}/).map do |chunk|
158
+ flag = 0
159
+ chunk.split("").each_with_index do |char, idx|
160
+ flag += (1 << idx) if char >= "A" && char <= "Z"
161
+ end
162
+
163
+ HASH_DICTIONARY[flag]
164
+ end
165
+
166
+ salesforce_id + suffixes.join
167
+ end
168
+
143
169
  end
144
170
 
145
171
  end
@@ -76,7 +76,7 @@ module Restforce
76
76
 
77
77
  true
78
78
  rescue Restforce::AuthenticationError => e
79
- error(e)
79
+ log e, :warn
80
80
  raise e
81
81
  rescue => e
82
82
  error(e)
@@ -3,7 +3,7 @@ module Restforce
3
3
  # :nodoc:
4
4
  module DB
5
5
 
6
- VERSION = "4.0.5"
6
+ VERSION = "4.1.0"
7
7
 
8
8
  end
9
9
 
@@ -48,19 +48,8 @@ namespace :restforce do
48
48
  desc "Get the 18-character version of a 15-character Salesforce ID"
49
49
  task :convertid, [:salesforce_id] do |_, args|
50
50
  sfid = args[:salesforce_id]
51
-
52
51
  raise ArgumentError, "Provide a Salesforce ID (restforce:convertid[<salesforce_id>])" if sfid.nil?
53
- raise ArgumentError, "The passed Salesforce ID must be 15 characters" unless sfid.length == 15
54
-
55
- suffixes = sfid.scan(/.{5}/).map do |chunk|
56
- flag = 0
57
- chunk.split("").each_with_index do |char, idx|
58
- flag += (1 << idx) if char.upcase == char && char >= "A" && char <= "Z"
59
- end
60
-
61
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345"[flag]
62
- end
63
52
 
64
- puts sfid + suffixes.join
53
+ puts Restforce::DB.hashed_id(sfid)
65
54
  end
66
55
  end
@@ -4,7 +4,7 @@ describe Restforce::DB do
4
4
 
5
5
  configure!
6
6
 
7
- describe "#configure" do
7
+ describe ".configure" do
8
8
 
9
9
  it "yields a Configuration" do
10
10
  Restforce::DB.configure do |config|
@@ -13,7 +13,7 @@ describe Restforce::DB do
13
13
  end
14
14
  end
15
15
 
16
- describe "#client" do
16
+ describe ".client" do
17
17
  before do
18
18
  Restforce::DB.configure do |config|
19
19
  config.adapter = :net_http
@@ -28,6 +28,26 @@ describe Restforce::DB do
28
28
  end
29
29
  end
30
30
 
31
+ describe ".hashed_id" do
32
+
33
+ it "returns an 18-character Salesforce ID untouched" do
34
+ expect(Restforce::DB.hashed_id("a001a000002zhZfAAI")).to_equal("a001a000002zhZfAAI")
35
+ end
36
+
37
+ it "generates a proper hash for a 15-character Salesforce ID" do
38
+ expect(Restforce::DB.hashed_id("aaaaaaaaaaaaaaa")).to_equal("aaaaaaaaaaaaaaaAAA")
39
+ expect(Restforce::DB.hashed_id("AaaAAAaaAAAaaAA")).to_equal("AaaAAAaaAAAaaAAZZZ")
40
+ expect(Restforce::DB.hashed_id("aAaAAaAaAAaAaAA")).to_equal("aAaAAaAaAAaAaAA000")
41
+ expect(Restforce::DB.hashed_id("AAAAAAAAAAAAAAA")).to_equal("AAAAAAAAAAAAAAA555")
42
+
43
+ expect(Restforce::DB.hashed_id("0063200001kSU3I")).to_equal("0063200001kSU3IAAW")
44
+ end
45
+
46
+ it "raises an ArgumentError if the passed String contains an invalid character count" do
47
+ expect { Restforce::DB.hashed_id("a001a000002zhZfA") }.to_raise(ArgumentError)
48
+ end
49
+ end
50
+
31
51
  describe "accessing Salesforce", :vcr do
32
52
 
33
53
  it "uses the configured credentials" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restforce-db
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.5
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Horner
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-23 00:00:00.000000000 Z
11
+ date: 2015-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord