zuora_api 1.9.09 → 1.10.0

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
  SHA256:
3
- metadata.gz: a6da8c9fbf54221b62336d0221ada0f53e9d22690b7a6a52cd83f214314b5ba5
4
- data.tar.gz: be31b09eef19df8b8d1fcbd70b9a11980f125c4eb4d5f96c3259ed516ab88934
3
+ metadata.gz: 17131e6d6129f3831868f5a029b5c1f781e7fb31ca31fddd682b8bd0a3994f68
4
+ data.tar.gz: 748d5ac46b7647dd5ebfaf2338de458a2ff42e65d138b045dcd40e1eb5741f2d
5
5
  SHA512:
6
- metadata.gz: d6382ae611e80b38e574357baa771b432c4e554662293e98e4a73ca446c9445264d902f0b604ee071fe9dac6cf6bee4fde8319f0f782975955fdd562cf921b6c
7
- data.tar.gz: 1008b0e7e533e01b6636cc82e3e79b21c825d095d789d83c73c96142d9de78556c0caa38775aedb97a3b27e43a93f16281680f10a7d988fb005951084a36f75e
6
+ metadata.gz: 289f4b0e533dbc666d649017ca97669525adc14976d135bbd9191955f5fe70384c3506261d65b89071752e1a23137593d70cb4afd47805a67a2b400e34e7fe3f
7
+ data.tar.gz: c85623dad76f6c4d02a49bbdddb602191c709576717cc2fad66a2b5324ff9824469fb3d1a70e98ad07c477a3b0191e47e1c5890e93bd7a13aaf5937302d0b8e4
@@ -45,9 +45,9 @@ module ZuoraAPI
45
45
  ZuoraAPI::Exceptions::ZuoraUnexpectedError
46
46
  ].freeze
47
47
 
48
- attr_accessor :region, :url, :wsdl_number, :current_session, :bearer_token, :oauth_session_expires_at, :environment, :status, :errors, :current_error, :user_info, :tenant_id, :tenant_name, :entity_id, :timeout_sleep, :hostname, :zconnect_provider
48
+ attr_accessor :region, :url, :wsdl_number, :current_session, :bearer_token, :oauth_session_expires_at, :environment, :status, :errors, :current_error, :user_info, :tenant_id, :tenant_name, :entity_id, :entity_identifier, :entity_header_type, :timeout_sleep, :hostname, :zconnect_provider
49
49
 
50
- def initialize(url: nil, entity_id: nil, session: nil, status: nil, bearer_token: nil, oauth_session_expires_at: nil, **keyword_args)
50
+ def initialize(url: nil, entity_id: nil, entity_identifier: nil, session: nil, status: nil, bearer_token: nil, oauth_session_expires_at: nil, **keyword_args)
51
51
  raise "URL is nil or empty, but URL is required" if url.nil? || url.empty?
52
52
  # raise "URL is improper. URL must contain zuora.com, zuora.eu, or zuora.na" if /zuora.com|zuora.eu|zuora.na/ === url
53
53
  self.hostname = /(?<=https:\/\/|http:\/\/)(.*?)(?=\/|$)/.match(url)[0] if !/(?<=https:\/\/|http:\/\/)(.*?)(?=\/|$)/.match(url).nil?
@@ -61,6 +61,8 @@ module ZuoraAPI
61
61
  self.url = url
62
62
  end
63
63
  self.entity_id = get_entity_id(entity_id: entity_id)
64
+ self.entity_identifier = entity_identifier
65
+ self.entity_header_type = :entity_id
64
66
  self.errors = Hash.new
65
67
  self.current_session = session
66
68
  self.bearer_token = bearer_token
@@ -1022,12 +1024,41 @@ module ZuoraAPI
1022
1024
  return self.get_file(url: self.aqua_endpoint("file/#{fileId}"))
1023
1025
  end
1024
1026
 
1027
+ def entity_header
1028
+ if self.entity_header_type == :entity_name && self.entity_identifier.present?
1029
+ { "entityName" => self.entity_identifier }
1030
+ elsif self.entity_id.present?
1031
+ { "Zuora-Entity-Ids" => self.entity_id }
1032
+ else
1033
+ {}
1034
+ end
1035
+ end
1036
+
1037
+ def insert_entity_header(destination_headers, lookup_headers: nil)
1038
+ # The entity header may be added to a place other than where we look for it
1039
+ lookup_headers = destination_headers if lookup_headers.nil?
1040
+
1041
+ entity_header_options = %w(zuora-entity-ids entityid entityname)
1042
+ # If the customer doesn't supply an entity header, fill it in
1043
+ if (entity_header_options & lookup_headers.keys.map(&:downcase)).blank?
1044
+ entity_header = self.entity_header
1045
+ if entity_header.present?
1046
+ destination_headers.merge!(entity_header)
1047
+ entity_header_options_to_exclude =
1048
+ entity_header_options.
1049
+ reject { |header| header == entity_header.keys.first&.downcase }
1050
+ destination_headers.delete_if { |key, _| entity_header_options_to_exclude.include?(key.to_s.downcase) }
1051
+ end
1052
+ end
1053
+ end
1054
+
1025
1055
  def describe_call(object = nil, log_errors = true)
1026
1056
  tries ||= 2
1027
1057
 
1028
1058
  base = self.url.include?(".com") ? self.url.split(".com")[0].concat(".com") : self.url.split(".eu")[0].concat(".eu")
1029
1059
  url = object ? "#{base}/apps/api/describe/#{object}" : "#{base}/apps/api/describe/"
1030
- headers = self.entity_id.present? ? {"Zuora-Entity-Ids" => self.entity_id, 'Content-Type' => "text/xml; charset=utf-8"} : {'Content-Type' => "text/xml; charset=utf-8"}
1060
+ headers = { "Content-Type" => "text/xml; charset=utf-8" }.merge(self.entity_header)
1061
+
1031
1062
  response = HTTParty.get(url, headers: {"Authorization" => self.get_session(prefix: true, auth_type: :basic), "User-Agent" => USER_AGENT}.merge(headers), :timeout => 130)
1032
1063
 
1033
1064
  raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new(self.current_error.present? ? self.current_error : 'Describe call 401', response) if response.code == 401
@@ -1114,10 +1145,8 @@ module ZuoraAPI
1114
1145
  authentication_headers = {}
1115
1146
  if z_session
1116
1147
  authentication_headers = {"Authorization" => self.get_session(prefix: true, auth_type: session_type, zuora_track_id: zuora_track_id) }
1117
- if self.entity_id.present?
1118
- authentication_headers["Zuora-Entity-Ids"] = self.entity_id if headers.dig("Zuora-Entity-Ids").nil?
1119
- authentication_headers.delete_if { |key, value| ["entityId", "entityName"].include?(key.to_s) }
1120
- end
1148
+
1149
+ self.insert_entity_header(authentication_headers, lookup_headers: headers)
1121
1150
  end
1122
1151
  headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
1123
1152
  headers['User-Agent'] = USER_AGENT
@@ -1282,7 +1311,8 @@ module ZuoraAPI
1282
1311
  http.use_ssl = true if !uri.scheme.nil? && uri.scheme.downcase == 'https'
1283
1312
  if z_session
1284
1313
  headers = headers.merge({"Authorization" => self.get_session(prefix: true)})
1285
- headers = headers.merge({"Zuora-Entity-Ids" => self.entity_id}) if !self.entity_id.blank?
1314
+
1315
+ self.insert_entity_header(headers)
1286
1316
  end
1287
1317
 
1288
1318
  headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
@@ -32,7 +32,7 @@ module ZuoraAPI
32
32
  end
33
33
 
34
34
  def get_z_session(debug: false, zuora_track_id: nil)
35
- headers = self.entity_id.present? ? {"Zuora-Entity-Ids" => self.entity_id } : {}
35
+ headers = self.entity_header
36
36
  headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
37
37
  output_json, response = self.rest_call(:url => self.rest_endpoint("connections"), :session_type => :bearer, :headers => headers)
38
38
  begin
@@ -1,3 +1,3 @@
1
1
  module ZuoraAPI
2
- VERSION = "1.9.09"
2
+ VERSION = "1.10.0"
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: 1.9.09
4
+ version: 1.10.0
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: 2021-08-04 00:00:00.000000000 Z
11
+ date: 2021-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler