zuora_api 1.3.997 → 1.3.999

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: 244b6ef47daa9d5f30620630e70e9b2917670213
4
- data.tar.gz: 4591349f6ac4f7ffaca7fdf9d9f1399655b167d4
3
+ metadata.gz: b138340746df0535ad03c3e1f69e9ccc74a7c9f1
4
+ data.tar.gz: 1921d1fa811273a169b53e090dc080c44d9902cb
5
5
  SHA512:
6
- metadata.gz: 457dfca43748e6817c814dcec4d7dac354a4a8f041f770a902a1c275c9cf85bfbcc87f934fa5f84bce8194495dcb0e491c0f9fffe19ab6373affecfb610c6482
7
- data.tar.gz: 0a4cfe45d894b0abad532d6858e52ec8428c4db8690b45afea76661cb2ea2f595c1adc217afb2effb7ae473aeba434aeb68de6db667887755c5a8e04a83aad25
6
+ metadata.gz: 2ae9cf95d5f69554653542e388a9e85add970e6584c3a3fec5aedae8de6bc913fe466d17604c0c5830252e041280cb10ae5940a21605111fe13d355e41b5ecce
7
+ data.tar.gz: d9b99dff207ab9ea38707b4d49bfcb87d12424caaafae989045248d1d6a73fdedcc888bc217df9ba9f6bb8cc4a1137ed49a612f88493478b62d3972078c3a168
@@ -79,8 +79,8 @@ module ZuoraAPI
79
79
  end
80
80
  end
81
81
 
82
- def fileURL
83
- return self.url.split(".com").first.concat(".com/apps/api/file/")
82
+ def fileURL(url="")
83
+ return self.url.split(".com").first.concat(".com/apps/api/file/").concat(url)
84
84
  end
85
85
 
86
86
  def dateFormat
@@ -275,7 +275,7 @@ module ZuoraAPI
275
275
  return getFileById(id: response[0]["id"])
276
276
  end
277
277
 
278
- def getFileById(id: "")
278
+ def getFileById(id: "2c92c0f85e7f88ff015e86b8f8f4517f")
279
279
  response = nil
280
280
  result = "new"
281
281
  while result != "completed" do
@@ -288,10 +288,9 @@ module ZuoraAPI
288
288
  end
289
289
  end
290
290
  fileId = response["batches"][0]["fileId"]
291
- return self.get_file(file_name: "#{fileId}.csv", url: self.aqua_endpoint("file/#{fileId}"), headers: {"Authorization" => "ZSession " + self.current_session, 'Content-Type' => "application/json; charset=utf-8"},file_type: "csv")
291
+ return self.get_file(url: self.aqua_endpoint("file/#{fileId}"))
292
292
  end
293
293
 
294
-
295
294
  def describe_call(object = nil)
296
295
  self.get_session
297
296
  base = self.url.include?(".com") ? self.url.split(".com")[0].concat(".com") : self.url.split(".eu")[0].concat(".eu")
@@ -389,8 +388,8 @@ module ZuoraAPI
389
388
  return self
390
389
  end
391
390
 
392
- def get_catalog
393
- products, catalog_map, response = [{}, {}, {'nextPage' => self.rest_endpoint('catalog/products?pageSize=40') }]
391
+ def get_catalog(page_size: 40)
392
+ products, catalog_map, response = [{}, {}, {'nextPage' => self.rest_endpoint("catalog/products?pageSize=#{page_size}") }]
394
393
  while !response["nextPage"].blank?
395
394
  url = self.rest_endpoint(response["nextPage"].split('/v1/').last)
396
395
  Rails.logger.debug("Fetch Catalog URL #{url}")
@@ -421,7 +420,7 @@ module ZuoraAPI
421
420
  return products, catalog_map
422
421
  end
423
422
 
424
- def get_file(file_name: nil, file_type: nil, url: nil, headers: {}, count: 3, z_session: true, tempfile: true, file_path: Rails.root.join('tmp'), **execute_params)
423
+ def get_file(url: nil, headers: {}, count: 3, z_session: true, tempfile: true, file_path: Rails.root.join('tmp'), **execute_params)
425
424
  raise "file_path must be of class Pathname" if file_path.class != Pathname
426
425
 
427
426
  #Make sure directory exists
@@ -448,7 +447,7 @@ module ZuoraAPI
448
447
  raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new(self.current_error) if count <= 0
449
448
  Rails.logger.fatal("Unauthorized: Retry")
450
449
  self.new_session
451
- return get_file(:file_name => file_name, :file_type => file_type, :url => url, :headers => headers, :count => count - 1, :z_session => z_session, :tempfile => tempfile, :file_path => file_path)
450
+ return get_file(:url => url, :headers => headers, :count => count - 1, :z_session => z_session, :tempfile => tempfile, :file_path => file_path)
452
451
 
453
452
  when Net::HTTPClientError
454
453
  Rails.logger.debug("Login: #{self.username} Export")
@@ -471,10 +470,10 @@ module ZuoraAPI
471
470
  when /.*; filename=/
472
471
  full_filename = /.*; filename=(.*)/.match(response.header["Content-Disposition"])[1].strip
473
472
  end
474
- file_ending = file_type.present? ? ".#{file_type}" : ".#{full_filename.partition(".").last}"
473
+ file_ending = ".#{full_filename.partition(".").last}"
475
474
  end
476
475
  #If user supplied a filename use it, else default to content header filename, else default to uri pattern
477
- filename = file_name.present? ? file_name : full_filename.present? ? full_filename.split(file_ending).first : File.basename(uri.path).rpartition('.').first
476
+ filename = full_filename.present? ? full_filename.split(file_ending).first : File.basename(uri.path).rpartition('.').first
478
477
 
479
478
  if response.header["Content-Type"].present?
480
479
  case response.header["Content-Type"]
@@ -517,6 +516,7 @@ module ZuoraAPI
517
516
  end
518
517
  end
519
518
 
519
+ Rails.logger.debug("Filepath: #{file_handle.path}")
520
520
  file_handle.close
521
521
  return file_handle
522
522
  end
@@ -528,8 +528,6 @@ module ZuoraAPI
528
528
  end
529
529
  end
530
530
 
531
-
532
-
533
531
  def getDataSourceExport(query, extract: true, encrypted: false, zip: true)
534
532
  Rails.logger.info('Export') {"Build export"}
535
533
  Rails.logger.info('Export query') {"#{query}"}
@@ -583,31 +581,20 @@ module ZuoraAPI
583
581
  end
584
582
  file_id = output_xml.xpath('//ns2:FileId', 'ns2' =>'http://object.api.zuora.com/').text
585
583
  Rails.logger.info('Export') {'=====> Export finished'}
586
- zip_file = get_file(:url => "#{self.fileURL}#{file_id}?file-id=#{file_id}")
584
+ export_file = get_file(:url => self.fileURL(file_id))
585
+ export_file_path = export_file.path
586
+ Rails.logger.info('Export') {"=====> Export path #{export_file.path}"}
587
+
587
588
  if extract && zip
588
- location = extract_zip(zip_file.path, "#{file_id}")
589
- File.delete(zip_file.path)
590
- return location
591
- elsif !zip
592
- file = get_file(:url => "#{self.fileURL}#{file_id}?file-id=#{file_id}", headers: {"Authorization" => "ZSession " + self.current_session})
593
- puts file.path
594
- return file.path
589
+ new_path = export_file_path.partition('.zip').first
590
+ zipped = Zip::File.open(export_file_path)
591
+ file_handle = zipped.entries.first
592
+ file_handle.extract(new_path)
593
+ File.delete(export_file_path)
594
+ return new_path
595
595
  else
596
- return zip_file.path
597
- end
598
- end
599
-
600
- def extract_zip(file,filename)
601
- files = Array.new
602
- FileUtils.mkdir_p("#{Rails.root}/tmp/#{filename}")
603
- ::Zip::File.open(file) do |zip_file|
604
- zip_file.each do |f|
605
- files << "#{Rails.root}/tmp/#{filename}/#{f.name}"
606
- fpath = File.join("#{Rails.root}/tmp/#{filename}", f.name)
607
- zip_file.extract(f, fpath) unless File.exist?(fpath)
608
- end
596
+ return export_file_path
609
597
  end
610
- return files
611
598
  end
612
599
 
613
600
  def query(query)
@@ -1,3 +1,3 @@
1
1
  module ZuoraAPI
2
- VERSION = "1.3.997"
2
+ VERSION = "1.3.999"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zuora_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.997
4
+ version: 1.3.999
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zuora Strategic Solutions Group