executrix 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b487dbd03be2bba6970d2b6fc7af64b598e0b04
4
- data.tar.gz: b6a6808797fa0485fc062fc8a2daac55ef3cc081
3
+ metadata.gz: adbfe678d21169065c727f7b0f11e9871398a5f8
4
+ data.tar.gz: 4d5baaf178dc01c99abf9e653aeadba6633d9576
5
5
  SHA512:
6
- metadata.gz: 99ca83a6dd6b0d8c0eec9b200d997aa44e75ae4893e6c6059b728f5b5fc537395820f727d5dd16960c326f8205ff2bb1894a1d7e930d681638f415c2c6330649
7
- data.tar.gz: ac1a3ace185b9b92f15fad6afaf17a65674421e2420ad7c812029079c912ee8ab80625f4a32194b5fa512c3e1cf23d320bf64ec5989fc11aa509be1232c8f2a3
6
+ metadata.gz: 2cfc598c3a8448f4a3efd3bf378d50b8ea2aa98827dfb3ecce236d685d1ac6cd51cf2445e073ccd91fe8a7bfc49ceff5bb679d37237449ecbf6cb83688577705
7
+ data.tar.gz: 12ff55f6dad093df4ca29a8d5e835b1ce3e58c869b52490df0ceb80b805d91f1f95450a567266489281b60a4a7cf1debb8de23da1f205c2a3234d59166fe87a8
@@ -1,5 +1,7 @@
1
1
  module Executrix
2
2
  class Batch
3
+ attr_reader :job_id
4
+
3
5
  def initialize connection, job_id, batch_id
4
6
  @connection = connection
5
7
  @job_id = job_id
@@ -39,6 +41,14 @@ module Executrix
39
41
  @connection.query_batch_result_data(@job_id, @batch_id, @result_id)
40
42
  end
41
43
 
44
+ def raw_request
45
+ @connection.raw_request
46
+ end
47
+
48
+ def raw_result
49
+ @connection.raw_result
50
+ end
51
+
42
52
  private
43
53
  def init_result_id
44
54
  result_raw = @connection.query_batch_result_id(@job_id, @batch_id)
@@ -1,5 +1,8 @@
1
1
  module Executrix
2
2
  class Connection
3
+ attr_reader :raw_request
4
+ attr_reader :raw_result
5
+
3
6
  def initialize(username, password, api_version, sandbox)
4
7
  @username = username
5
8
  @password = password
@@ -73,7 +76,7 @@ module Executrix
73
76
  end
74
77
 
75
78
  def query_batch_result_data job_id, batch_id, result_id
76
- Executrix::Http.query_batch_result_data(
79
+ @raw_result = Executrix::Http.query_batch_result_data(
77
80
  @instance,
78
81
  @session_id,
79
82
  job_id,
@@ -81,25 +84,28 @@ module Executrix
81
84
  result_id,
82
85
  @api_version,
83
86
  )
87
+ Executrix::Helper.parse_csv @raw_result
84
88
  end
85
89
 
86
90
  def add_file_upload_batch job_id, filename
91
+ @raw_request = File.read(filename)
87
92
  Executrix::Http.add_file_upload_batch(
88
93
  @instance,
89
94
  @session_id,
90
95
  job_id,
91
- filename,
96
+ @raw_request,
92
97
  @api_version)[:id]
93
98
  end
94
99
 
95
100
  def add_batch job_id, records
96
101
  return -1 if records.nil? || records.empty?
102
+ @raw_request = Executrix::Helper.records_to_csv(records)
97
103
 
98
104
  Executrix::Http.add_batch(
99
105
  @instance,
100
106
  @session_id,
101
107
  job_id,
102
- Executrix::Helper.records_to_csv(records),
108
+ @raw_request,
103
109
  @api_version)[:id]
104
110
  end
105
111
 
@@ -65,5 +65,9 @@ module Executrix
65
65
  def absolute_to_relative_path input, replacement
66
66
  input.gsub(/(^C:[\/\\])|(^\/)/,replacement)
67
67
  end
68
+
69
+ def parse_csv csv_string
70
+ CSV.parse(csv_string, headers: true).map{|r| r.to_hash}
71
+ end
68
72
  end
69
73
  end
@@ -38,11 +38,10 @@ module Executrix
38
38
 
39
39
  def query_batch_result_data *args
40
40
  r = Http::Request.query_batch_result_data(*args)
41
- process_csv_response(process_http_request(r))
41
+ normalize_csv(process_http_request(r))
42
42
  end
43
43
 
44
- def add_file_upload_batch instance, session_id, job_id, filename, api_version
45
- data = File.read(filename)
44
+ def add_file_upload_batch instance, session_id, job_id, data, api_version
46
45
  headers = {
47
46
  'Content-Type' => 'zip/csv',
48
47
  'X-SFDC-Session' => session_id}
@@ -82,8 +81,8 @@ module Executrix
82
81
  res.values.first
83
82
  end
84
83
 
85
- def process_csv_response res
86
- CSV.parse(res.gsub(/\n\s+/, "\n"), headers: true).map{|r| r.to_hash}
84
+ def normalize_csv res
85
+ res.gsub(/\n\s+/, "\n")
87
86
  end
88
87
 
89
88
  def process_soap_response res
@@ -1,3 +1,3 @@
1
1
  module Executrix
2
- VERSION = '1.2.2'
2
+ VERSION = '1.3.0'
3
3
  end
@@ -56,4 +56,18 @@ describe Executrix::Batch do
56
56
  .to raise_error(StandardError, expected_error_message)
57
57
  end
58
58
  end
59
+
60
+ [:request, :result].each do |action|
61
+ let(:connection) { double('Executrix::Connection') }
62
+ let(:request_result) { 'Generic Result/Request' }
63
+ describe "#raw_#{action}" do
64
+
65
+ it 'sends correct messages to connection' do
66
+ b = described_class.new nil, nil, nil
67
+ b.instance_variable_set '@connection', connection
68
+ expect(connection).to receive(:"raw_#{action}").and_return(request_result)
69
+ expect(b.send(:"raw_#{action}")).to eq(request_result)
70
+ end
71
+ end
72
+ end
59
73
  end
@@ -14,6 +14,7 @@ describe Executrix::Connection do
14
14
  }.each do |method_name, num_of_params|
