restforce 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of restforce might be problematic. Click here for more details.
- data/CHANGELOG.md +53 -0
- data/README.md +25 -1
- data/lib/restforce.rb +3 -2
- data/lib/restforce/client.rb +2 -0
- data/lib/restforce/client/picklists.rb +90 -0
- data/lib/restforce/mash.rb +1 -1
- data/lib/restforce/version.rb +1 -1
- data/spec/fixtures/sobject/sobject_describe_success_response.json +58 -0
- data/spec/lib/client_spec.rb +42 -0
- metadata +4 -3
data/CHANGELOG.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
## 1.0.5 (Jan 11, 2013)
|
2
|
+
|
3
|
+
* Added `picklist_values` method.
|
4
|
+
|
5
|
+
Example
|
6
|
+
|
7
|
+
client.picklist_values('Account', 'Type')
|
8
|
+
|
9
|
+
client.picklist_values('Automobile__c', 'Model__c', :valid_for => 'Honda')
|
10
|
+
|
11
|
+
* Added CHANGELOG.md
|
12
|
+
|
13
|
+
## 1.0.4 (Jan 8, 2013)
|
14
|
+
|
15
|
+
* `Restforce::Client#inspect` now only prints out the options and not the
|
16
|
+
Faraday connection.
|
17
|
+
|
18
|
+
* The Faraday adapter is now configurabled:
|
19
|
+
|
20
|
+
Example:
|
21
|
+
|
22
|
+
Restforce.configure do |config|
|
23
|
+
config.adapter = :excon
|
24
|
+
end
|
25
|
+
|
26
|
+
* The http connection read/open timeout is now configurabled.
|
27
|
+
|
28
|
+
Example:
|
29
|
+
|
30
|
+
Restforce.configure do |config|
|
31
|
+
config.timeout = 300
|
32
|
+
end
|
33
|
+
|
34
|
+
## 1.0.3 (Jan 7, 2013)
|
35
|
+
|
36
|
+
* Fixed typo in method call.
|
37
|
+
|
38
|
+
## 1.0.2 (Jan 7, 2013)
|
39
|
+
|
40
|
+
* Minor cleanup.
|
41
|
+
* Moved decoding of signed requests into it's own class.
|
42
|
+
|
43
|
+
## 1.0.1 (Dec 31, 2012)
|
44
|
+
|
45
|
+
* `username`, `password`, `security_token`, `client_id` and `client_secret`
|
46
|
+
options now obtain defaults from environment variables.
|
47
|
+
* Add `head` verb.
|
48
|
+
|
49
|
+
## 1.0.0 (Dec 23, 2012)
|
50
|
+
|
51
|
+
* Default api version changed from 24.0 to 26.0.
|
52
|
+
* Fixed tests for streaming api to work with latest versions of faye.
|
53
|
+
* Added .find method to obtain all fields from an sobject.
|
data/README.md
CHANGED
@@ -16,9 +16,10 @@ Features include:
|
|
16
16
|
* Support for blob data types.
|
17
17
|
* Support for GZIP compression.
|
18
18
|
* Support for [custom Apex REST endpoints](#custom-apex-rest-endpoints).
|
19
|
+
* Support for dependent picklists.
|
19
20
|
* Support for decoding [Force.com Canvas](http://www.salesforce.com/us/developer/docs/platform_connectpre/canvas_framework.pdf) signed requests. (NEW!)
|
20
21
|
|
21
|
-
[Documentation](http://rubydoc.info/gems/restforce/frames) | [Changelog](
|
22
|
+
[Documentation](http://rubydoc.info/gems/restforce/frames) | [Changelog](https://github.com/ejholmes/restforce/tree/master/CHANGELOG.md)
|
22
23
|
|
23
24
|
## Installation
|
24
25
|
|
@@ -274,6 +275,29 @@ _See also: http://www.salesforce.com/us/developer/docs/api_rest/Content/dome_des
|
|
274
275
|
|
275
276
|
* * *
|
276
277
|
|
278
|
+
### picklist\_values(sobject, field, options = {})
|
279
|
+
|
280
|
+
Takes the name of an sobject and the name of a picklist field and returns the
|
281
|
+
valid picklist values for that field.
|
282
|
+
|
283
|
+
If a :valid\_for key is specified in the options, it will filter the picklist
|
284
|
+
values to only return picklist values that are valid for the controlling
|
285
|
+
picklist field.
|
286
|
+
|
287
|
+
|
288
|
+
```ruby
|
289
|
+
client.picklist_values('Account', 'Type')
|
290
|
+
# => [#<Restforce::Mash label="Prospect" value="Prospect">]
|
291
|
+
|
292
|
+
# Given a custom object named Automobile__c with picklist fields
|
293
|
+
# Model__c and Make__c, where Model__c depends on the value of
|
294
|
+
# Make__c.
|
295
|
+
client.picklist_values('Automobile__c', 'Model__c', :valid_for => 'Honda')
|
296
|
+
# => [#<Restforce::Mash label="Civic" value="Civic">, ... ]
|
297
|
+
```
|
298
|
+
|
299
|
+
* * *
|
300
|
+
|
277
301
|
### authenticate!
|
278
302
|
|
279
303
|
Performs an authentication and returns the response. In general, calling this
|
data/lib/restforce.rb
CHANGED
@@ -25,8 +25,9 @@ module Restforce
|
|
25
25
|
Restforce::Client.new(options)
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
# Helper for decoding signed requests.
|
29
|
+
def decode_signed_request(*args)
|
30
|
+
SignedRequest.decode(*args)
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
data/lib/restforce/client.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'restforce/client/connection'
|
2
2
|
require 'restforce/client/authentication'
|
3
3
|
require 'restforce/client/streaming'
|
4
|
+
require 'restforce/client/picklists'
|
4
5
|
require 'restforce/client/caching'
|
5
6
|
require 'restforce/client/canvas'
|
6
7
|
require 'restforce/client/api'
|
@@ -10,6 +11,7 @@ module Restforce
|
|
10
11
|
include Restforce::Client::Connection
|
11
12
|
include Restforce::Client::Authentication
|
12
13
|
include Restforce::Client::Streaming
|
14
|
+
include Restforce::Client::Picklists
|
13
15
|
include Restforce::Client::Caching
|
14
16
|
include Restforce::Client::Canvas
|
15
17
|
include Restforce::Client::API
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module Restforce
|
2
|
+
class Client
|
3
|
+
module Picklists
|
4
|
+
|
5
|
+
# Public: Get the available picklist values for a picklist or multipicklist field.
|
6
|
+
#
|
7
|
+
# sobject - The String name of the sobject.
|
8
|
+
# field - The String name of the picklist/multipicklist field.
|
9
|
+
# options - A hash of options. (default: {}).
|
10
|
+
# :valid_for - If specified, will only return picklist values
|
11
|
+
# that are valid for the controlling picklist
|
12
|
+
# value
|
13
|
+
#
|
14
|
+
# Examples
|
15
|
+
#
|
16
|
+
# client.picklist_values('Account', 'Type')
|
17
|
+
# # => [#<Restforce::Mash label="Prospect" value="Prospect">]
|
18
|
+
#
|
19
|
+
# # Given a custom object named Automobile__c with picklist fields
|
20
|
+
# # Model__c and Make__c, where Model__c depends on the value of
|
21
|
+
# # Make__c.
|
22
|
+
# client.picklist_values('Automobile__c', 'Model__c', :valid_for => 'Honda')
|
23
|
+
# # => [#<Restforce::Mash label="Civic" value="Civic">, ... ]
|
24
|
+
#
|
25
|
+
# Returns an array of Restforce::Mash objects.
|
26
|
+
def picklist_values(sobject, field, options = {})
|
27
|
+
PicklistValues.new(describe(sobject)['fields'], field, options)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
class PicklistValues < Array
|
33
|
+
|
34
|
+
def initialize(fields, field, options = {})
|
35
|
+
@fields, @field = fields, field
|
36
|
+
@valid_for = options.delete(:valid_for)
|
37
|
+
raise "#{field} is not a dependent picklist" if @valid_for && !dependent?
|
38
|
+
replace(picklist_values)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
attr_reader :fields
|
44
|
+
|
45
|
+
def picklist_values
|
46
|
+
if valid_for?
|
47
|
+
field['picklistValues'].select { |picklist_entry| valid? picklist_entry }
|
48
|
+
else
|
49
|
+
field['picklistValues']
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Returns true of the given field is dependent on another field.
|
54
|
+
def dependent?
|
55
|
+
!!field['dependentPicklist']
|
56
|
+
end
|
57
|
+
|
58
|
+
def valid_for?
|
59
|
+
!!@valid_for
|
60
|
+
end
|
61
|
+
|
62
|
+
def controlling_picklist
|
63
|
+
@_controlling_picklist ||= controlling_field['picklistValues'].find { |picklist_entry| picklist_entry['value'] == @valid_for }
|
64
|
+
end
|
65
|
+
|
66
|
+
def index
|
67
|
+
@_index ||= controlling_field['picklistValues'].index(controlling_picklist)
|
68
|
+
end
|
69
|
+
|
70
|
+
def controlling_field
|
71
|
+
@_controlling_field ||= fields.find { |f| f['name'] == field['controllerName'] }
|
72
|
+
end
|
73
|
+
|
74
|
+
def field
|
75
|
+
@_field ||= fields.find { |f| f['name'] == @field }
|
76
|
+
end
|
77
|
+
|
78
|
+
# Returns true if the picklist entry is valid for the controlling picklist.
|
79
|
+
#
|
80
|
+
# See http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_describesobjects_describesobjectresult.htm
|
81
|
+
def valid?(picklist_entry)
|
82
|
+
valid_for = picklist_entry['validFor'].ljust(16, 'A').unpack('m').first.unpack('q*')
|
83
|
+
(valid_for[index >> 3] & (0x80 >> index % 8)) != 0
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/lib/restforce/mash.rb
CHANGED
@@ -10,7 +10,7 @@ module Restforce
|
|
10
10
|
# Restforce::Mash objects.
|
11
11
|
def build(val, client)
|
12
12
|
if val.is_a?(Array)
|
13
|
-
val.collect { |
|
13
|
+
val.collect { |val| self.build(val, client) }
|
14
14
|
elsif val.is_a?(Hash)
|
15
15
|
self.klass(val).new(val, client)
|
16
16
|
else
|
data/lib/restforce/version.rb
CHANGED
@@ -837,6 +837,64 @@
|
|
837
837
|
"writeRequiresMasterRead" : false,
|
838
838
|
"sortable" : false
|
839
839
|
}, {
|
840
|
+
"length" : 255,
|
841
|
+
"name" : "Dependent_Picklist_Field",
|
842
|
+
"type" : "picklist",
|
843
|
+
"defaultValue" : null,
|
844
|
+
"label" : "Dependent Picklist Label",
|
845
|
+
"updateable" : true,
|
846
|
+
"calculated" : false,
|
847
|
+
"controllerName" : "Picklist_Field",
|
848
|
+
"nillable" : true,
|
849
|
+
"unique" : false,
|
850
|
+
"precision" : 0,
|
851
|
+
"scale" : 0,
|
852
|
+
"caseSensitive" : false,
|
853
|
+
"byteLength" : 765,
|
854
|
+
"inlineHelpText" : null,
|
855
|
+
"nameField" : false,
|
856
|
+
"externalId" : false,
|
857
|
+
"idLookup" : false,
|
858
|
+
"filterable" : true,
|
859
|
+
"soapType" : "xsd:string",
|
860
|
+
"createable" : true,
|
861
|
+
"deprecatedAndHidden" : false,
|
862
|
+
"autoNumber" : false,
|
863
|
+
"calculatedFormula" : null,
|
864
|
+
"defaultValueFormula" : null,
|
865
|
+
"defaultedOnCreate" : false,
|
866
|
+
"digits" : 0,
|
867
|
+
"groupable" : true,
|
868
|
+
"picklistValues" : [ {
|
869
|
+
"value" : "seven",
|
870
|
+
"active" : true,
|
871
|
+
"label" : "seven",
|
872
|
+
"defaultValue" : false,
|
873
|
+
"validFor" : "gAAA"
|
874
|
+
}, {
|
875
|
+
"value" : "eight",
|
876
|
+
"active" : true,
|
877
|
+
"label" : "eight",
|
878
|
+
"defaultValue" : false,
|
879
|
+
"validFor" : "gAAA"
|
880
|
+
}, {
|
881
|
+
"value" : "nine",
|
882
|
+
"active" : true,
|
883
|
+
"label" : "nine",
|
884
|
+
"defaultValue" : false,
|
885
|
+
"validFor" : "QAAA"
|
886
|
+
} ],
|
887
|
+
"referenceTo" : [ ],
|
888
|
+
"relationshipName" : null,
|
889
|
+
"relationshipOrder" : null,
|
890
|
+
"restrictedPicklist" : false,
|
891
|
+
"namePointing" : false,
|
892
|
+
"custom" : true,
|
893
|
+
"htmlFormatted" : false,
|
894
|
+
"dependentPicklist" : true,
|
895
|
+
"writeRequiresMasterRead" : false,
|
896
|
+
"sortable" : true
|
897
|
+
}, {
|
840
898
|
"length" : 80,
|
841
899
|
"name" : "Text_Field",
|
842
900
|
"type" : "string",
|
data/spec/lib/client_spec.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
RSpec::Matchers.define :include_picklist_values do |expected|
|
4
|
+
match do |actual|
|
5
|
+
actual.all? { |picklist_value| expected.include? picklist_value['value'] }
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
3
9
|
class MockCache
|
4
10
|
def initialize
|
5
11
|
@storage = {}
|
@@ -264,6 +270,42 @@ shared_examples_for 'methods' do
|
|
264
270
|
end
|
265
271
|
end
|
266
272
|
|
273
|
+
describe '.picklist_values' do
|
274
|
+
requests 'sobjects/Account/describe',
|
275
|
+
:fixture => 'sobject/sobject_describe_success_response'
|
276
|
+
|
277
|
+
context 'when given a picklist field' do
|
278
|
+
subject { client.picklist_values('Account', 'Picklist_Field') }
|
279
|
+
it { should be_an Array }
|
280
|
+
its(:length) { should eq 3 }
|
281
|
+
it { should include_picklist_values ['one', 'two', 'three'] }
|
282
|
+
end
|
283
|
+
|
284
|
+
context 'when given a multipicklist field' do
|
285
|
+
subject { client.picklist_values('Account', 'Picklist_Multiselect_Field') }
|
286
|
+
it { should be_an Array }
|
287
|
+
its(:length) { should eq 3 }
|
288
|
+
it { should include_picklist_values ['four', 'five', 'six'] }
|
289
|
+
end
|
290
|
+
|
291
|
+
describe 'dependent picklists' do
|
292
|
+
context 'when given a picklist field that has a dependency' do
|
293
|
+
subject { client.picklist_values('Account', 'Dependent_Picklist_Field', :valid_for => 'one') }
|
294
|
+
it { should be_an Array }
|
295
|
+
its(:length) { should eq 2 }
|
296
|
+
it { should include_picklist_values ['seven', 'eight'] }
|
297
|
+
it { should_not include_picklist_values ['nine'] }
|
298
|
+
end
|
299
|
+
|
300
|
+
context 'when given a picklist field that does not have a dependency' do
|
301
|
+
subject { client.picklist_values('Account', 'Picklist_Field', :valid_for => 'one') }
|
302
|
+
it 'raises an exception' do
|
303
|
+
expect { subject }.to raise_error(/Picklist_Field is not a dependent picklist/)
|
304
|
+
end
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
267
309
|
describe '.authenticate!' do
|
268
310
|
subject { client.authenticate! }
|
269
311
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restforce
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -149,6 +149,7 @@ files:
|
|
149
149
|
- .gitignore
|
150
150
|
- .rspec
|
151
151
|
- .travis.yml
|
152
|
+
- CHANGELOG.md
|
152
153
|
- Gemfile
|
153
154
|
- LICENSE
|
154
155
|
- README.md
|
@@ -160,6 +161,7 @@ files:
|
|
160
161
|
- lib/restforce/client/caching.rb
|
161
162
|
- lib/restforce/client/canvas.rb
|
162
163
|
- lib/restforce/client/connection.rb
|
164
|
+
- lib/restforce/client/picklists.rb
|
163
165
|
- lib/restforce/client/streaming.rb
|
164
166
|
- lib/restforce/client/verbs.rb
|
165
167
|
- lib/restforce/collection.rb
|
@@ -307,4 +309,3 @@ test_files:
|
|
307
309
|
- spec/support/basic_client.rb
|
308
310
|
- spec/support/fixture_helpers.rb
|
309
311
|
- spec/support/middleware.rb
|
310
|
-
has_rdoc:
|