salesforceapi-rest 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/salesforceapi-rest.rb +78 -5
- data/lib/salesforceapi-rest/errors.rb +1 -1
- data/lib/salesforceapi-rest/version.rb +1 -1
- metadata +117 -95
- data/lib/salesforceapi-rest/sobject.rb +0 -12
data/lib/salesforceapi-rest.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require "salesforceapi-rest/version"
|
2
|
-
require "salesforceapi-rest/sobject"
|
3
2
|
require "salesforceapi-rest/request"
|
4
3
|
require "salesforceapi-rest/errors"
|
5
4
|
require 'net/https'
|
6
5
|
require 'net/http'
|
7
6
|
require 'active_resource'
|
8
7
|
require 'httparty'
|
8
|
+
require 'builder'
|
9
|
+
require 'crack/xml'
|
9
10
|
|
10
11
|
module Salesforceapi
|
11
12
|
module Rest
|
@@ -18,14 +19,17 @@ module Salesforceapi
|
|
18
19
|
format :json
|
19
20
|
@@ssl_port = 443
|
20
21
|
|
22
|
+
|
23
|
+
|
21
24
|
# set header for httparty
|
22
25
|
def self.set_headers (auth_setting)
|
23
26
|
headers (auth_setting)
|
24
27
|
end
|
25
28
|
|
26
|
-
def initialize(oauth_token, instance_uri, api_version = "v21.0")
|
29
|
+
def initialize(oauth_token, instance_uri, metadata_uri, api_version = "v21.0")
|
27
30
|
@oauth_token = oauth_token
|
28
31
|
@instance_uri = instance_uri
|
32
|
+
@metadata_uri = metadata_uri
|
29
33
|
@api_version = api_version ? api_version : "v21.0" #take a dynamic api server version
|
30
34
|
@full_url = instance_uri + "/services/data/#{api_version}/sobjects"
|
31
35
|
@ssl_port = 443 # TODO, right SF use port 443 for all HTTPS traffic.
|
@@ -36,19 +40,20 @@ module Salesforceapi
|
|
36
40
|
"Authorization" => "OAuth " + @oauth_token,
|
37
41
|
"content-Type" => 'application/json'
|
38
42
|
}
|
39
|
-
|
43
|
+
|
40
44
|
self.class.base_uri @instance_uri
|
41
45
|
|
42
46
|
end
|
43
47
|
|
44
48
|
|
45
|
-
def
|
49
|
+
def create(object, attributes)
|
46
50
|
|
47
51
|
path = "/services/data/#{@api_version}/sobjects/#{object}/"
|
48
52
|
target = @instance_uri + path
|
49
53
|
|
50
|
-
|
54
|
+
self.class.base_uri @instance_uri
|
51
55
|
|
56
|
+
data = ActiveSupport::JSON::encode(attributes)
|
52
57
|
resp = SalesforceApi::Request.do_request("POST", target, @auth_header, data)
|
53
58
|
|
54
59
|
# HTTP code 201 means it was successfully saved.
|
@@ -65,6 +70,8 @@ module Salesforceapi
|
|
65
70
|
path = "/services/data/#{@api_version}/sobjects/#{object}/describe"
|
66
71
|
target = @instance_uri + path
|
67
72
|
|
73
|
+
self.class.base_uri @instance_uri
|
74
|
+
|
68
75
|
resp = SalesforceApi::Request.do_request("GET", target, @auth_header, nil)
|
69
76
|
if (resp.code != 200) || !resp.success?
|
70
77
|
message = ActiveSupport::JSON.decode(resp.body)[0]["message"]
|
@@ -78,6 +85,8 @@ module Salesforceapi
|
|
78
85
|
path = "/services/data/#{@api_version}"
|
79
86
|
target = @instance_uri + path
|
80
87
|
|
88
|
+
self.class.base_uri @instance_uri
|
89
|
+
|
81
90
|
resp = SalesforceApi::Request.do_request("GET", target, @auth_header, nil)
|
82
91
|
if (resp.code != 200) || !resp.success?
|
83
92
|
message = ActiveSupport::JSON.decode(resp.body)[0]["message"]
|
@@ -86,6 +95,70 @@ module Salesforceapi
|
|
86
95
|
return ActiveSupport::JSON.decode(resp.body)
|
87
96
|
end
|
88
97
|
end
|
98
|
+
|
99
|
+
|
100
|
+
def add_custom_field(attributes)
|
101
|
+
auth_header = {
|
102
|
+
"Authorization" => "OAuth " + @oauth_token,
|
103
|
+
'Connection' => 'Keep-Alive',
|
104
|
+
'Content-Type' => 'text/xml',
|
105
|
+
'SOAPAction' => '""'
|
106
|
+
}
|
107
|
+
self.class.base_uri @metadata_uri
|
108
|
+
|
109
|
+
data = (Envelope % [@oauth_token, custom_fields_xml(attributes)])
|
110
|
+
resp = SalesforceApi::Request.do_request("POST", @metadata_uri, auth_header, data.lstrip)
|
111
|
+
|
112
|
+
xml_response = Crack::XML.parse(resp.body)
|
113
|
+
|
114
|
+
if resp.code != 200
|
115
|
+
message = xml_response["soapenv:Envelope"]["soapenv:Body"]["soapenv:Fault"]["faultstring"]
|
116
|
+
SalesforceApi::Errors::ErrorManager.raise_error("HTTP code " + resp.code.to_s + ": " + message, resp.code)
|
117
|
+
|
118
|
+
else
|
119
|
+
return xml_response
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
def custom_fields_xml(opts)
|
125
|
+
# Create XML text from the arguments.
|
126
|
+
expanded = ''
|
127
|
+
@builder = Builder::XmlMarkup.new(:target => expanded)
|
128
|
+
@builder.tag! :create, :xmlns => "http://soap.sforce.com/2006/04/metadata" do |b|
|
129
|
+
b.tag! :metadata, "xsi:type" => "ns2:CustomField", "xmlns:ns2" => "http://soap.sforce.com/2006/04/metadata" do |c|
|
130
|
+
opts.each { |k,v| c.tag! k, v }
|
131
|
+
end
|
132
|
+
end
|
133
|
+
expanded
|
134
|
+
end
|
135
|
+
|
136
|
+
Envelope = <<-HERE
|
137
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
138
|
+
<soapenv:Envelope
|
139
|
+
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
|
140
|
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
141
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
142
|
+
<soapenv:Header>
|
143
|
+
<ns1:SessionHeader soapenv:mustUnderstand="0" xsi:type="ns1:SessionHeader"
|
144
|
+
xmlns:ns1="http://soap.sforce.com/2006/04/metadata">
|
145
|
+
<ns1:sessionId>%s</ns1:sessionId>
|
146
|
+
</ns1:SessionHeader>
|
147
|
+
<ns2:CallOptions soapenv:mustUnderstand="0" xsi:type="ns2:SessionHeader"
|
148
|
+
xmlns:ns2="http://soap.sforce.com/2006/04/metadata">
|
149
|
+
<ns2:client>apex_eclipse/16.0.200906151227</ns2:client>
|
150
|
+
</ns2:CallOptions>
|
151
|
+
<ns3:DebuggingHeader soapenv:mustUnderstand="0" xsi:type="ns3:DebuggingHeader"
|
152
|
+
xmlns:ns3="http://soap.sforce.com/2006/04/metadata">
|
153
|
+
<ns3:debugLevel xsi:nil="true" />
|
154
|
+
</ns3:DebuggingHeader>
|
155
|
+
</soapenv:Header>
|
156
|
+
<soapenv:Body>
|
157
|
+
%s
|
158
|
+
</soapenv:Body>
|
159
|
+
</soapenv:Envelope>
|
160
|
+
HERE
|
161
|
+
|
89
162
|
end
|
90
163
|
end
|
91
164
|
end
|
metadata
CHANGED
@@ -1,139 +1,161 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: salesforceapi-rest
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 1
|
10
|
-
version: 0.0.1
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Lucas Allan Amorim
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-05-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: rspec
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
32
22
|
type: :development
|
33
|
-
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: rforce
|
36
23
|
prerelease: false
|
37
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
25
|
none: false
|
39
|
-
requirements:
|
40
|
-
- -
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rforce
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
46
38
|
type: :development
|
47
|
-
version_requirements: *id002
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: omniauth
|
50
39
|
prerelease: false
|
51
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
41
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: omniauth
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
60
54
|
type: :development
|
61
|
-
|
62
|
-
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
63
|
name: httparty
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
64
71
|
prerelease: false
|
65
|
-
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: activeresource
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
66
81
|
none: false
|
67
|
-
requirements:
|
68
|
-
- -
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
|
71
|
-
segments:
|
72
|
-
- 0
|
73
|
-
version: "0"
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
74
86
|
type: :development
|
75
|
-
version_requirements: *id004
|
76
|
-
- !ruby/object:Gem::Dependency
|
77
|
-
name: active_resource
|
78
87
|
prerelease: false
|
79
|
-
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: crack
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
80
97
|
none: false
|
81
|
-
requirements:
|
82
|
-
- -
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
|
85
|
-
segments:
|
86
|
-
- 0
|
87
|
-
version: "0"
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
88
102
|
type: :development
|
89
|
-
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: builder
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
90
126
|
description: Ruby wrapper to access salesforce rest api
|
91
|
-
email:
|
127
|
+
email:
|
92
128
|
- lucas.allan@gmail.com
|
93
129
|
executables: []
|
94
|
-
|
95
130
|
extensions: []
|
96
|
-
|
97
131
|
extra_rdoc_files: []
|
98
|
-
|
99
|
-
files:
|
132
|
+
files:
|
100
133
|
- lib/salesforceapi-rest/errors.rb
|
101
134
|
- lib/salesforceapi-rest/request.rb
|
102
|
-
- lib/salesforceapi-rest/sobject.rb
|
103
135
|
- lib/salesforceapi-rest/version.rb
|
104
136
|
- lib/salesforceapi-rest.rb
|
105
|
-
homepage:
|
137
|
+
homepage: ''
|
106
138
|
licenses: []
|
107
|
-
|
108
139
|
post_install_message:
|
109
140
|
rdoc_options: []
|
110
|
-
|
111
|
-
require_paths:
|
141
|
+
require_paths:
|
112
142
|
- lib
|
113
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
144
|
none: false
|
115
|
-
requirements:
|
116
|
-
- -
|
117
|
-
- !ruby/object:Gem::Version
|
118
|
-
|
119
|
-
|
120
|
-
- 0
|
121
|
-
version: "0"
|
122
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ! '>='
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
150
|
none: false
|
124
|
-
requirements:
|
125
|
-
- -
|
126
|
-
- !ruby/object:Gem::Version
|
127
|
-
|
128
|
-
segments:
|
129
|
-
- 0
|
130
|
-
version: "0"
|
151
|
+
requirements:
|
152
|
+
- - ! '>='
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
131
155
|
requirements: []
|
132
|
-
|
133
156
|
rubyforge_project:
|
134
|
-
rubygems_version: 1.8.
|
157
|
+
rubygems_version: 1.8.22
|
135
158
|
signing_key:
|
136
159
|
specification_version: 3
|
137
160
|
summary: Ruby wrapper to access salesforce rest api
|
138
161
|
test_files: []
|
139
|
-
|