zuora_connect 2.0.60o → 2.0.60t

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
  SHA256:
3
- metadata.gz: 7d82918ec805d77782d6697f71fa0e28c85c75d243632207a2930046aeacdc60
4
- data.tar.gz: 9f2341b491fbb516259cd0ace04482da657f688000609ba6cca99a9d85437fc6
3
+ metadata.gz: d7eee2d7cabce6128892afac88428f3c7f77a3318e244bd3becdf521716d0a25
4
+ data.tar.gz: 12c07009df449c54d70bec094e16594f0a3ecdb251c59ffed230d64787939cfb
5
5
  SHA512:
6
- metadata.gz: '059e06f6514b2580a013cedf8e37843936465f44c1b55020d0fc790862b3f983b6ecac6696c2b899db8eba94bfccf6fe431b8ae7422c1ef241b1c833652b87a1'
7
- data.tar.gz: 0174a924a7291780e970718d2c98a6bf43819eae85f4b71afd43f5f4214b357587967cd3072d7f9996d21fe97897903f5e4da9d0bcce7b4915421982dcef3d72
6
+ metadata.gz: a45196b2a77449c349e1e1fe4b9853d08e35da763327e2f74134cee20f4ee4af9311a4298b048b937d1d4f5056e047f0db503f57b3b36f2335a963fe4e1f3336
7
+ data.tar.gz: d3d14ec18ce3da9ad27776cf2c79ed3b7f9aafa88c331f3a0efa9a2075258cf438e3dd469c50ba1e4d0e46d339ec0ba895632535ab9644dd8cf4a29513d77f7d
@@ -22,6 +22,9 @@ module ZuoraConnect
22
22
  CONNECT_APPLICATION_ID = 0
23
23
  CONNECT_COMMUNICATION_SLEEP = Rails.env.test? ? 0.seconds : 5.seconds
24
24
  CATALOG_LOOKUP_PAGE_SIZE = 10_000
25
+ CATALOG_LOOKUP_CACHE_TIME_KEY = 'CatalogCachedAt'
26
+ CATALOG_LOOKUP_TTL = 60.seconds
27
+ CATALOG_LOOKUP_CACHE_RESULT_KEY = 'CatalogCache'
25
28
  IGNORED_LOCALS = ['fr', 'ja', 'es', 'zh', 'de']
26
29
  INTERNAL_HOSTS = []
27
30
  LOGIN_TENANT_DESTINATION = 'target_login'
@@ -1015,25 +1018,29 @@ module ZuoraConnect
1015
1018
  end
1016
1019
 
1017
1020
  if source == 'API'
1018
- zuora_login = self.login_lookup(type: 'Zuora').first
1019
- login = zuora_login.client(entity_reference)
1020
-
1021
1021
  catalog_container = {}
1022
- response = {
1023
- 'nextPage' => login.rest_endpoint("catalog/products?pageSize=#{CATALOG_LOOKUP_PAGE_SIZE}")
1024
- }
1025
- while response['nextPage'].present?
1026
- url = login.rest_endpoint(response['nextPage'].split('/v1/').last)
1027
- output_json, response = login.rest_call(debug: false, url: url, timeout_retry: true)
1028
-
1029
- case object
1030
- when :product
1031
- output_json.fetch('products', []).each do |product|
1032
- if object_id.nil?
1033
- catalog_container[product['id']] = product.except('productRatePlans')
1034
- elsif object_id.is_a?(String)
1035
- next unless product['id'] == object_id
1036
1022
 
1023
+ if (Redis.current.hget(CATALOG_LOOKUP_CACHE_TIME_KEY, self.id).to_i + CATALOG_LOOKUP_TTL.to_i) > Time.now.to_i
1024
+ begin
1025
+ catalog_container = JSON.parse(Redis.current.hget(CATALOG_LOOKUP_CACHE_RESULT_KEY, self.id))
1026
+ rescue JSON::ParserError => ex
1027
+ Rails.logger.warn('Failed to parse catalog cache', ex)
1028
+ end
1029
+ else
1030
+ zuora_login = self.login_lookup(type: 'Zuora').first
1031
+ login = zuora_login.client(entity_reference)
1032
+
1033
+ response = {
1034
+ 'nextPage' => login.rest_endpoint("catalog/products?pageSize=#{CATALOG_LOOKUP_PAGE_SIZE}")
1035
+ }
1036
+
1037
+ while response['nextPage'].present?
1038
+ url = login.rest_endpoint(response['nextPage'].split('/v1/').last)
1039
+ output_json, response = login.rest_call(debug: false, url: url, timeout_retry: true)
1040
+
1041
+ case object
1042
+ when :product
1043
+ output_json.fetch('products', []).each do |product|
1037
1044
  rate_plans = {}
