big_machines 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MWFhYjZmYzgxNzg5NTIxNjU2NDBjNWM0MjM2ODU2NzU3ODI2YWUxYQ==
5
- data.tar.gz: !binary |-
6
- YmVmZTliYzM4N2VkNTBlZjljYjI3ZjZjNGZiODk1MzkyNWEyMjBiOA==
2
+ SHA1:
3
+ metadata.gz: 3f3c7d06d716ea3d6e8dadf02eeae6701cdca7ba
4
+ data.tar.gz: 0f780d198d87cfd98a59fcaa3ce169adb98a4f68
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YmRhOGRiZWI3N2YzNjJjZjZhMjUxMmNkZmIwZjFkYjlmOGQzOTU1OWI5N2Nm
10
- ZTQ2YjhiZGU1NDVkZDQwZmIxZjkwY2M0MDY2MTg2ZGM0MGFmZTU0MmQ1Mzc5
11
- MGRjNDI0NjM5OGE1NTg4ZTkxMmNlZWY5MjJiNjVkOTMyZTY0OWQ=
12
- data.tar.gz: !binary |-
13
- YjUzNGYzMDE4ZjdiNjFjYTAzM2U0MDU4MTU3MmQ4YzNmMmE3NjA5MzdhODJm
14
- Y2VkN2FjNDViNzVlY2JkNmE3ODg1MDUxYmY5NTA4ZjdiZmU1YjRjZmIzZWM5
15
- NGQ5OWMyMTI0Njc3MGZjNmYzM2RkY2ZjMTFmOGUwNTNhYmE3MzA=
6
+ metadata.gz: 965d70d90c979a70ac511236e521cb9d179b6a88ce93e6db7512e6fce524ad535d142b3160b9f9c5027e97b9be4534c327568c6badc80e58b7732fac15f23254
7
+ data.tar.gz: 5994b8395ed66c170325cefa9d82a9647ae981225dfb65af350f440bc2590541c689fa68a00be01a35cf04c163d5cc821eb380324d42c507f91d41123ed6e9ca
data/README.md CHANGED
@@ -46,7 +46,7 @@ client = BigMachines::Client.new('subdomain', process_name: 'quotes_process')
46
46
  #### Authenticate
47
47
 
48
48
  ```ruby
49
- client.login(:username => 'foo', :password => 'password')
49
+ client.login('foo', 'password')
50
50
  ```
51
51
 
52
52
  ### set_session_currency
@@ -74,8 +74,8 @@ client.get_transaction(id)
74
74
  ### update_transaction
75
75
 
76
76
  ```ruby
77
- # Update transaction
78
- client.update_transaction(id, data={})
77
+ # Update transaction (quote_process)
78
+ client.update_transaction(id, data={notesCMPM_es: "Sample Notes"})
79
79
  # => Hash[:status]
80
80
  ```
81
81
 
@@ -10,6 +10,7 @@ module BigMachines
10
10
  @site_name = site_name
11
11
  raise "Valid Site Name must be provided" if @site_name.nil? || @site_name.empty?
12
12
  @process_var_name = options[:process_name] || "quotes_process"
13
+ @logger = options[:logger] || false
13
14
 
14
15
  @namespaces = {
15
16
  "xmlns:bm" => "urn:soap.bigmachines.com"
@@ -20,13 +21,7 @@ module BigMachines
20
21
 
21
22
  @endpoint = "https://#{@site_name}.bigmachines.com/v1_0/receiver"
22
23
 
23
- @client = Savon.client(
24
- wsdl: @security_wsdl,
25
- endpoint: @endpoint,
26
- soap_header: headers(:security),
27
- convert_request_keys_to: :none,
28
- pretty_print_xml: true
29
- )
24
+ @client = Savon.client(configuration)
30
25
  end
31
26
 
32
27
  def headers(type=:security)
@@ -60,45 +55,26 @@ module BigMachines
60
55
  @client.operations
61
56
  end
62
57
 
63
- # Public: Get the names of all wsdl operations.
64
- #
65
- # Supports a username/password (with token) combination or session_id/server_url pair.
58
+ # Public: login
66
59
  #
67
60
  # Examples
68
61
  #
69
- # client.login(username: 'test', password: 'password_and_token')
70
- # # => {...}
71
- #
72
- # client.login(session_id: 'abcd1234', server_url: 'https://na1.salesforce.com/')
62
+ # client.login(username, password)
73
63
  # # => {...}
74
64
  #
75
65
  # Returns Hash of login response and user info
76
- def login(options={})
66
+ def login(username, password)
77
67
  result = nil
78
- if options[:username] && options[:password]
79
- message = {userInfo: {username: options[:username], password: options[:password]}}
80
- response = self.security_call(:login, message)
68
+ message = {userInfo: {username: username, password: password}}
69
+ response = self.security_call(:login, message)
81
70
 
82
- userInfo = response[:user_info]
71
+ userInfo = response[:user_info]
83
72
 
84
- @session_id = userInfo[:session_id]
85
- else
86
- raise ArgumentError.new("Must provide username/password or session_id/server_url.")
87
- end
73
+ @session_id = userInfo[:session_id]
88
74
 
89
- @security_client = Savon.client(
90
- wsdl: @security_wsdl,
91
- endpoint: @endpoint,
92
- soap_header: headers(:security),
93
- convert_request_keys_to: :none,
94
- pretty_print_xml: true
95
- )
75
+ @security_client = Savon.client(configuration)
96
76
 
97
- # If a session_id/server_url were passed in then invoke get_user_info for confirmation.
98
- # Method missing to call_soap_api
99
- result = self.get_user_info if options[:session_id]
100
-
101
- result
77
+ response[:status][:success]
102
78
  end
103
79
  alias_method :authenticate, :login
104
80
 
@@ -123,14 +99,14 @@ module BigMachines
123
99
  # </bm:return_specific_attributes>
124
100
  # </bm:transaction>
125
101
  # </bm:getTransaction>
126
- def get_transaction(id)
102
+ def get_transaction(id, document_var_name='quote_process')
127
103
  transaction = {
128
104
  transaction: {
129
105
  id: id,
130
106
  return_specific_attributes: {
131
107
  documents: {
132
108
  document: {
133
- var_name: "quote_process"
109
+ var_name: document_var_name
134
110
  }
135
111
  }
136
112
  }
@@ -156,17 +132,20 @@ module BigMachines
156
132
  # </bm:transaction>
157
133
  # </bm:updateTransaction>
158
134
  def update_transaction(id, data={})
135
+
136
+ # :opportunityName_quote => 'Test Oppty Auto Approval TinderBox 12',
137
+ # :siteName_quote => 'My Dummy Site'
138
+ quote_process_data = {
139
+ :"@bs_id" => id,
140
+ :"@data_type" => 0,
141
+ :"@document_number" => 1
142
+ }.merge(data)
143
+
159
144
  transaction = {
160
145
  transaction: {
161
146
  id: id,
162
147
  data_xml: {
163
- quote_process: {
164
- :"@bs_id" => id,
165
- :"@data_type" => 0,
166
- :"@document_number" => 1,
167
- :opportunityName_quote => 'Test Oppty Auto Approval TinderBox 12',
168
- :siteName_quote => 'My Dummy Site'
169
- }
148
+ quote_process: quote_process_data
170
149
  },
171
150
  action_data: {
172
151
  action_var_name: '_update_line_items'
@@ -190,6 +169,19 @@ module BigMachines
190
169
 
191
170
  protected
192
171
 
172
+ def configuration(custom={})
173
+ {
174
+ wsdl: @security_wsdl,
175
+ endpoint: @endpoint,
176
+ soap_header: headers(:security),
177
+ filters: [:password],
178
+ convert_request_keys_to: :none,
179
+ pretty_print_xml: true,
180
+ logger: @logger,
181
+ log: @logger != false
182
+ }.merge(custom)
183
+ end
184
+
193
185
  def commerce_client
194
186
  @commerce_client ||= client_api(@commerce_wsdl)
195
187
  end
@@ -200,14 +192,7 @@ module BigMachines
200
192
 
201
193
  def client_api(wsdl)
202
194
  category = wsdl.include?('security') ? :security : :commerce
203
-
204
- client = Savon.client(
205
- wsdl: wsdl,
206
- endpoint: @endpoint,
207
- soap_header: headers(category),
208
- convert_request_keys_to: :none,
209
- pretty_print_xml: true
210
- )
195
+ client = Savon.client(configuration(wsdl: wsdl, soap_header: headers(category)))
211
196
  end
212
197
 
213
198
  def security_call(method, message_hash={})
@@ -1,3 +1,3 @@
1
1
  module BigMachines
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,14 @@
1
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
2
+ <soapenv:Body>
3
+ <soapenv:Fault>
4
+ <faultcode>soapenv:Server</faultcode>
5
+ <faultstring>COMMERCE-ERR:No transactions were found for the given ID, 266898199</faultstring>
6
+ <detail xmlns:bm="urn:soap.bigmachines.com">
7
+ <bm:fault>
8
+ <bm:exceptionCode>COMMERCE-ERR</bm:exceptionCode>
9
+ <bm:exceptionMessage>No transactions were found for the given ID, 266898199</bm:exceptionMessage>
10
+ </bm:fault>
11
+ </detail>
12
+ </soapenv:Fault>
13
+ </soapenv:Body>
14
+ </soapenv:Envelope>
@@ -0,0 +1,10 @@
1
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
2
+ <soapenv:Body>
3
+ <bm:updateTransactionResponse xmlns:bm="urn:soap.bigmachines.com">
4
+ <bm:status>
5
+ <bm:success>true</bm:success>
6
+ <bm:message>Successfully processed API for newtempge at Sat Sep 20 11:23:05 CDT 2014</bm:message>
7
+ </bm:status>
8
+ </bm:updateTransactionResponse>
9
+ </soapenv:Body>
10
+ </soapenv:Envelope>
@@ -24,7 +24,7 @@ describe BigMachines::Client do
24
24
  stub = stub_login_request({with_body: login_body})
25
25
  stub.to_return(:status => 200, :body => fixture("login_response"))
26
26
 
27
- subject.login(username: 'jheth', password: 'changeme')
27
+ subject.login('jheth', 'changeme')
28
28
  end
29
29
  end
30
30
 
@@ -66,6 +66,8 @@ describe BigMachines::Client do
66
66
  describe "getTransaction" do
67
67
  it "returns transaction with specific attributes" do
68
68
 
69
+ # NOTE: return_specific_attributes is optional
70
+ # All attributes are returned when not defined.
69
71
  body = %Q{
70
72
  <bm:getTransaction>
71
73
  <bm:transaction>
@@ -98,6 +100,67 @@ describe BigMachines::Client do
98
100
  expect(quote_line_items.length).to eq(109)
99
101
  expect(quote_line_items.first[:_model_id]).to eq("17400975")
100
102
  end
103
+
104
+ it "returns not found error" do
105
+
106
+ # NOTE: return_specific_attributes is optional
107
+ # All attributes are returned when not defined.
108
+ body = %Q{
109
+ <bm:getTransaction>
110
+ <bm:transaction>
111
+ <bm:id>265393499</bm:id>
112
+ <bm:return_specific_attributes>
113
+ <bm:documents>
114
+ <bm:document>
115
+ <bm:var_name>quote_process</bm:var_name>
116
+ </bm:document>
117
+ </bm:documents>
118
+ </bm:return_specific_attributes>
119
+ </bm:transaction>
120
+ </bm:getTransaction>
121
+ }.gsub(/^\s+/, '').gsub(/[\n]/, '').gsub("bm:", "targetNamespace:")
122
+
123
+ stub = stub_commerce_request({with_body: body, fixture: 'get_transaction_not_found_response'})
124
+
125
+ expect {
126
+ subject.get_transaction(265393499)
127
+ }.to raise_error(Savon::SOAPFault)
128
+ end
129
+
130
+ end
131
+
132
+ describe "updateTransaction" do
133
+ it "confirms that transaction was updated" do
134
+
135
+ body = %Q{
136
+ <bm:updateTransaction>
137
+ <bm:transaction>
138
+ <bm:id>26539349</bm:id>
139
+ <bm:data_xml>
140
+ <bm:quote_process bs_id="26539349" data_type="0" document_number="1">
141
+ <bm:opportunityName_quote>Test Oppty Auto Approval TinderBox</bm:opportunityName_quote>
142
+ <bm:siteName_quote>MY DUMMY SITE</bm:siteName_quote>
143
+ <bm:notesCMPM_es>http://subdomain.mytinder.com/view/X2Y58?version=1</bm:notesCMPM_es>
144
+ </bm:quote_process>
145
+ </bm:data_xml>
146
+ <bm:action_data>
147
+ <bm:action_var_name>_update_line_items</bm:action_var_name>
148
+ </bm:action_data>
149
+ </bm:transaction>
150
+ </bm:updateTransaction>
151
+ }.gsub(/^\s+/, '').gsub(/[\n]/, '').gsub("bm:", "targetNamespace:")
152
+
153
+ stub = stub_commerce_request({with_body: body, fixture: 'update_transaction_response'})
154
+
155
+ data = {
156
+ opportunityName_quote: "Test Oppty Auto Approval TinderBox",
157
+ siteName_quote: "MY DUMMY SITE",
158
+ notesCMPM_es: "http://subdomain.mytinder.com/view/X2Y58?version=1"
159
+ }
160
+ response = subject.update_transaction(26539349, data)
161
+
162
+ expect(response[:status][:success]).to eq(true)
163
+ end
101
164
  end
102
165
  end
103
166
 
@@ -6,11 +6,6 @@ module FixtureHelpers
6
6
  stub_api_request(options)
7
7
  end
8
8
 
9
- def stub_security_request(options={})
10
- options = options.merge({headers: {service: :security}})
11
- stub_api_request(options)
12
- end
13
-
14
9
  def stub_api_request(options={})
15
10
  options = {
16
11
  :method => :post,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: big_machines
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Heth
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-17 00:00:00.000000000 Z
11
+ date: 2014-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: savon
@@ -17,7 +17,7 @@ dependencies:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: 2.3.0
20
- - - ! '>='
20
+ - - '>='
21
21
  - !ruby/object:Gem::Version
22
22
  version: 2.3.0
23
23
  type: :runtime
@@ -27,7 +27,7 @@ dependencies:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: 2.3.0
30
- - - ! '>='
30
+ - - '>='
31
31
  - !ruby/object:Gem::Version
32
32
  version: 2.3.0
33
33
  - !ruby/object:Gem::Dependency
@@ -51,7 +51,7 @@ dependencies:
51
51
  - - ~>
52
52
  - !ruby/object:Gem::Version
53
53
  version: 2.14.0
54
- - - ! '>='
54
+ - - '>='
55
55
  - !ruby/object:Gem::Version
56
56
  version: 2.14.0
57
57
  type: :development
@@ -61,7 +61,7 @@ dependencies:
61
61
  - - ~>
62
62
  - !ruby/object:Gem::Version
63
63
  version: 2.14.0
64
- - - ! '>='
64
+ - - '>='
65
65
  - !ruby/object:Gem::Version
66
66
  version: 2.14.0
67
67
  - !ruby/object:Gem::Dependency
@@ -71,7 +71,7 @@ dependencies:
71
71
  - - ~>
72
72
  - !ruby/object:Gem::Version
73
73
  version: 1.13.0
74
- - - ! '>='
74
+ - - '>='
75
75
  - !ruby/object:Gem::Version
76
76
  version: 1.13.0
77
77
  type: :development
@@ -81,7 +81,7 @@ dependencies:
81
81
  - - ~>
82
82
  - !ruby/object:Gem::Version
83
83
  version: 1.13.0
84
- - - ! '>='
84
+ - - '>='
85
85
  - !ruby/object:Gem::Version
86
86
  version: 1.13.0
87
87
  - !ruby/object:Gem::Dependency
@@ -91,7 +91,7 @@ dependencies:
91
91
  - - ~>
92
92
  - !ruby/object:Gem::Version
93
93
  version: 0.7.1
94
- - - ! '>='
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.7.1
97
97
  type: :development
@@ -101,7 +101,7 @@ dependencies:
101
101
  - - ~>
102
102
  - !ruby/object:Gem::Version
103
103
  version: 0.7.1
104
- - - ! '>='
104
+ - - '>='
105
105
  - !ruby/object:Gem::Version
106
106
  version: 0.7.1
107
107
  description: BigMachine's SOAP API Implementation
@@ -124,12 +124,14 @@ files:
124
124
  - lib/big_machines/version.rb
125
125
  - resources/commerce.wsdl.xml
126
126
  - resources/security.wsdl.xml
127
+ - spec/fixtures/get_transaction_not_found_response.xml
127
128
  - spec/fixtures/get_transaction_response.xml
128
129
  - spec/fixtures/get_transaction_response_full.xml
129
130
  - spec/fixtures/get_user_info_response.xml
130
131
  - spec/fixtures/login_response.xml
131
132
  - spec/fixtures/logout_response.xml
132
133
  - spec/fixtures/set_session_currency_response.xml
134
+ - spec/fixtures/update_transaction_response.xml
133
135
  - spec/lib/client_spec.rb
134
136
  - spec/spec_helper.rb
135
137
  - spec/support/fixture_helpers.rb
@@ -143,27 +145,29 @@ require_paths:
143
145
  - lib
144
146
  required_ruby_version: !ruby/object:Gem::Requirement
145
147
  requirements:
146
- - - ! '>='
148
+ - - '>='
147
149
  - !ruby/object:Gem::Version
148
150
  version: '0'
149
151
  required_rubygems_version: !ruby/object:Gem::Requirement
150
152
  requirements:
151
- - - ! '>='
153
+ - - '>='
152
154
  - !ruby/object:Gem::Version
153
155
  version: '0'
154
156
  requirements: []
155
157
  rubyforge_project:
156
- rubygems_version: 2.2.2
158
+ rubygems_version: 2.2.1
157
159
  signing_key:
158
160
  specification_version: 4
159
161
  summary: Communicate with BigMachine's SOAP API
160
162
  test_files:
163
+ - spec/fixtures/get_transaction_not_found_response.xml
161
164
  - spec/fixtures/get_transaction_response.xml
162
165
  - spec/fixtures/get_transaction_response_full.xml
163
166
  - spec/fixtures/get_user_info_response.xml
164
167
  - spec/fixtures/login_response.xml
165
168
  - spec/fixtures/logout_response.xml
166
169
  - spec/fixtures/set_session_currency_response.xml
170
+ - spec/fixtures/update_transaction_response.xml
167
171
  - spec/lib/client_spec.rb
168
172
  - spec/spec_helper.rb
169
173
  - spec/support/fixture_helpers.rb