15
15
  describe "##{method_name}" do
16
16
  it 'delegates correctly to Http class' do
17
+ allow(Executrix::Helper).to receive(:parse_csv).and_return([])
17
18
  expect(Executrix::Http)
18
19
  .to receive(method_name)
19
20
  .and_return({})
@@ -217,4 +217,21 @@ describe Executrix::Helper do
217
217
  to eq('a/forwardslash/path')
218
218
  end
219
219
  end
220
+
221
+ describe '.parse_csv' do
222
+ let(:csv_string) {
223
+ "Id,my_external_id__c\n" \
224
+ "003M000057GH39aIAD,K-00J799\n" \
225
+ "003M001200KO82cIAD,K-015699"
226
+ }
227
+ let(:expected_result) {
228
+ [
229
+ { 'Id' => '003M000057GH39aIAD', 'my_external_id__c' => 'K-00J799' },
230
+ { 'Id' => '003M001200KO82cIAD', 'my_external_id__c' => 'K-015699' },
231
+ ]
232
+ }
233
+ it 'correctly transforms csv string' do
234
+ expect(described_class.parse_csv(csv_string)).to eq(expected_result)
235
+ end
236
+ end
220
237
  end
@@ -317,22 +317,18 @@ describe Executrix::Http do
317
317
  "003K001200KO82cIAD","King of the Hill"}
318
318
  end
319
319
 
320
- it 'returns array of arrays for data' do
320
+ it 'returns a correctly formatted CSV string' do
321
321
  expect(Executrix::Http).to receive(:process_http_request)
322
322
  .and_return(batch_result_data_success)
323
323
  result = Executrix::Http.query_batch_result_data('a','b','c','d','e','f')
324
- expect(result).to eq([
325
- {'Id' => '003M000057GH39aIAD', 'my_external_id__c' => 'K-00J799'},
326
- {'Id' => '003M001200KO82cIAD', 'my_external_id__c' => 'K-015699'}])
324
+ expect(result).to eq(batch_result_data_success.gsub(/^\s+/, ''))
327
325
  end
328
326
 
329
- it 'returns correct array with spaces' do
327
+ it 'returns a correctly formatted CSV string including spaces' do
330
328
  expect(Executrix::Http).to receive(:process_http_request)
331
329
  .and_return(batch_result_data_with_spaces_success)
332
330
  result = Executrix::Http.query_batch_result_data('a','b','c','d','e','f')
333
- expect(result).to eq([
334
- {'Id' => '003K000057GH39aIAD', 'Name' => 'Master of Disaster'},
335
- {'Id' => '003K001200KO82cIAD', 'Name' => 'King of the Hill'}])
331
+ expect(result).to eq(batch_result_data_with_spaces_success.gsub(/^\s+/, ''))
336
332
  end
337
333
  end
338
334
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: executrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jorge Valdivia
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-05 00:00:00.000000000 Z
12
+ date: 2014-02-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake