zuora_api 0.2.6.5 → 0.2.6.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9c1f8874502663f7cdee03e9070150a4a4a00f8
4
- data.tar.gz: 25aad3a7dcb1641458d3c2534b7d5fa70dcc8d49
3
+ metadata.gz: 1053ff11c1376a088bd917846d947ad723474283
4
+ data.tar.gz: e8362876fe1320b101392870e2343670243b98f0
5
5
  SHA512:
6
- metadata.gz: f42b415b8c7fdddb15c28c5473e8697246af6b31fbe29021dc0ee3621c63a792b561211ffa6b035ceb6015a38740256d87ca680716e930754bd84d6583217bac
7
- data.tar.gz: f644c667eb2585a42523985fea64c50164b5a0731524af4473f6dede562324049208c8eaf3153884859ce8342643a4ef86109f8b03a7e3a6927c4043ac82c666
6
+ metadata.gz: ab9da8db92b5687dc45646530ec128b0061cd16814d3125a9305c3b7ad5fa905932fa23fa27977a2971bf7fb0994d2a64b52b11e28f2b40dac2c611417286608
7
+ data.tar.gz: d7fdb8d1e2bf9eb71f3dc6d30ea99b63e99db1670e5e641cf77c0bf34dbecfa940af9dddfee11d9439c65ea279f856394d44b48b4322e3f8b7c5656961a10717
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zuora_api (0.2.6.5)
4
+ zuora_api (0.2.6.6)
5
5
  httparty
6
6
  nokogiri (~> 1.6.8)
7
7
  railties (>= 4.1.0, < 5.1)
@@ -1,4 +1,5 @@
1
1
  require "httparty"
2
+ require "zip"
2
3
  require "nokogiri"
3
4
  module ZuoraAPI
4
5
  class Login
@@ -316,7 +317,7 @@ module ZuoraAPI
316
317
  temp_file ||= tmp_file
317
318
  tmp_file.binmode if (response.to_hash["content-type"].include?("application/zip") || response.to_hash["content-type"] == "application/zip")
318
319
  response.read_body do |chunk|
319
- tmp_file.write chunk
320
+ tmp_file.write chunk.force_encoding("UTF-8")
320
321
  end
321
322
  end if response.is_a?(Net::HTTPSuccess)
322
323
  end
@@ -333,7 +334,7 @@ module ZuoraAPI
333
334
  return temp_file
334
335
  end
335
336
 
336
- def getDataSourceExport(query)
337
+ def getDataSourceExport(query, extract: true)
337
338
  Rails.logger.info('Export') {"Build export"}
338
339
  Rails.logger.info('Export query') {"#{query}"}
339
340
  request = Nokogiri::XML::Builder.new do |xml|
@@ -385,44 +386,25 @@ module ZuoraAPI
385
386
  end
386
387
  file_id = output_xml.xpath('//ns2:FileId', 'ns2' =>'http://object.api.zuora.com/').text
387
388
  Rails.logger.info('Export') {'=====> Export finished'}
388
- #return get_file(:file_name => "data_export#{Time.now}.csv" ,:url => "#{self.fileURL}#{file_id}?file-id=#{file_id}", headers: {"Authorization" => "ZSession " + self.current_session})
389
+ zip_file = get_file(:file_name => "#{file_id}.zip" ,:url => "#{self.fileURL}#{file_id}?file-id=#{file_id}", headers: {"Authorization" => "ZSession " + self.current_session})
390
+ if extract
391
+ location = extract_zip(zip_file.path, "#{file_id}")
392
+ File.delete(zip_file.path)
393
+ return location
394
+ else
395
+ return zip_file.path
396
+ end
397
+ end
389
398
 
390
- response_query = HTTParty.get(self.fileURL + file_id, body: request.to_xml, headers: {"Authorization" => "ZSession " + self.current_session}, query: {"file-id" => file_id})
391
- Rails.logger.info('Export') {'=====> Export finished'}
392
- list = Array.new
393
- headers = Array.new
394
- i=0
395
- Zip::Archive.open_buffer(response_query.body) do |ar|
396
- ar.fopen(0) do |zf|
397
- open(zf.name, 'wb') do |f|
398
- CSV.parse(zf.read) do |row|
399
- j=0
400
- values = Hash.new
401
- storename = ''
402
- row.each do |col|
403
- if i == 0
404
- headers[j] = col
405
- else
406
- #Is this needed - can just store all dates as string
407
- if headers[j].include? 'CreatedDate'
408
- values[headers[j]] = Date.strptime(row[j], self.dateFormat)
409
- elsif row[j].nil?
410
- values[headers[j]] = ''
411
- else
412
- values[headers[j]] = row[j]
413
- end
414
- end
415
- j += 1
416
- end
417
- if i!=0
418
- list[i-1] = values
419
- end
420
- i += 1
421
- end
422
- end
399
+ def extract_zip(file,filename)
400
+ FileUtils.mkdir_p("#{Rails.root}/tmp/#{filename}")
401
+ ::Zip::File.open(file) do |zip_file|
402
+ zip_file.each do |f|
403
+ fpath = File.join("#{Rails.root}/tmp/#{filename}", f.name)
404
+ zip_file.extract(f, fpath) unless File.exist?(fpath)
423
405
  end
424
406
  end
425
- return list
407
+ return "#{Rails.root}/tmp/#{filename}"
426
408
  end
427
409
 
428
410
  def query(query)
@@ -1,3 +1,3 @@
1
1
  module ZuoraAPI
2
- VERSION = "0.2.6.5"
2
+ VERSION = "0.2.6.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zuora_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6.5
4
+ version: 0.2.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zuora Strategic Solutions Group
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-16 00:00:00.000000000 Z
11
+ date: 2016-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler