restforce 1.4.1 → 1.4.2

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.

checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f155672fa355a4c60e63fa1f66ef16692a16e886
4
+ data.tar.gz: aa39f74eda4066a8a8addce8907423e9cb536bd7
5
+ SHA512:
6
+ metadata.gz: e081ce4d5954161f172634639c36e8a7646f5500934830f1a2795ca40ae49b6e706a16109f19e6998a0082284061e469a09ff55252aa6ae7e8432485dfd281d3
7
+ data.tar.gz: 17dd0fe6fb064e1e05f312a3ac6edcaf10dfafbec79c422db8de824dc1b98bfacfa3a9c29f0a3eb885e27a97f40cfff05b82c408c941fbbdc077ad7075a4ef5a
data/README.md CHANGED
@@ -229,6 +229,18 @@ client.describe('Account')
229
229
  # => { ... }
230
230
  ```
231
231
 
232
+ ### describe_layouts
233
+
234
+ ```ruby
235
+ # get layouts for an sobject type
236
+ client.describe_layout('Account')
237
+ # => { ... }
238
+
239
+ # get the details for a specific layout
240
+ client.describe_layouts('Account', '012E0000000RHEp')
241
+ # => { ... }
242
+ ```
243
+
232
244
  ### picklist\_values
233
245
 
234
246
 
@@ -22,6 +22,11 @@ module Restforce
22
22
  end
23
23
  alias_method :length, :size
24
24
 
25
+ # Return array of the elements on the current page
26
+ def current_page
27
+ first(@raw_page['records'].size)
28
+ end
29
+
25
30
  # Return the current and all of the following pages.
26
31
  def pages
27
32
  [self] + (has_next_page? ? next_page.pages : [])
@@ -65,6 +65,30 @@ module Restforce
65
65
  end
66
66
  end
67
67
 
68
+ # Public: Returns a detailed description of the Page Layout for the
69
+ # specified sobject type, or URIs for layouts if the sobject has
70
+ # multiple Record Types.
71
+ #
72
+ # This resource was introduced in version 28.0.
73
+ #
74
+ # Examples:
75
+ # # get the layouts for the sobject
76
+ # client.describe_layouts('Account')
77
+ # # => { ... }
78
+ #
79
+ # # get the layout for the specified Id for the sobject
80
+ # client.describe_layouts('Account', '012E0000000RHEp')
81
+ # # => { ... }
82
+ #
83
+ # Returns the Hash representation of the describe_layouts result
84
+ def describe_layouts(sobject, layout_id = nil)
85
+ if layout_id
86
+ api_get("sobjects/#{sobject.to_s}/describe/layouts/#{layout_id}").body
87
+ else
88
+ api_get("sobjects/#{sobject.to_s}/describe/layouts").body
89
+ end
90
+ end
91
+
68
92
  # Public: Get the current organization's Id.
69
93
  #
70
94
  # Examples
@@ -37,6 +37,9 @@ module Restforce
37
37
  # :timeout - Faraday connection request read/open timeout. (default: nil).
38
38
  #
39
39
  # :proxy_uri - Proxy URI: 'http://proxy.example.com:port' or 'http://user@pass:proxy.example.com:port'
40
+ #
41
+ # :authentication_callback
42
+ # - A Proc that is called with the response body after a successful authentication.
40
43
  def initialize(opts = {})
41
44
  raise ArgumentError, 'Please specify a hash of options' unless opts.is_a?(Hash)
42
45
  @options = Hash[Restforce.configuration.options.map { |option| [option, Restforce.configuration.send(option)] }]
@@ -51,7 +51,7 @@ module Restforce
51
51
  end
52
52
 
53
53
  def adapter
54
- Restforce.configuration.adapter
54
+ options[:adapter]
55
55
  end
56
56
 
57
57
  # Internal: Faraday Connection options
@@ -125,6 +125,9 @@ module Restforce
125
125
 
126
126
  option :proxy_uri, :default => lambda { ENV['PROXY_URI'] }
127
127
 
128
+ # A Proc that is called with the response body after a successful authentication.
129
+ option :authentication_callback
130
+
128
131
  def logger
129
132
  @logger ||= ::Logger.new STDOUT
130
133
  end
@@ -46,6 +46,10 @@ module Restforce
46
46
  deep_update(source_hash) if source_hash
47
47
  default ? super(default) : super(&blk)
48
48
  end
49
+
50
+ def dup
51
+ self.class.new(self, @client, self.default)
52
+ end
49
53
 
50
54
  def convert_value(val, duping=false)
51
55
  case val
@@ -24,6 +24,7 @@ module Restforce
24
24
  raise Restforce::AuthenticationError, error_message(response) if response.status != 200
25
25
  @options[:instance_url] = response.body['instance_url']
26
26
  @options[:oauth_token] = response.body['access_token']
27
+ @options[:authentication_callback].call(response.body) if @options[:authentication_callback]
27
28
  response.body
28
29
  end
29
30
 
@@ -2,7 +2,7 @@ module Restforce
2
2
  class SObject < Restforce::Mash
3
3
 
4
4
  def sobject_type
5
- self.attributes.type
5
+ self.attributes['type']
6
6
  end
7
7
 
8
8
  # Public: Get the describe for this sobject type
@@ -10,6 +10,11 @@ module Restforce
10
10
  @client.describe(sobject_type)
11
11
  end
12
12
 
13
+ # Public: Describe layouts for this sobject type
14
+ def describe_layouts(layout_id = nil)
15
+ @client.describe_layouts(sobject_type, layout_id)
16
+ end
17
+
13
18
  # Public: Persist the attributes to Salesforce.
14
19
  #
15
20
  # Examples
@@ -1,3 +1,3 @@
1
1
  module Restforce
2
- VERSION = '1.4.1'
2
+ VERSION = '1.4.2'
3
3
  end
data/restforce.gemspec CHANGED
@@ -17,11 +17,11 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_dependency 'faraday', '~> 0.8.4'
19
19
  gem.add_dependency 'faraday_middleware', '>= 0.8.8'
20
- gem.add_dependency 'json', '~> 1.7.5'
21
- gem.add_dependency 'hashie', '~> 1.2.0'
20
+ gem.add_dependency 'json', ['>= 1.7.5', '< 1.9.0']
21
+ gem.add_dependency 'hashie', ['>= 1.2.0', '< 2.1']
22
22
 
23
- gem.add_development_dependency 'rspec', '~> 2.12.0'
24
- gem.add_development_dependency 'webmock', '~> 1.9.0'
23
+ gem.add_development_dependency 'rspec', '~> 2.14.0'
24
+ gem.add_development_dependency 'webmock', '~> 1.13.0'
25
25
  gem.add_development_dependency 'simplecov', '~> 0.7.1'
26
26
  gem.add_development_dependency 'faye' unless RUBY_PLATFORM == 'java'
27
27
  end
data/spec/spec_helper.rb CHANGED
@@ -9,6 +9,12 @@ require 'webmock/rspec'
9
9
 
10
10
  WebMock.disable_net_connect!
11
11
 
12
+ RSpec.configure do |config|
13
+ config.order = 'random'
14
+ config.filter_run :focus => true
15
+ config.run_all_when_everything_filtered = true
16
+ end
17
+
12
18
  # Requires supporting ruby files with custom matchers and macros, etc,
13
19
  # in spec/support/ and its subdirectories.
14
20
  Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f}
@@ -6,6 +6,8 @@ module MiddlewareExampleGroup
6
6
  let(:retries) { 3 }
7
7
  let(:options) { { } }
8
8
  let(:client) { double(Restforce::AbstractClient) }
9
+ let(:auth_callback) { double(Proc) }
10
+ let(:success_response) { Restforce::Mash.new(JSON.parse(fixture(:auth_success_response))) }
9
11
  subject(:middleware) { described_class.new app, client, options }
10
12
  end
11
13
  end
@@ -25,16 +27,27 @@ shared_examples_for 'authentication middleware' do
25
27
  context 'when successful' do
26
28
  let!(:request) { success_request }
27
29
 
28
- before do
29
- middleware.authenticate!
30
- end
31
-
32
30
  describe '@options' do
33
31
  subject { options }
34
32
 
33
+ before do
34
+ middleware.authenticate!
35
+ end
36
+
35
37
  its([:instance_url]) { should eq 'https://na1.salesforce.com' }
36
38
  its([:oauth_token]) { should eq '00Dx0000000BV7z!AR8AQAxo9UfVkh8AlV0Gomt9Czx9LjHnSSpwBMmbRcgKFmxOtvxjTrKW19ye6PE3Ds1eQz3z8jr3W7_VbWmEu4Q8TVGSTHxs' }
37
39
  end
40
+
41
+ context 'when an authentication_callback is specified' do
42
+ before(:each) do
43
+ options.merge!(:authentication_callback => auth_callback)
44
+ end
45
+
46
+ it 'calls the authentication callback with the response body' do
47
+ auth_callback.should_receive(:call).with(success_response)
48
+ middleware.authenticate!
49
+ end
50
+ end
38
51
  end
39
52
 
40
53
  context 'when unsuccessful' do
@@ -45,6 +58,19 @@ shared_examples_for 'authentication middleware' do
45
58
  middleware.authenticate!
46
59
  }.to raise_error Restforce::AuthenticationError, /^invalid_grant: .*/
47
60
  end
61
+
62
+ context 'when an authentication_callback is specified' do
63
+ before(:each) do
64
+ options.merge!(:authentication_callback => auth_callback)
65
+ end
66
+
67
+ it 'does not call the authentication callback' do
68
+ auth_callback.should_not_receive(:call)
69
+ expect do
70
+ middleware.authenticate!
71
+ end.to raise_error
72
+ end
73
+ end
48
74
  end
49
75
  end
50
76
  end
@@ -32,12 +32,14 @@ describe Restforce::Collection do
32
32
 
33
33
  its(:size) { should eq 2 }
34
34
  its(:first) { should be_a Restforce::SObject }
35
+ its(:current_page) { should be_a Array }
36
+ its(:current_page) { should have(1).element }
35
37
  end
36
38
 
37
39
  context 'when all of the values are being requested' do
38
40
  before do
39
41
  client.stub(:get).
40
- and_return(stub :body => Restforce::Collection.new(next_page, client))
42
+ and_return(double(:body => Restforce::Collection.new(next_page, client)))
41
43
  end
42
44
 
43
45
  its(:pages) { should be_all { |page| expect(page).to be_a Restforce::Collection } }
@@ -37,6 +37,28 @@ describe Restforce::Concerns::API do
37
37
  end
38
38
  end
39
39
 
40
+ describe '.describe_layouts' do
41
+ subject(:describe_layouts) { client.describe_layouts('Whizbang') }
42
+
43
+ it 'returns the layouts for the sobject' do
44
+ client.should_receive(:api_get).
45
+ with('sobjects/Whizbang/describe/layouts').
46
+ and_return(response)
47
+ expect(describe_layouts).to eq response.body
48
+ end
49
+
50
+ context 'when given the id of a layout' do
51
+ subject(:describe_layouts) { client.describe_layouts('Whizbang', '012E0000000RHEp') }
52
+
53
+ it 'returns the describe for the specified layout' do
54
+ client.should_receive(:api_get).
55
+ with('sobjects/Whizbang/describe/layouts/012E0000000RHEp').
56
+ and_return(response)
57
+ expect(describe_layouts).to eq response.body
58
+ end
59
+ end
60
+ end
61
+
40
62
  describe '.org_id' do
41
63
  subject(:org_id) { client.org_id }
42
64
 
@@ -22,7 +22,7 @@ describe Restforce::Concerns::Authentication do
22
22
  authentication_middleware.
23
23
  should_receive(:new).
24
24
  with(nil, client, client.options).
25
- and_return(stub(:authenticate! => 'foo'))
25
+ and_return(double(:authenticate! => 'foo'))
26
26
  expect(result).to eq 'foo'
27
27
  end
28
28
  end
@@ -95,4 +95,4 @@ describe Restforce::Concerns::Authentication do
95
95
  it { should_not be_true }
96
96
  end
97
97
  end
98
- end
98
+ end
@@ -11,4 +11,12 @@ describe Restforce::Concerns::Connection do
11
11
 
12
12
  it { should eq builder }
13
13
  end
14
+
15
+ describe '#adapter' do
16
+ before do
17
+ client.stub :options => {:adapter => :typhoeus}
18
+ end
19
+
20
+ its(:adapter) { should eq(:typhoeus) }
21
+ end
14
22
  end
@@ -25,7 +25,7 @@ describe Restforce do
25
25
  its(:adapter) { should eq Faraday.default_adapter }
26
26
  [:username, :password, :security_token, :client_id, :client_secret,
27
27
  :oauth_token, :refresh_token, :instance_url, :compress, :timeout,
28
- :proxy_uri].each do |attr|
28
+ :proxy_uri, :authentication_callback].each do |attr|
29
29
  its(attr) { should be_nil }
30
30
  end
31
31
  end
@@ -55,7 +55,7 @@ describe Restforce do
55
55
  describe '#configure' do
56
56
  [:username, :password, :security_token, :client_id, :client_secret, :compress, :timeout,
57
57
  :oauth_token, :refresh_token, :instance_url, :api_version, :host, :authentication_retries,
58
- :proxy_uri].each do |attr|
58
+ :proxy_uri, :authentication_callback].each do |attr|
59
59
  it "allows #{attr} to be set" do
60
60
  Restforce.configure do |config|
61
61
  config.send("#{attr}=", 'foobar')
@@ -65,4 +65,22 @@ describe Restforce::SObject do
65
65
 
66
66
  it { should_not raise_error }
67
67
  end
68
+
69
+ describe '.describe_layouts' do
70
+ let(:layout_id) { nil }
71
+ subject { lambda { sobject.describe_layouts } }
72
+
73
+ before do
74
+ client.should_receive(:describe_layouts).with('Whizbang', layout_id)
75
+ end
76
+
77
+ it { should_not raise_error }
78
+
79
+ context 'when a layout Id is specified' do
80
+ let(:layout_id) { '012E0000000RHEp' }
81
+ subject { lambda { sobject.describe_layouts(layout_id) } }
82
+
83
+ it { should_not raise_error }
84
+ end
85
+ end
68
86
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restforce
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
5
- prerelease:
4
+ version: 1.4.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Eric J. Holmes
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-06-19 00:00:00.000000000 Z
11
+ date: 2013-09-16 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: faraday
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,87 +27,88 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: faraday_middleware
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: 0.8.8
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: 0.8.8
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: json
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: 1.7.5
48
+ - - <
49
+ - !ruby/object:Gem::Version
50
+ version: 1.9.0
54
51
  type: :runtime
55
52
  prerelease: false
56
53
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
54
  requirements:
59
- - - ~>
55
+ - - '>='
60
56
  - !ruby/object:Gem::Version
61
57
  version: 1.7.5
58
+ - - <
59
+ - !ruby/object:Gem::Version
60
+ version: 1.9.0
62
61
  - !ruby/object:Gem::Dependency
63
62
  name: hashie
64
63
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
64
  requirements:
67
- - - ~>
65
+ - - '>='
68
66
  - !ruby/object:Gem::Version
69
67
  version: 1.2.0
68
+ - - <
69
+ - !ruby/object:Gem::Version
70
+ version: '2.1'
70
71
  type: :runtime
71
72
  prerelease: false
72
73
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
74
  requirements:
75
- - - ~>
75
+ - - '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: 1.2.0
78
+ - - <
79
+ - !ruby/object:Gem::Version
80
+ version: '2.1'
78
81
  - !ruby/object:Gem::Dependency
79
82
  name: rspec
80
83
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
84
  requirements:
83
85
  - - ~>
84
86
  - !ruby/object:Gem::Version
85
- version: 2.12.0
87
+ version: 2.14.0
86
88
  type: :development
87
89
  prerelease: false
88
90
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
91
  requirements:
91
92
  - - ~>
92
93
  - !ruby/object:Gem::Version
93
- version: 2.12.0
94
+ version: 2.14.0
94
95
  - !ruby/object:Gem::Dependency
95
96
  name: webmock
96
97
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
98
  requirements:
99
99
  - - ~>
100
100
  - !ruby/object:Gem::Version
101
- version: 1.9.0
101
+ version: 1.13.0
102
102
  type: :development
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
105
  requirements:
107
106
  - - ~>
108
107
  - !ruby/object:Gem::Version
109
- version: 1.9.0
108
+ version: 1.13.0
110
109
  - !ruby/object:Gem::Dependency
111
110
  name: simplecov
112
111
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
112
  requirements:
115
113
  - - ~>
116
114
  - !ruby/object:Gem::Version
@@ -118,7 +116,6 @@ dependencies:
118
116
  type: :development
119
117
  prerelease: false
120
118
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
119
  requirements:
123
120
  - - ~>
124
121
  - !ruby/object:Gem::Version
@@ -126,17 +123,15 @@ dependencies:
126
123
  - !ruby/object:Gem::Dependency
127
124
  name: faye
128
125
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
126
  requirements:
131
- - - ! '>='
127
+ - - '>='
132
128
  - !ruby/object:Gem::Version
133
129
  version: '0'
134
130
  type: :development
135
131
  prerelease: false
136
132
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
133
  requirements:
139
- - - ! '>='
134
+ - - '>='
140
135
  - !ruby/object:Gem::Version
141
136
  version: '0'
142
137
  description: A lightweight ruby client for the Salesforce REST api.
@@ -257,33 +252,26 @@ files:
257
252
  - spec/unit/tooling/client_spec.rb
258
253
  homepage: https://github.com/ejholmes/restforce
259
254
  licenses: []
255
+ metadata: {}
260
256
  post_install_message:
261
257
  rdoc_options: []
262
258
  require_paths:
263
259
  - lib
264
260
  required_ruby_version: !ruby/object:Gem::Requirement
265
- none: false
266
261
  requirements:
267
- - - ! '>='
262
+ - - '>='
268
263
  - !ruby/object:Gem::Version
269
264
  version: '0'
270
- segments:
271
- - 0
272
- hash: -1556101281965570886
273
265
  required_rubygems_version: !ruby/object:Gem::Requirement
274
- none: false
275
266
  requirements:
276
- - - ! '>='
267
+ - - '>='
277
268
  - !ruby/object:Gem::Version
278
269
  version: '0'
279
- segments:
280
- - 0
281
- hash: -1556101281965570886
282
270
  requirements: []
283
271
  rubyforge_project:
284
- rubygems_version: 1.8.23
272
+ rubygems_version: 2.0.3
285
273
  signing_key:
286
- specification_version: 3
274
+ specification_version: 4
287
275
  summary: A lightweight ruby client for the Salesforce REST api.
288
276
  test_files:
289
277
  - spec/fixtures/auth_error_response.json