soapforce 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Soapforce do
4
+
5
+ after do
6
+ Soapforce.instance_variable_set :@configuration, nil
7
+ end
8
+
9
+ describe '#configuration' do
10
+ subject { Soapforce.configuration }
11
+
12
+ it { should be_a Soapforce::Configuration }
13
+ it { subject.client_id.should be_nil }
14
+
15
+ end
16
+
17
+ describe '#configure' do
18
+ [:client_id].each do |attr|
19
+ it "allows #{attr} to be set" do
20
+ Soapforce.configure do |config|
21
+ config.send("#{attr}=", 'foobar')
22
+ end
23
+ expect(Soapforce.configuration.send(attr)).to eq 'foobar'
24
+ end
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe Soapforce::QueryResult do
4
+
5
+ describe 'empty object' do
6
+ subject { Soapforce::QueryResult.new }
7
+
8
+ context "should have defaults" do
9
+ it { subject.size.should == 0 }
10
+ it { subject.query_locator.should be_nil }
11
+ it { subject.first.should be_nil }
12
+ it { subject.last.should be_nil }
13
+ it { subject.should be_done }
14
+ end
15
+
16
+ end
17
+
18
+ describe 'result object' do
19
+
20
+ context "single object" do
21
+
22
+ subject {
23
+ hash = {
24
+ done: true,
25
+ query_locator: nil,
26
+ size: 1,
27
+ records: {id: 1, name: "Opportunity 1", stage_name: "Prospecting"}
28
+ }
29
+ Soapforce::QueryResult.new(hash)
30
+ }
31
+
32
+ it { subject.size.should == 1 }
33
+ it { subject.query_locator.should be_nil }
34
+ it { subject.should be_done }
35
+
36
+ it "#each" do
37
+ count = 0
38
+ subject.each do |obj|
39
+ count +=1
40
+ obj[:id].should == count
41
+ obj.Id.should == count
42
+ end
43
+ expect(count).to be(1)
44
+ end
45
+ end
46
+
47
+ context "multiple records" do
48
+
49
+ subject {
50
+ hash = {
51
+ done: true,
52
+ query_locator: nil,
53
+ size: 2,
54
+ records: [
55
+ {id: 1, name: "Opportunity 1", stage_name: "Prospecting"},
56
+ {id: 2, name: "Opportunity 2", stage_name: "Closed Won"}
57
+ ]
58
+ }
59
+ Soapforce::QueryResult.new(hash)
60
+ }
61
+
62
+ it { subject.size.should == 2 }
63
+ it { subject.query_locator.should be_nil }
64
+ it { subject.should be_done }
65
+
66
+ it "#each" do
67
+ count = 0
68
+ subject.each do |obj|
69
+ count +=1
70
+ obj[:id].should == count
71
+ obj.Id.should == count
72
+ end
73
+ expect(count).to be(2)
74
+ end
75
+ end
76
+
77
+ end
78
+
79
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Soapforce::SObject do
4
+
5
+ describe 'empty object' do
6
+ subject { Soapforce::SObject.new(id: [1, 1], name: "testing", stage_name: "Prospecting") }
7
+
8
+ context "should have defaults" do
9
+ it { subject.Id.should == 1 }
10
+ it { subject.Name.should == "testing" }
11
+ it { subject.StageName.should == "Prospecting" }
12
+ it { subject.InvalidField.should be_nil }
13
+
14
+ it { subject[:id].should == [1, 1] }
15
+ it { subject[:name].should == "testing" }
16
+ it { subject[:stage_name].should == "Prospecting" }
17
+ it { subject[:no_field].should be_nil }
18
+ end
19
+
20
+ context "assignment" do
21
+ it "should assign through hash index" do
22
+ subject[:nothing].should be_nil
23
+ subject[:nothing] = "New Value"
24
+ subject[:nothing].should == "New Value"
25
+ subject.Nothing.should == "New Value"
26
+ end
27
+ end
28
+
29
+ context "respond to hash methods" do
30
+
31
+ it "should has_key?" do
32
+ subject.has_key?(:name).should be_true
33
+ subject.has_key?(:stage_name).should be_true
34
+ subject.has_key?(:nothing).should be_false
35
+ end
36
+
37
+ it "should return keys" do
38
+ subject.keys.should == [:id, :name, :stage_name]
39
+ end
40
+ end
41
+
42
+ end
43
+
44
+ end
@@ -0,0 +1,21 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_filter "/vendor/"
4
+ end
5
+
6
+ require 'bundler/setup'
7
+ Bundler.require :default, :test
8
+
9
+ require 'webmock/rspec'
10
+
11
+ WebMock.disable_net_connect!
12
+
13
+ RSpec.configure do |config|
14
+ config.order = 'random'
15
+ config.filter_run :focus => true
16
+ config.run_all_when_everything_filtered = true
17
+ end
18
+
19
+ # Requires supporting ruby files with custom matchers and macros, etc,
20
+ # in spec/support/ and its subdirectories.
21
+ Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f}
@@ -0,0 +1,58 @@
1
+ module FixtureHelpers
2
+ module InstanceMethods
3
+
4
+ def stub_api_request(endpoint, options={})
5
+ options = {
6
+ :method => :post,
7
+ :status => 200,
8
+ }.merge(options)
9
+
10
+ instance_url = options[:instance_url] || "https://login.salesforce.com/services/Soap/u/28.0"
11
+ stub = stub_request(options[:method], instance_url)
12
+ stub = stub.with(:body => soap_envelope(options[:headers], options[:with_body]))
13
+ stub = stub.to_return(:status => options[:status], :body => fixture(options[:fixture]), :headers => { 'Content-Type' => 'text/xml;charset=UTF-8'}) if options[:fixture]
14
+ stub
15
+ end
16
+
17
+ def stub_login_request(options={})
18
+ server_url = options[:server_url] || "https://login.salesforce.com/services/Soap/u/28.0"
19
+ stub = stub_request(:post, server_url)
20
+ stub = stub.with(:body => soap_envelope(options[:headers], options[:with_body]))
21
+ stub
22
+ end
23
+
24
+ def fixture(f)
25
+ File.read(File.expand_path("../../fixtures/#{f}.xml", __FILE__))
26
+ end
27
+
28
+ def soap_envelope(headers, body)
29
+ envelope = <<EOF
30
+ <?xml version="1.0" encoding="UTF-8"?>
31
+ <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
32
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
+ xmlns:tns="urn:partner.soap.sforce.com"
34
+ xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
35
+ xmlns:ins0="urn:sobject.partner.soap.sforce.com"
36
+ xmlns:ins1="urn:fault.partner.soap.sforce.com">
37
+ #{soap_headers(headers)}
38
+ <env:Body>#{body}</env:Body>
39
+ </env:Envelope>
40
+ EOF
41
+ envelope.gsub("\n", "")
42
+ end
43
+
44
+ def soap_headers(params={})
45
+ return '' if params.nil? || params.empty?
46
+ headers = "<env:Header>"
47
+ headers << "<tns:CallOptions><tns:client>#{params[:client_id]}</tns:client></tns:CallOptions>" if params[:client_id]
48
+ headers << "<tns:SessionHeader><tns:sessionId>#{params[:session_id]}</tns:sessionId></tns:SessionHeader>" if params[:session_id]
49
+ headers << "</env:Header>"
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+
56
+ RSpec.configure do |config|
57
+ config.include FixtureHelpers::InstanceMethods
58
+ end
data/test.rb ADDED
@@ -0,0 +1,58 @@
1
+ require 'soapforce'
2
+
3
+ Soapforce.configure do |config|
4
+ config.client_id = "TinderBox/TinderBox/"
5
+ end
6
+
7
+ client = Soapforce::Client.new
8
+ puts client.operations
9
+
10
+ user_result = client.login(username: "joe.heth@gettinderbox.com", password: "t1nd3rb0x1uzAgNZt8mT7G0MZlIr1Zq0oG") # 1Qn2uKB1DGZBF8WNGMFz1CS42s")
11
+
12
+ client.invalidate_sessions
13
+
14
+ exit
15
+ #ap client.get_user_info
16
+
17
+ #ap client.list_sobjects
18
+ #ap client.org_id
19
+ #ap client.field_list("Opportunity")
20
+ #ap client.field_details("Opportunity", "Name")
21
+ #ap client.find_by_field("Opportunity", "006A000000LbkT5IAJ", "Id")
22
+
23
+ #ap client.find_where("Opportunity", {Id: "006A000000LbkT5IAJ", Amount: nil}).first
24
+ ap client.retrieve("Opportunity", "006A000000LbkT5IAJ")
25
+
26
+ exit
27
+
28
+ opp = client.describe("Opportunity")
29
+ ap opp
30
+
31
+ objects = client.describe(["Account", "Contact"])
32
+ ap objects.first
33
+ ap objects.last
34
+
35
+ result = client.query("Select Id, Name, StageName From Opportunity WHERE Id = '006A000000LZhwN' OR Id = '006A000000LaF4x'")
36
+ result.each do |opp|
37
+ ap opp
38
+ end
39
+
40
+ #result = client.search("FIND {Name} IN ALL FIELDS RETURNING Account (Id, Name), Contact, Opportunity, Lead")
41
+ #ap result
42
+
43
+ ap client.create("Opportunity", {
44
+ Name: "SOAPForce Opportunity",
45
+ CloseDate: Date.today,
46
+ StageName: 'Prospecting'
47
+ })
48
+
49
+ =begin
50
+ ap client.update("Opportunity", {
51
+ Id: "006A000000LbiizIAB",
52
+ tinderbox__OrderNumber__c: "12345",
53
+ tinderbox__TrackingNumber__c: "ABCDEF",
54
+ Amount: 12.50
55
+ })
56
+
57
+ ap client.delete("006A000000LbiizIAB")
58
+ =end
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: soapforce
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Joe Heth
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: savon
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.3.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.3.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.14.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.14.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: webmock
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.13.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.13.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: simplecov
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 0.7.1
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 0.7.1
78
+ description: A ruby client for the Salesforce SOAP API based on Savon.
79
+ email:
80
+ - joeheth@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - .travis.yml
87
+ - Gemfile
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - lib/soapforce.rb
92
+ - lib/soapforce/client.rb
93
+ - lib/soapforce/configuration.rb
94
+ - lib/soapforce/query_result.rb
95
+ - lib/soapforce/sobject.rb
96
+ - lib/soapforce/version.rb
97
+ - resources/partner.wsdl.xml
98
+ - soapforce.gemspec
99
+ - spec/fixtures/create_response.xml
100
+ - spec/fixtures/delete_response.xml
101
+ - spec/fixtures/describe_global_response.xml
102
+ - spec/fixtures/describe_s_object_response.xml
103
+ - spec/fixtures/describe_s_objects_response.xml
104
+ - spec/fixtures/get_user_info_response.xml
105
+ - spec/fixtures/login_response.xml
106
+ - spec/fixtures/org_id_response.xml
107
+ - spec/fixtures/query_all_response.xml
108
+ - spec/fixtures/query_more_response.xml
109
+ - spec/fixtures/query_response.xml
110
+ - spec/fixtures/retrieve_response.xml
111
+ - spec/fixtures/search_response.xml
112
+ - spec/fixtures/update_response.xml
113
+ - spec/fixtures/upsert_response.xml
114
+ - spec/lib/client_spec.rb
115
+ - spec/lib/configuration_spec.rb
116
+ - spec/lib/query_result_spec.rb
117
+ - spec/lib/sobject_spec.rb
118
+ - spec/spec_helper.rb
119
+ - spec/support/fixture_helpers.rb
120
+ - test.rb
121
+ homepage: https://github.com/TinderBox/soapforce
122
+ licenses: []
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 1.8.24
142
+ signing_key:
143
+ specification_version: 3
144
+ summary: Wraps Savon with helper methods and custom types for interacting with the
145
+ Salesforce SOAP API.
146
+ test_files:
147
+ - spec/fixtures/create_response.xml
148
+ - spec/fixtures/delete_response.xml
149
+ - spec/fixtures/describe_global_response.xml
150
+ - spec/fixtures/describe_s_object_response.xml
151
+ - spec/fixtures/describe_s_objects_response.xml
152
+ - spec/fixtures/get_user_info_response.xml
153
+ - spec/fixtures/login_response.xml
154
+ - spec/fixtures/org_id_response.xml
155
+ - spec/fixtures/query_all_response.xml
156
+ - spec/fixtures/query_more_response.xml
157
+ - spec/fixtures/query_response.xml
158
+ - spec/fixtures/retrieve_response.xml
159
+ - spec/fixtures/search_response.xml
160
+ - spec/fixtures/update_response.xml
161
+ - spec/fixtures/upsert_response.xml
162
+ - spec/lib/client_spec.rb
163
+ - spec/lib/configuration_spec.rb
164
+ - spec/lib/query_result_spec.rb
165
+ - spec/lib/sobject_spec.rb
166
+ - spec/spec_helper.rb
167
+ - spec/support/fixture_helpers.rb