zuora_connect 2.0.60p → 2.0.60q

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: 49954ce1a10057c773fa3dbc859cccd19e756297192ee85d276cada97c085446
4
- data.tar.gz: bd0ce83a9631479cb2402383c5a53e104742d19fb83b951d24cdf5fe66b48bfb
3
+ metadata.gz: 3a9478b4c078e02402f100894a54bac2b08c1a89465e83ec55cb9f1bbe3f5dff
4
+ data.tar.gz: e0d5c40113abe3b72ef867ca59f620ce19dc1dee778a7e4e531aedae68a6812c
5
5
  SHA512:
6
- metadata.gz: d1e341cea3b729c967af29ecfaa9bd143ef656a415487654ae59870ef75e3b719d4873975aa12fe6b845b3916d8ef1de2f63faca22c42c89280058d404c8d3b7
7
- data.tar.gz: 22804e4a0db2285d91ef7c1da8fab9d67261ff13302b48db31f872c820d3b037425ece070a41aa3a119c1bfc7be039a78a6298ff99066b0a2fb3bbfeb6559a40
6
+ metadata.gz: 2c8392e166c5bad4c990c00344476adec37e7dff8176865202a8fedc47e853222197fc2837dd5ea780b96c7fbb92922bcb482206079d376c29c1fadee90a18d9
7
+ data.tar.gz: 66a9558d6ba34f591a82d1c1f5a92d8930fffde9258afc142e7dd68abbffbfbfdf830bbb2576cfe01e74bef6248ce2bc65b347c16cd08d434b69328fcc407c0b
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module ZuoraConnect
2
- VERSION = "2.0.60p"
2
+ VERSION = "2.0.60q"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zuora_connect
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.60p
4
+ version: 2.0.60q
5
5
  platform: ruby
6
6
  authors:
7
7
  - Connect Team