big_machines 0.1.1 → 0.2.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
- MGU3N2Y1NGU1MWFjMGE5ZmM1Y2Y0YjM4ZmUyODQ0M2Q5YjEzNTIyYQ==
5
- data.tar.gz: !binary |-
6
- NTIzNDc1MmE0MWI4NTliZTJlNWNiYWNhNGZlZDliMmRlZGIyM2E4YQ==
2
+ SHA1:
3
+ metadata.gz: a216a48de5944b2b2fcc7543074ec46e8f191d10
4
+ data.tar.gz: 1155a7074e956c23aadca7031020c90c13f8a10e
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- NzhkOGM4YzQzMjUwYjJkYmZkNDlmNTc5Yjk0NjU3N2EwMzBmNjBjMDlmMDRi
10
- ZmVhYjk4ODkxNWMzYjgwYjNlMjczMDE2MTgzNzY4Y2Q5YTY1MTdjMmQxYmZk
11
- ZGE5MmRhMTdmZjM4Y2FjMGExOTg1MzJjZTQ0OTdmODdhYmExYjY=
12
- data.tar.gz: !binary |-
13
- MGFjZGE2Y2Q2ZDBhYTVmNjM2ZGVhZWE3NGE1ODdhN2JjYzEyNWZiNjI5NTlm
14
- MDJhMTczMWVhYTlhNmI3MzFjNTAzZjhmZThkMTI0ZTIyMmY3MDc5MGNlZTRm
15
- ZWQwMDM2MzdiOGVlNTg0NTNiODNkYzU0OTJiODlkZTc3ZDdlZTY=
6
+ metadata.gz: 1aca170032182d3009e486b4d737d4d2a570d0572297e62f183b9ed4fd40abae8d6525ae82b1a831d2befa277f8f77642a32ba26a7cf6126c9b076b96dc0f117
7
+ data.tar.gz: bb9c99b32b5a8e8d2cbf125a380299f1b1d308385e5b760af7d7ddc44d0341bff72bea19527f33bfbe8e5b32d04fda0502fe5be3af5cf17b2bfd90fb8e8d502e
data/.travis.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
3
+ - 2.0.0
4
4
  notifications:
5
5
  email:
6
6
  recipients:
data/README.md CHANGED
@@ -63,6 +63,8 @@ client.get_user_info
63
63
  # => Hash[:user_info]
64
64
  ```
65
65
 
66
+ #### Commerce
67
+
66
68
  ### get_transaction
67
69
 
68
70
  ```ruby
@@ -79,6 +81,30 @@ client.update_transaction(id, data={notesCMPM_es: "Sample Notes"})
79
81
  # => Hash[:status]
80
82
  ```
81
83
 
84
+ #### Attachments
85
+
86
+ ### get_attachment
87
+
88
+ ```ruby
89
+ # Retrieve Single File Attachment
90
+ client.get_attachment(transaction_id, "uploadTemplate_File")
91
+ # => BigMachines::Attachment
92
+ ```
93
+
94
+ ### upload_attachment
95
+
96
+ ```ruby
97
+ # Upload File Attachment
98
+ client.upload_attachment(transaction_id, file, "uploadTemplate_File")
99
+ # => {status: true, message: '...'}
100
+ ```
101
+ ### delete_attachment
102
+
103
+ ```ruby
104
+ # Delete File Attachement
105
+ client.delete_attachment(transaction_id, "uploadTemplate_File")
106
+ # => {status: true, message: '...'}
107
+ ```
82
108
 
83
109
  ### logout
84
110
 
data/lib/big_machines.rb CHANGED
@@ -3,6 +3,7 @@ require "big_machines/version"
3
3
  require 'savon'
4
4
  require "big_machines/client"
5
5
  require "big_machines/transaction"
6
+ require "big_machines/attachment"
6
7
 
7
8
  module BigMachines
8
9
  # Your code goes here...
@@ -0,0 +1,21 @@
1
+ module BigMachines
2
+ class Attachment
3
+ attr_reader :raw_attachment
4
+
5
+ def initialize(entry)
6
+ @raw_attachment = entry
7
+ end
8
+
9
+ def write(file_path)
10
+ data = Base64.strict_decode64(@raw_attachment[:file_content])
11
+ File.open(file_path, 'wb') do |f|
12
+ f.write(data)
13
+ end
14
+ end
15
+
16
+ def method_missing(method, *args)
17
+ @raw_attachment[method]
18
+ end
19
+
20
+ end
21
+ end
@@ -156,6 +156,73 @@ module BigMachines
156
156
  commerce_call(:update_transaction, transaction)
157
157
  end
158
158
 
159
+ # Returns a single BigMachines::Attachment based on the variable_name provided.
160
+ def get_attachment(transaction_id, variable_name, document_number: 1, mode: "content", inline: true)
161
+
162
+ export = {
163
+ mode: mode,
164
+ inline: inline,
165
+ attachments: {
166
+ attachment: {
167
+ document_number: document_number,
168
+ variable_name: variable_name
169
+ }
170
+ },
171
+ transaction: {
172
+ process_var_name: @process_var_name,
173
+ id: transaction_id
174
+ }
175
+ }
176
+
177
+ result = commerce_call(:export_file_attachments, export)
178
+
179
+ attachments = []
180
+ result[:attachments].each do |key, data|
181
+ attachments << BigMachines::Attachment.new(data)
182
+ end
183
+
184
+ attachments
185
+ end
186
+
187
+ # Uploads a single file to the specified field in BigMachines
188
+ def upload_attachment(transaction_id, file, variable_name, document_number: 1)
189
+
190
+ import = {
191
+ mode: 'update',
192
+ attachments: {
193
+ attachment: {
194
+ document_number: document_number,
195
+ variable_name: variable_name,
196
+ filename: file.path,
197
+ file_content: Base64.strict_encode64(file.read)
198
+ }
199
+ },
200
+ transaction: {
201
+ process_var_name: @process_var_name,
202
+ id: transaction_id
203
+ }
204
+ }
205
+ commerce_call(:import_file_attachments, import)
206
+ end
207
+
208
+ # Deletes the file associated with the specified field in BigMachines.
209
+ def delete_attachment(transaction_id, variable_name, document_number: 1)
210
+ delete = {
211
+ mode: 'delete',
212
+ attachments: {
213
+ attachment: {
214
+ document_number: document_number,
215
+ variable_name: variable_name
216
+ }
217
+ },
218
+ transaction: {
219
+ process_var_name: @process_var_name,
220
+ id: transaction_id
221
+ }
222
+ }
223
+ commerce_call(:import_file_attachments, delete)
224
+ end
225
+
159
226
  # Supports the following No Argument methods:
160
227
  # get_user_info
161
228
  # logout
@@ -8,8 +8,12 @@ module BigMachines
8
8
  @transaction = response[:transaction]
9
9
  # Quote
10
10
  @quote_process = @transaction[:data_xml][:quote_process]
11
- # Quote Line Items
12
- @line_process = @quote_process[:sub_documents][:line_process]
11
+ # Line Items
12
+ @line_process = if @quote_process[:sub_documents].is_a?(Hash)
13
+ @quote_process[:sub_documents][:line_process]
14
+ else
15
+ []
16
+ end
13
17
  end
14
18
 
15
19
  def method_missing(method, *args)
@@ -1,3 +1,3 @@
1
1
  module BigMachines
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,28 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <soapenv:Header>
4
+ <bm:userInfo xmlns:bm="urn:soap.bigmachines.com">
5
+ <bm:sessionId>82CAAC6A7EE8DBBE4C30931F3B4A88A6</bm:sessionId>
6
+ </bm:userInfo>
7
+ <bm:category xmlns:bm="urn:soap.bigmachines.com">Commerce</bm:category>
8
+ <bm:xsdInfo xmlns:bm="urn:soap.bigmachines.com">
9
+ <bm:schemaLocation>https://newtempge.bigmachines.com/bmfsweb/newtempge/schema/v1_0/commerce/quotes_process_bmClone_16.xsd</bm:schemaLocation>
10
+ </bm:xsdInfo>
11
+ </soapenv:Header>
12
+ <soapenv:Body>
13
+ <bm:exportFileAttachments xmlns:bm="urn:soap.bigmachines.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
14
+ <bm:mode>content</bm:mode>
15
+ <bm:inline>true</bm:inline>
16
+ <bm:attachments>
17
+ <bm:attachment>
18
+ <bm:document_number>1</bm:document_number>
19
+ <bm:variable_name>uploadEngineeringTemplate_File</bm:variable_name>
20
+ </bm:attachment>
21
+ </bm:attachments>
22
+ <bm:transaction>
23
+ <bm:process_var_name>quotes_process_bmClone_16</bm:process_var_name>
24
+ <bm:id>34706909</bm:id>
25
+ </bm:transaction>
26
+ </bm:exportFileAttachments>
27
+ </soapenv:Body>
28
+ </soapenv:Envelope>
@@ -0,0 +1,20 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <soapenv:Body>
4
+ <bm:exportFileAttachmentsResponse xmlns:bm="urn:soap.bigmachines.com">
5
+ <bm:status>
6
+ <bm:success>true</bm:success>
7
+ <bm:message>Mon Mar 30 11:25:16 CDT 2015 - Successfully processed API for newtempge</bm:message>
8
+ </bm:status>
9
+ <bm:id>34706909</bm:id>
10
+ <bm:attachments>
11
+ <bm:attachment>
12
+ <bm:document_number>1</bm:document_number>
13
+ <bm:variable_name>uploadEngineeringTemplate_File</bm:variable_name>
14
+ <bm:filename>1020636-38959 Rev 0.docx</bm:filename>
15
+ <bm:file_content>UEsDBBQABgAIAAAAIQDQt2tlKQIAAJILAAATAACiBAIooAACAAAA==</bm:file_content>
16
+ </bm:attachment>
17
+ </bm:attachments>
18
+ </bm:exportFileAttachmentsResponse>
19
+ </soapenv:Body>
20
+ </soapenv:Envelope>
@@ -0,0 +1,28 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <soapenv:Header>
4
+ <bm:userInfo xmlns:bm="urn:soap.bigmachines.com">
5
+ <bm:sessionId>82CAAC6A7EE8DBBE4C30931F3B4A88A6</bm:sessionId>
6
+ </bm:userInfo>
7
+ <bm:category xmlns:bm="urn:soap.bigmachines.com">Commerce</bm:category>
8
+ <bm:xsdInfo xmlns:bm="urn:soap.bigmachines.com">
9
+ <bm:schemaLocation>https://newtempge.bigmachines.com/bmfsweb/newtempge/schema/v1_0/commerce/quotes_process_bmClone_16.xsd</bm:schemaLocation>
10
+ </bm:xsdInfo>
11
+ </soapenv:Header>
12
+ <soapenv:Body>
13
+ <bm:exportFileAttachments xmlns:bm="urn:soap.bigmachines.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
14
+ <bm:mode>content</bm:mode>
15
+ <bm:inline/>
16
+ <bm:attachments>
17
+ <bm:attachment>
18
+ <bm:document_number>1</bm:document_number>
19
+ <bm:variable_name>uploadEngineeringTemplate_File</bm:variable_name>
20
+ </bm:attachment>
21
+ </bm:attachments>
22
+ <bm:transaction>
23
+ <bm:process_var_name>quotes_process_bmClone_16</bm:process_var_name>
24
+ <bm:id>34706909</bm:id>
25
+ </bm:transaction>
26
+ </bm:exportFileAttachments>
27
+ </soapenv:Body>
28
+ </soapenv:Envelope>
@@ -0,0 +1,20 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <soapenv:Body>
4
+ <bm:exportFileAttachmentsResponse xmlns:bm="urn:soap.bigmachines.com">
5
+ <bm:status>
6
+ <bm:success>true</bm:success>
7
+ <bm:message>Mon Mar 30 11:08:34 CDT 2015 - Successfully processed API for newtempge</bm:message>
8
+ </bm:status>
9
+ <bm:id>34706909</bm:id>
10
+ <bm:attachments>
11
+ <bm:attachment>
12
+ <bm:document_number>1</bm:document_number>
13
+ <bm:variable_name>uploadEngineeringTemplate_File</bm:variable_name>
14
+ <bm:filename>1020636-38959 Rev 0.docx</bm:filename>
15
+ <bm:file_content bm:href="cid:1020636-38959_Rev_0.docx@newtempge.bigmachines.com"/>
16
+ </bm:attachment>
17
+ </bm:attachments>
18
+ </bm:exportFileAttachmentsResponse>
19
+ </soapenv:Body>
20
+ </soapenv:Envelope>
@@ -0,0 +1,28 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <soapenv:Header>
4
+ <bm:userInfo xmlns:bm="urn:soap.bigmachines.com">
5
+ <bm:sessionId>82CAAC6A7EE8DBBE4C30931F3B4A88A6</bm:sessionId>
6
+ </bm:userInfo>
7
+ <bm:category xmlns:bm="urn:soap.bigmachines.com">Commerce</bm:category>
8
+ <bm:xsdInfo xmlns:bm="urn:soap.bigmachines.com">
9
+ <bm:schemaLocation>https://newtempge.bigmachines.com/bmfsweb/newtempge/schema/v1_0/commerce/quotes_process_bmClone_16.xsd</bm:schemaLocation>
10
+ </bm:xsdInfo>
11
+ </soapenv:Header>
12
+ <soapenv:Body>
13
+ <bm:exportFileAttachments xmlns:bm="urn:soap.bigmachines.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
14
+ <bm:mode>metadata</bm:mode>
15
+ <bm:inline/>
16
+ <bm:attachments>
17
+ <bm:attachment>
18
+ <bm:document_number>1</bm:document_number>
19
+ <bm:variable_name>uploadEngineeringTemplate_File</bm:variable_name>
20
+ </bm:attachment>
21
+ </bm:attachments>
22
+ <bm:transaction>
23
+ <bm:process_var_name>quotes_process_bmClone_16</bm:process_var_name>
24
+ <bm:id>34706909</bm:id>
25
+ </bm:transaction>
26
+ </bm:exportFileAttachments>
27
+ </soapenv:Body>
28
+ </soapenv:Envelope>
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <soapenv:Body>
4
+ <bm:exportFileAttachmentsResponse xmlns:bm="urn:soap.bigmachines.com">
5
+ <bm:status>
6
+ <bm:success>true</bm:success>
7
+ <bm:message>Mon Mar 30 11:16:27 CDT 2015 - Successfully processed API for newtempge</bm:message>
8
+ </bm:status>
9
+ <bm:id>34706909</bm:id>
10
+ <bm:attachments>
11
+ <bm:attachment>
12
+ <bm:document_number>1</bm:document_number>
13
+ <bm:variable_name>uploadEngineeringTemplate_File</bm:variable_name>
14
+ <bm:filename>1020636-38959 Rev 0.docx</bm:filename>
15
+ <bm:size>404695</bm:size>
16
+ <bm:added_date>2015-03-25 13:09:39</bm:added_date>
17
+ <bm:last_modified_date>2015-03-25 13:09:39</bm:last_modified_date>
18
+ </bm:attachment>
19
+ </bm:attachments>
20
+ </bm:exportFileAttachmentsResponse>
21
+ </soapenv:Body>
22
+ </soapenv:Envelope>
@@ -0,0 +1,27 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <soapenv:Header>
4
+ <bm:userInfo xmlns:bm="urn:soap.bigmachines.com">
5
+ <bm:sessionId>82CAAC6A7EE8DBBE4C30931F3B4A88A6</bm:sessionId>
6
+ </bm:userInfo>
7
+ <bm:category xmlns:bm="urn:soap.bigmachines.com">Commerce</bm:category>
8
+ <bm:xsdInfo xmlns:bm="urn:soap.bigmachines.com">
9
+ <bm:schemaLocation>https://newtempge.bigmachines.com/bmfsweb/newtempge/schema/v1_0/commerce/quotes_process_bmClone_16.xsd</bm:schemaLocation>
10
+ </bm:xsdInfo>
11
+ </soapenv:Header>
12
+ <soapenv:Body>
13
+ <bm:importFileAttachments xmlns:bm="urn:soap.bigmachines.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
14
+ <bm:mode>delete</bm:mode>
15
+ <bm:attachments>
16
+ <bm:attachment>
17
+ <bm:document_number>1</bm:document_number>
18
+ <bm:variable_name>uploadEngineeringTemplate_File</bm:variable_name>
19
+ </bm:attachment>
20
+ </bm:attachments>
21
+ <bm:transaction>
22
+ <bm:process_var_name>quotes_process_bmClone_16</bm:process_var_name>
23
+ <bm:id>34706909</bm:id>
24
+ </bm:transaction>
25
+ </bm:importFileAttachments>
26
+ </soapenv:Body>
27
+ </soapenv:Envelope>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <soapenv:Body>
4
+ <bm:importFileAttachmentsResponse xmlns:bm="urn:soap.bigmachines.com">
5
+ <bm:status>
6
+ <bm:success>true</bm:success>
7
+ <bm:message>Mon Mar 30 16:00:33 CDT 2015 - Successfully processed API for newtempge</bm:message>
8
+ </bm:status>
9
+ </bm:importFileAttachmentsResponse>
10
+ </soapenv:Body>
11
+ </soapenv:Envelope>
@@ -0,0 +1,29 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <soapenv:Header>
4
+ <bm:userInfo xmlns:bm="urn:soap.bigmachines.com">
5
+ <bm:sessionId>82CAAC6A7EE8DBBE4C30931F3B4A88A6</bm:sessionId>
6
+ </bm:userInfo>
7
+ <bm:category xmlns:bm="urn:soap.bigmachines.com">Commerce</bm:category>
8
+ <bm:xsdInfo xmlns:bm="urn:soap.bigmachines.com">
9
+ <bm:schemaLocation>https://newtempge.bigmachines.com/bmfsweb/newtempge/schema/v1_0/commerce/quotes_process_bmClone_16.xsd</bm:schemaLocation>
10
+ </bm:xsdInfo>
11
+ </soapenv:Header>
12
+ <soapenv:Body>
13
+ <bm:importFileAttachments xmlns:bm="urn:soap.bigmachines.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
14
+ <bm:mode>update</bm:mode>
15
+ <bm:attachments>
16
+ <bm:attachment>
17
+ <bm:document_number>1</bm:document_number>
18
+ <bm:variable_name>uploadEngineeringTemplate_File</bm:variable_name>
19
+ <bm:filename>NewProposal.docx</bm:filename>
20
+ <bm:file_content>UEsDBBQABgAIAAAAIQDQt2tlKQIAAJILAAATAACiBAIooAACAAAA==</bm:file_content>
21
+ </bm:attachment>
22
+ </bm:attachments>
23
+ <bm:transaction>
24
+ <bm:process_var_name>quotes_process_bmClone_16</bm:process_var_name>
25
+ <bm:id>34706909</bm:id>
26
+ </bm:transaction>
27
+ </bm:importFileAttachments>
28
+ </soapenv:Body>
29
+ </soapenv:Envelope>
@@ -101,8 +101,7 @@ describe BigMachines::Client do
101
101
  expect(quote_line_items.first[:_model_id]).to eq("17400975")
102
102
  end
103
103
 
104
- it "returns not found error" do
105
-
104
+ it "returns not found error" do
106
105
  # NOTE: return_specific_attributes is optional
107
106
  # All attributes are returned when not defined.
108
107
  body = %Q{
@@ -162,6 +161,167 @@ describe BigMachines::Client do
162
161
  expect(response[:status][:success]).to eq(true)
163
162
  end
164
163
  end
165
- end
166
164
 
165
+ describe "exportFileAttachments" do
166
+ it "returns metadata for attachments" do
167
+
168
+ body = %Q{
169
+ <bm:exportFileAttachments>
170
+ <bm:mode>metadata</bm:mode>
171
+ <bm:inline>true</bm:inline>
172
+ <bm:attachments>
173
+ <bm:attachment>
174
+ <bm:document_number>1</bm:document_number>
175
+ <bm:variable_name>uploadEngineeringTemplate_File</bm:variable_name>
176
+ </bm:attachment>
177
+ </bm:attachments>
178
+ <bm:transaction>
179
+ <bm:process_var_name>quotes_process_bmClone_16</bm:process_var_name>
180
+ <bm:id>34706909</bm:id>
181
+ </bm:transaction>
182
+ </bm:exportFileAttachments>
183
+ }.gsub(/^\s+/, '').gsub(/[\n]/, '').gsub("bm:", "targetNamespace:")
184
+
185
+ stub = stub_commerce_request({with_body: body, fixture: 'export_file_attachments_metadata_response'})
186
+
187
+ attachments = subject.get_attachment(34706909, "uploadEngineeringTemplate_File", mode: 'metadata')
188
+
189
+ expect(attachments).to be_a(Array)
190
+ expect(attachments.size).to eq(1)
191
+
192
+ file = attachments.first
193
+ expect(file.filename).to eq('1020636-38959 Rev 0.docx')
194
+ expect(file.size).to eq('404695')
195
+ expect(file.added_date).to eq('2015-03-25 13:09:39')
196
+ expect(file.last_modified_date).to eq('2015-03-25 13:09:39')
197
+ end
198
+
199
+ it "returns inline content for attachments" do
200
+
201
+ body = %Q{
202
+ <bm:exportFileAttachments>
203
+ <bm:mode>content</bm:mode>
204
+ <bm:inline>true</bm:inline>
205
+ <bm:attachments>
206
+ <bm:attachment>
207
+ <bm:document_number>1</bm:document_number>
208
+ <bm:variable_name>uploadEngineeringTemplate_File</bm:variable_name>
209
+ </bm:attachment>
210
+ </bm:attachments>
211
+ <bm:transaction>
212
+ <bm:process_var_name>quotes_process_bmClone_16</bm:process_var_name>
213
+ <bm:id>34706909</bm:id>
214
+ </bm:transaction>
215
+ </bm:exportFileAttachments>
216
+ }.gsub(/^\s+/, '').gsub(/[\n]/, '').gsub("bm:", "targetNamespace:")
217
+
218
+ stub = stub_commerce_request({with_body: body, fixture: 'export_file_attachments_content_inline_response'})
219
+
220
+ attachments = subject.get_attachment(34706909, "uploadEngineeringTemplate_File")
221
+
222
+ expect(attachments).to be_a(Array)
223
+ expect(attachments.size).to eq(1)
224
+
225
+ file = attachments.first
226
+ expect(file.filename).to eq('1020636-38959 Rev 0.docx')
227
+ expect(file.file_content).to eq('UEsDBBQABgAIAAAAIQDQt2tlKQIAAJILAAATAACiBAIooAACAAAA==')
228
+ end
229
+
230
+ it "returns content for attachments using mime boundary" do
231
+
232
+ body = %Q{
233
+ <bm:exportFileAttachments>
234
+ <bm:mode>content</bm:mode>
235
+ <bm:inline>false</bm:inline>
236
+ <bm:attachments>
237
+ <bm:attachment>
238
+ <bm:document_number>1</bm:document_number>
239
+ <bm:variable_name>uploadEngineeringTemplate_File</bm:variable_name>
240
+ </bm:attachment>
241
+ </bm:attachments>
242
+ <bm:transaction>
243
+ <bm:process_var_name>quotes_process_bmClone_16</bm:process_var_name>
244
+ <bm:id>34706909</bm:id>
245
+ </bm:transaction>
246
+ </bm:exportFileAttachments>
247
+ }.gsub(/^\s+/, '').gsub(/[\n]/, '').gsub("bm:", "targetNamespace:")
248
+
249
+ stub = stub_commerce_request({with_body: body, fixture: 'export_file_attachments_content_response'})
250
+
251
+ attachments = subject.get_attachment(34706909, "uploadEngineeringTemplate_File", inline: false)
252
+
253
+ expect(attachments).to be_a(Array)
254
+ expect(attachments.size).to eq(1)
255
+
256
+ file = attachments.first
257
+ expect(file.filename).to eq('1020636-38959 Rev 0.docx')
258
+ expect(file.file_content[:"@bm:href"]).to eq("cid:1020636-38959_Rev_0.docx@newtempge.bigmachines.com")
259
+ end
260
+
261
+ end
262
+
263
+ describe "importFileAttachments" do
264
+ it "uploads new file attachment" do
265
+
266
+ contents = "This is a test"
267
+ encoded = Base64.strict_encode64(contents)
268
+
269
+ body = %Q{
270
+ <bm:importFileAttachments>
271
+ <bm:mode>update</bm:mode>
272
+ <bm:attachments>
273
+ <bm:attachment>
274
+ <bm:document_number>1</bm:document_number>
275
+ <bm:variable_name>uploadEngineeringTemplate_File</bm:variable_name>
276
+ <bm:filename>NewProposal.txt</bm:filename>
277
+ <bm:file_content>#{encoded}</bm:file_content>
278
+ </bm:attachment>
279
+ </bm:attachments>
280
+ <bm:transaction>
281
+ <bm:process_var_name>quotes_process_bmClone_16</bm:process_var_name>
282
+ <bm:id>34706909</bm:id>
283
+ </bm:transaction>
284
+ </bm:importFileAttachments>
285
+ }.gsub(/^\s+/, '').gsub(/[\n]/, '').gsub("bm:", "targetNamespace:")
286
+
287
+ stub = stub_commerce_request({with_body: body, fixture: 'import_file_attachments_response'})
288
+
289
+ File.open('NewProposal.txt', 'w') {|f| f.write(contents) }
290
+ file = File.open('NewProposal.txt')
291
+ response = subject.upload_attachment(34706909, file, "uploadEngineeringTemplate_File")
292
+
293
+ File.unlink('NewProposal.txt')
294
+
295
+ expect(response[:status][:success]).to eq(true)
296
+ end
297
+
298
+ it "deletes file attachment" do
299
+
300
+ body = %Q{
301
+ <bm:importFileAttachments>
302
+ <bm:mode>delete</bm:mode>
303
+ <bm:attachments>
304
+ <bm:attachment>
305
+ <bm:document_number>1</bm:document_number>
306
+ <bm:variable_name>uploadEngineeringTemplate_File</bm:variable_name>
307
+ </bm:attachment>
308
+ </bm:attachments>
309
+ <bm:transaction>
310
+ <bm:process_var_name>quotes_process_bmClone_16</bm:process_var_name>
311
+ <bm:id>34706909</bm:id>
312
+ </bm:transaction>
313
+ </bm:importFileAttachments>
314
+ }.gsub(/^\s+/, '').gsub(/[\n]/, '').gsub("bm:", "targetNamespace:")
315
+
316
+ stub = stub_commerce_request({with_body: body, fixture: 'import_file_attachments_response'})
317
+
318
+ response = subject.delete_attachment(34706909, "uploadEngineeringTemplate_File")
319
+
320
+ expect(response[:status][:success]).to eq(true)
321
+ end
322
+
323
+ end
324
+
325
+ end
326
+ # Commerce API
167
327
  end
metadata CHANGED
@@ -1,20 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: big_machines
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.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-11-17 00:00:00.000000000 Z
11
+ date: 2015-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: savon
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: 2.3.0
20
20
  - - <
@@ -24,7 +24,7 @@ dependencies:
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - ! '>='
27
+ - - '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: 2.3.0
30
30
  - - <
@@ -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
@@ -119,15 +119,25 @@ files:
119
119
  - Rakefile
120
120
  - big_machines.gemspec
121
121
  - lib/big_machines.rb
122
+ - lib/big_machines/attachment.rb
122
123
  - lib/big_machines/client.rb
123
124
  - lib/big_machines/transaction.rb
124
125
  - lib/big_machines/version.rb
125
126
  - resources/commerce.wsdl.xml
126
127
  - resources/security.wsdl.xml
128
+ - spec/fixtures/export_file_attachments_content_inline_request.xml
129
+ - spec/fixtures/export_file_attachments_content_inline_response.xml
130
+ - spec/fixtures/export_file_attachments_content_request.xml
131
+ - spec/fixtures/export_file_attachments_content_response.xml
132
+ - spec/fixtures/export_file_attachments_metadata_request.xml
133
+ - spec/fixtures/export_file_attachments_metadata_response.xml
127
134
  - spec/fixtures/get_transaction_not_found_response.xml
128
135
  - spec/fixtures/get_transaction_response.xml
129
136
  - spec/fixtures/get_transaction_response_full.xml
130
137
  - spec/fixtures/get_user_info_response.xml
138
+ - spec/fixtures/import_file_attachments_delete_request.xml
139
+ - spec/fixtures/import_file_attachments_response.xml
140
+ - spec/fixtures/import_file_attachments_update_request.xml
131
141
  - spec/fixtures/login_response.xml
132
142
  - spec/fixtures/logout_response.xml
133
143
  - spec/fixtures/set_session_currency_response.xml
@@ -145,25 +155,34 @@ require_paths:
145
155
  - lib
146
156
  required_ruby_version: !ruby/object:Gem::Requirement
147
157
  requirements:
148
- - - ! '>='
158
+ - - '>='
149
159
  - !ruby/object:Gem::Version
150
160
  version: '0'
151
161
  required_rubygems_version: !ruby/object:Gem::Requirement
152
162
  requirements:
153
- - - ! '>='
163
+ - - '>='
154
164
  - !ruby/object:Gem::Version
155
165
  version: '0'
156
166
  requirements: []
157
167
  rubyforge_project:
158
- rubygems_version: 2.2.2
168
+ rubygems_version: 2.4.5
159
169
  signing_key:
160
170
  specification_version: 4
161
171
  summary: Communicate with BigMachine's SOAP API
162
172
  test_files:
173
+ - spec/fixtures/export_file_attachments_content_inline_request.xml
174
+ - spec/fixtures/export_file_attachments_content_inline_response.xml
175
+ - spec/fixtures/export_file_attachments_content_request.xml
176
+ - spec/fixtures/export_file_attachments_content_response.xml
177
+ - spec/fixtures/export_file_attachments_metadata_request.xml
178
+ - spec/fixtures/export_file_attachments_metadata_response.xml
163
179
  - spec/fixtures/get_transaction_not_found_response.xml
164
180
  - spec/fixtures/get_transaction_response.xml
165
181
  - spec/fixtures/get_transaction_response_full.xml
166
182
  - spec/fixtures/get_user_info_response.xml
183
+ - spec/fixtures/import_file_attachments_delete_request.xml
184
+ - spec/fixtures/import_file_attachments_response.xml
185
+ - spec/fixtures/import_file_attachments_update_request.xml
167
186
  - spec/fixtures/login_response.xml
168
187
  - spec/fixtures/logout_response.xml
169
188
  - spec/fixtures/set_session_currency_response.xml