1038
1045
  product['productRatePlans'].each do |rate_plan|
1039
1046
  charges = {}
@@ -1058,13 +1065,23 @@ module ZuoraConnect
1058
1065
  end
1059
1066
 
1060
1067
  product['productRatePlans'] = rate_plans
1061
- catalog_container = product
1068
+ catalog_container[product['id']] = product
1062
1069
  end
1070
+ else
1071
+ raise "Available objects include [:product]"
1063
1072
  end
1064
- else
1065
- raise "Available objects include [:product]"
1066
1073
  end
1074
+
1075
+ Redis.current.hset(CATALOG_LOOKUP_CACHE_RESULT_KEY, self.id, catalog_container.to_json)
1076
+ Redis.current.hset(CATALOG_LOOKUP_CACHE_TIME_KEY, self.id, Time.now.to_i)
1067
1077
  end
1078
+
1079
+ if object_id.nil?
1080
+ catalog_container.transform_values! { |v| v.except('productRatePlans') }
1081
+ elsif object_id.is_a?(String)
1082
+ catalog_container = catalog_container[object_id]
1083
+ end
1084
+
1068
1085
  return catalog_container
1069
1086
  end
1070
1087
 
@@ -2,6 +2,6 @@ module ZuoraConnect
2
2
  class ZuoraUser < ActiveRecord::Base
3
3
  self.table_name = "zuora_users"
4
4
  attr_accessor :session
5
- cattr_accessor :current_user
5
+ cattr_accessor :current_user_id
6
6
  end
7
7
  end
@@ -33,6 +33,8 @@ if defined? Prometheus
33
33
  file.write(Prometheus::Client::Formats::Text.marshal(@registry))
34
34
  end
35
35
  end
36
+ rescue
37
+ # Ignored
36
38
  end
37
39
  end
38
40
 
@@ -442,7 +442,7 @@ module ZuoraConnect
442
442
  @zuora_user = ZuoraConnect::ZuoraUser.create!(:zuora_user_id => zuora_user_id, :zuora_identity_response => {zuora_entity_id => session["ZuoraCurrentIdentity"]})
443
443
  end
444
444
  @zuora_user.session = session
445
- ZuoraConnect::ZuoraUser.current_user = @zuora_user
445
+ ZuoraConnect::ZuoraUser.current_user_id = zuora_user_id
446
446
  session["#{@appinstance.id}::user::localUserId"] = @zuora_user.id
447
447
  session["#{@appinstance.id}::user::email"] = session['ZuoraCurrentIdentity']["username"]
448
448
  session["#{@appinstance.id}::user::timezone"] = session['ZuoraCurrentIdentity']["timeZone"]
@@ -685,7 +685,7 @@ module ZuoraConnect
685
685
  key = ZuoraConnect.configuration.dev_mode_pass
686
686
  values = {:user => user , :key => key, :appinstance => session["appInstance"]}
687
687
  @appinstance = ZuoraConnect::AppInstance.find_by(:id => values[:appinstance].to_i)
688
- ZuoraConnect::ZuoraUser.current_user = user
688
+ ZuoraConnect::ZuoraUser.current_user_id = 0
689
689
  if @appinstance.blank?
690
690
  Apartment::Tenant.switch!("public")
691
691
  begin
@@ -1,3 +1,3 @@
1
1
  module ZuoraConnect
2
- VERSION = "2.0.60o"
2
+ VERSION = "2.0.60t"
3
3
  end
@@ -9,7 +9,7 @@ module ZuoraConnect
9
9
  module ClassMethods
10
10
  def zuora_audit
11
11
  include ZuoraConnect::ZuoraAudit::ZuoraAuditInstanceMethods
12
- after_create :set_created_by_id
12
+ before_create :set_created_by_id
13
13
  before_update :set_updated_by_id
14
14
  end
15
15
  end
@@ -24,7 +24,7 @@ module ZuoraConnect
24
24
  end
25
25
 
26
26
  def current_user_id
27
- return ZuoraConnect::ZuoraUser.current_user
27
+ return ZuoraConnect::ZuoraUser.current_user_id
28
28
  end
29
29
  end
30
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zuora_connect
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.60o
4
+ version: 2.0.60t
5
5
  platform: ruby
6
6
  authors:
7
7
  - Connect Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-11 00:00:00.000000000 Z
11
+ date: 2020-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: apartment