restforce 1.0.5 → 1.0.6
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 +16 -0
- data/README.md +10 -77
- data/lib/restforce/client.rb +14 -0
- data/lib/restforce/sobject.rb +4 -0
- data/lib/restforce/version.rb +1 -1
- data/spec/lib/client_spec.rb +19 -20
- data/spec/lib/sobject_spec.rb +0 -6
- data/spec/spec_helper.rb +4 -0
- data/spec/support/matchers.rb +11 -0
- data/spec/support/mock_cache.rb +13 -0
- metadata +12 -2
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
## 1.0.6 (Feb 16, 2013)
|
2
|
+
|
3
|
+
* Added `url` method.
|
4
|
+
|
5
|
+
Example
|
6
|
+
|
7
|
+
# Url to a record id
|
8
|
+
client.url('0013000000rRz')
|
9
|
+
# => https://na1.salesforce.com/0013000000rRz
|
10
|
+
|
11
|
+
# Url to an object that responds to `to_sparam`
|
12
|
+
record = Struct.new(:to_sparam).new('0013000000rRz')
|
13
|
+
client.url('0013000000rRz')
|
14
|
+
# => https://na1.salesforce.com/0013000000rRz
|
15
|
+
|
16
|
+
|
1
17
|
## 1.0.5 (Jan 11, 2013)
|
2
18
|
|
3
19
|
* Added `picklist_values` method.
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Restforce
|
2
2
|
|
3
|
-
[![travis-ci](https://
|
3
|
+
[![travis-ci](https://travis-ci.org/ejholmes/restforce.png?branch=master)](https://travis-ci.org/ejholmes/restforce) [![Code Climate](https://codeclimate.com/github/ejholmes/restforce.png)](https://codeclimate.com/github/ejholmes/restforce) [![Dependency Status](https://gemnasium.com/ejholmes/restforce.png)](https://gemnasium.com/ejholmes/restforce)
|
4
4
|
|
5
5
|
Restforce is a ruby gem for the [Salesforce REST api](http://www.salesforce.com/us/developer/docs/api_rest/index.htm).
|
6
6
|
It's meant to be a lighter weight alternative to the [databasedotcom gem](https://github.com/heroku/databasedotcom) that offers
|
@@ -127,10 +127,7 @@ works similarly to ActiveRecord.
|
|
127
127
|
|
128
128
|
* * *
|
129
129
|
|
130
|
-
### query
|
131
|
-
|
132
|
-
Performs a soql query and returns the result. The result will be a
|
133
|
-
[Restforce::Collection][], which can be iterated over.
|
130
|
+
### query
|
134
131
|
|
135
132
|
```ruby
|
136
133
|
accounts = client.query("select Id, Something__c from Account where Id = 'someid'")
|
@@ -153,16 +150,7 @@ account.destroy
|
|
153
150
|
# => true
|
154
151
|
```
|
155
152
|
|
156
|
-
|
157
|
-
|
158
|
-
* * *
|
159
|
-
|
160
|
-
### find(sobject, id, field=nil)
|
161
|
-
|
162
|
-
Finds the record with the specified id and the specified sobject type and
|
163
|
-
returns all fields for the sobject. An external id field can be used instead
|
164
|
-
of the default Id field by specifiying the name of the external id field as the
|
165
|
-
last parameter.
|
153
|
+
### find
|
166
154
|
|
167
155
|
```ruby
|
168
156
|
client.find('Account', '001D000000INjVe')
|
@@ -172,14 +160,7 @@ client.find('Account', '1234', 'Some_External_Id_Field__c')
|
|
172
160
|
# => #<Restforce::SObject Id="001D000000INjVe" Name="Test" LastModifiedBy="005G0000002f8FHIAY" ... >
|
173
161
|
```
|
174
162
|
|
175
|
-
|
176
|
-
|
177
|
-
* * *
|
178
|
-
|
179
|
-
### search(sosl)
|
180
|
-
|
181
|
-
Performs a sosl query and returns the result. The result will be a
|
182
|
-
[Restforce::Collection][].
|
163
|
+
### search
|
183
164
|
|
184
165
|
```ruby
|
185
166
|
# Find all occurrences of 'bar'
|
@@ -191,16 +172,7 @@ client.search('FIND {genepoint} RETURNING Account (Name)').map(&:Name)
|
|
191
172
|
# => ['GenePoint']
|
192
173
|
```
|
193
174
|
|
194
|
-
|
195
|
-
|
196
|
-
* * *
|
197
|
-
|
198
|
-
### create(sobject, attrs)
|
199
|
-
|
200
|
-
_Alias: insert_
|
201
|
-
|
202
|
-
Takes an sobject name and a hash of attributes to create a record. Returns the
|
203
|
-
Id of the newly created reocrd if the record was successfully created.
|
175
|
+
### create
|
204
176
|
|
205
177
|
```ruby
|
206
178
|
# Add a new account
|
@@ -208,14 +180,7 @@ client.create('Account', Name: 'Foobar Inc.')
|
|
208
180
|
# => '0016000000MRatd'
|
209
181
|
```
|
210
182
|
|
211
|
-
|
212
|
-
|
213
|
-
* * *
|
214
|
-
|
215
|
-
### update(sobject, attrs)
|
216
|
-
|
217
|
-
Takes an sobject name and a hash of attributes to update a record. An 'Id' key is required in attrs (either a string or symbol). Returns true if the record was successfully
|
218
|
-
updated.
|
183
|
+
### update
|
219
184
|
|
220
185
|
```ruby
|
221
186
|
# Update the Account with Id '0016000000MRatd'
|
@@ -223,28 +188,14 @@ client.update('Account', Id: '0016000000MRatd', Name: 'Whizbang Corp')
|
|
223
188
|
# => true
|
224
189
|
```
|
225
190
|
|
226
|
-
|
227
|
-
|
228
|
-
* * *
|
229
|
-
|
230
|
-
### upsert(sobject, field, attrs)
|
231
|
-
|
232
|
-
Takes an sobject name, an external id field, and a hash of attributes and
|
233
|
-
either inserts or updates the record depending on the existince of the record.
|
234
|
-
Returns true if the record was updated or the Id of the record if the record was
|
235
|
-
created.
|
191
|
+
### upsert
|
236
192
|
|
237
193
|
```ruby
|
238
194
|
# Update the record with external ID of 12
|
239
195
|
client.upsert('Account', 'External__c', External__c: 12, Name: 'Foobar')
|
240
196
|
```
|
241
197
|
|
242
|
-
|
243
|
-
|
244
|
-
### destroy(sobject, id)
|
245
|
-
|
246
|
-
Takes an sobject name and an Id and deletes the record. Returns true if the
|
247
|
-
record was successfully deleted.
|
198
|
+
### destroy
|
248
199
|
|
249
200
|
```ruby
|
250
201
|
# Delete the Account with Id '0016000000MRatd'
|
@@ -252,14 +203,7 @@ client.destroy('Account', '0016000000MRatd')
|
|
252
203
|
# => true
|
253
204
|
```
|
254
205
|
|
255
|
-
|
256
|
-
|
257
|
-
* * *
|
258
|
-
|
259
|
-
### describe(sobject)
|
260
|
-
|
261
|
-
If no parameter is given, it will return the global describe. If the name of an
|
262
|
-
sobject is given, it will return the describe for that sobject.
|
206
|
+
### describe
|
263
207
|
|
264
208
|
```ruby
|
265
209
|
# get the global describe for all sobjects
|
@@ -271,18 +215,7 @@ client.describe('Account')
|
|
271
215
|
# => { ... }
|
272
216
|
```
|
273
217
|
|
274
|
-
|
275
|
-
|
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.
|
218
|
+
### picklist\_values
|
286
219
|
|
287
220
|
|
288
221
|
```ruby
|
data/lib/restforce/client.rb
CHANGED
@@ -78,6 +78,20 @@ module Restforce
|
|
78
78
|
@options.merge! opts
|
79
79
|
end
|
80
80
|
|
81
|
+
def instance_url
|
82
|
+
authenticate! unless @options[:instance_url]
|
83
|
+
@options[:instance_url]
|
84
|
+
end
|
85
|
+
|
86
|
+
# Public: Returns a url to the resource.
|
87
|
+
#
|
88
|
+
# resource - A record that responds to to_sparam or a String/Fixnum.
|
89
|
+
#
|
90
|
+
# Returns the url to the resource.
|
91
|
+
def url(resource)
|
92
|
+
"#{instance_url}/#{(resource.respond_to?(:to_sparam) ? resource.to_sparam : resource)}"
|
93
|
+
end
|
94
|
+
|
81
95
|
def inspect
|
82
96
|
"#<#{self.class} @options=#{@options.inspect}>"
|
83
97
|
end
|
data/lib/restforce/sobject.rb
CHANGED
data/lib/restforce/version.rb
CHANGED
data/spec/lib/client_spec.rb
CHANGED
@@ -1,25 +1,5 @@
|
|
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
|
-
|
9
|
-
class MockCache
|
10
|
-
def initialize
|
11
|
-
@storage = {}
|
12
|
-
end
|
13
|
-
|
14
|
-
def fetch(key, &block)
|
15
|
-
@storage[key] ||= block.call
|
16
|
-
end
|
17
|
-
|
18
|
-
def delete(key)
|
19
|
-
@storage.delete(key)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
3
|
shared_examples_for 'methods' do
|
24
4
|
describe '#new' do
|
25
5
|
context 'without options passed in' do
|
@@ -51,6 +31,25 @@ shared_examples_for 'methods' do
|
|
51
31
|
its([:security_token]) { should eq security_token }
|
52
32
|
end
|
53
33
|
|
34
|
+
describe '.instance_url' do
|
35
|
+
subject { client.instance_url }
|
36
|
+
it { should eq 'https://na1.salesforce.com' }
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '.url' do
|
40
|
+
subject { client.url(resource) }
|
41
|
+
|
42
|
+
context 'when given something that responds to to_sparam' do
|
43
|
+
let(:resource) { Struct.new(:to_sparam).new('1234') }
|
44
|
+
it { should eq 'https://na1.salesforce.com/1234' }
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'when given a string' do
|
48
|
+
let(:resource) { '4321' }
|
49
|
+
it { should eq 'https://na1.salesforce.com/4321' }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
54
53
|
describe '.authentication_middleware' do
|
55
54
|
subject { client.send :authentication_middleware }
|
56
55
|
|
data/spec/lib/sobject_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -14,6 +14,10 @@ WebMock.disable_net_connect!
|
|
14
14
|
Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f}
|
15
15
|
|
16
16
|
RSpec.configure do |config|
|
17
|
+
config.before do
|
18
|
+
EventMachine.stub(:connect) if defined?(EventMachine)
|
19
|
+
end
|
20
|
+
|
17
21
|
config.around :eventmachine => true do |example|
|
18
22
|
EM.run {
|
19
23
|
example.run
|
@@ -0,0 +1,11 @@
|
|
1
|
+
RSpec::Matchers.define :include_picklist_values do |expected|
|
2
|
+
match do |actual|
|
3
|
+
actual.all? { |picklist_value| expected.include? picklist_value['value'] }
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
RSpec::Matchers.define :have_client do |expected|
|
8
|
+
match do |actual|
|
9
|
+
actual.instance_variable_get(:@client) == expected
|
10
|
+
end
|
11
|
+
end
|
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.6
|
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-
|
12
|
+
date: 2013-02-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -233,7 +233,9 @@ files:
|
|
233
233
|
- spec/spec_helper.rb
|
234
234
|
- spec/support/basic_client.rb
|
235
235
|
- spec/support/fixture_helpers.rb
|
236
|
+
- spec/support/matchers.rb
|
236
237
|
- spec/support/middleware.rb
|
238
|
+
- spec/support/mock_cache.rb
|
237
239
|
homepage: https://github.com/ejholmes/restforce
|
238
240
|
licenses: []
|
239
241
|
post_install_message:
|
@@ -246,12 +248,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
246
248
|
- - ! '>='
|
247
249
|
- !ruby/object:Gem::Version
|
248
250
|
version: '0'
|
251
|
+
segments:
|
252
|
+
- 0
|
253
|
+
hash: -3883981851438487723
|
249
254
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
250
255
|
none: false
|
251
256
|
requirements:
|
252
257
|
- - ! '>='
|
253
258
|
- !ruby/object:Gem::Version
|
254
259
|
version: '0'
|
260
|
+
segments:
|
261
|
+
- 0
|
262
|
+
hash: -3883981851438487723
|
255
263
|
requirements: []
|
256
264
|
rubyforge_project:
|
257
265
|
rubygems_version: 1.8.23
|
@@ -308,4 +316,6 @@ test_files:
|
|
308
316
|
- spec/spec_helper.rb
|
309
317
|
- spec/support/basic_client.rb
|
310
318
|
- spec/support/fixture_helpers.rb
|
319
|
+
- spec/support/matchers.rb
|
311
320
|
- spec/support/middleware.rb
|
321
|
+
- spec/support/mock_cache.rb
|