zuora_connect 1.4.13 → 1.4.14

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: e73c25e9febca6028ce9eea3567c32f5581657a9
4
- data.tar.gz: 6f1da4f69f89c488ab5dbb552dc18e2b774143d2
3
+ metadata.gz: 077a25dc2d6bcd586fb61024dc7b4afbd59d8f88
4
+ data.tar.gz: ca164373466c60e40379266f5e5abd2dc1c38a76
5
5
  SHA512:
6
- metadata.gz: 88081b7081819c38d4017b4429938d728a0e0422cc9d745f1be1ad7c72798143c7b61e88fd59c99c43db8a09cde3468bc4aa6cefa157d0fea376d9cc37474151
7
- data.tar.gz: cdfe231a983d87f0f91baa038315cecf79e069ed53df50493800fbf2950dee5151863a2b59d1729648cf24500f202c5cb0592ceb8b31fd7c0bf70e5520186ff4
6
+ metadata.gz: dd291bd585b089603743ae549c46d63c4d49b39945458ff737312079bb19060905b63dc0b465017614697a871b26774aed0795d91a170606ce3573139c2e069e
7
+ data.tar.gz: e033ed78d360990bfd58e4aab9463c0098777206f3b1fa75229a1201ee59b29da5aa51ca9e71217d3fcc984b62ddba6475a1eabf29cdfc5ae6e4129412da7795
@@ -23,17 +23,21 @@ module ZuoraConnect
23
23
  end
24
24
 
25
25
  def cache_app_instance
26
- $redis.set("AppInstance:#{self.id}", encrypt_data(self.save_data.to_json))
27
- $redis.expire("AppInstance:#{self.id}", 60.minutes.to_i)
28
- $redis.del("Deleted:#{self.id}")
26
+ if defined?(Redis.current)
27
+ Redis.current.set("AppInstance:#{self.id}", encrypt_data(self.save_data))
28
+ Redis.current.expire("AppInstance:#{self.id}", 60.minutes.to_i)
29
+ Redis.current.del("Deleted:#{self.id}")
30
+ end
29
31
  end
30
32
 
31
33
  def decrypt_data(data)
34
+ return data if data.blank?
32
35
  return Rails.env == 'development' ? JSON.parse(data) : JSON.parse(encryptor.decrypt_and_verify(CGI::unescape(data)))
33
36
  end
34
37
 
35
38
  def encrypt_data(data)
36
- return Rails.env == 'development' ? data : encryptor.encrypt_and_sign(data)
39
+ return data if data.blank?
40
+ return Rails.env == 'development' ? data.to_json : encryptor.encrypt_and_sign(data.to_json)
37
41
  end
38
42
 
39
43
  def encryptor
@@ -50,14 +54,24 @@ module ZuoraConnect
50
54
 
51
55
  def catalog_lookup(entity_id: nil, object: :product, object_id: nil, map_lower_objects: true)
52
56
  entity_reference = entity_id.blank? ? 'Default' : entity_id
53
- object_hierarchy = (JSON.parse(ActiveRecord::Base.connection.execute('SELECT catalog_mapping #> \'{%s}\' AS item FROM "public"."zuora_connect_app_instances" WHERE "id" = %s LIMIT 1' % [entity_reference, self.id]).first["item"] || "{}") [object_id] || {"productId" => "SAFTEY", "productRatePlanId" => "SAFTEY", "productRatePlanChargeId" => "SAFTEY"})
57
+
58
+ if defined?(Redis.current) && !object_id.blank?
59
+ stub_catalog = decrypt_data(Redis.current.get("Catalog:#{self.id}:#{object_id}"))
60
+ object_hierarchy = decrypt_data(Redis.current.get("Catalog:#{self.id}:Hierarchy:#{object_id}"))
61
+ end
62
+
63
+ if defined?(object_hierarchy)
64
+ object_hierarchy ||= (JSON.parse(ActiveRecord::Base.connection.execute('SELECT catalog_mapping #> \'{%s}\' AS item FROM "public"."zuora_connect_app_instances" WHERE "id" = %s LIMIT 1' % [entity_reference, self.id]).first["item"] || "{}") [object_id] || {"productId" => "SAFTEY", "productRatePlanId" => "SAFTEY", "productRatePlanChargeId" => "SAFTEY"})
65
+ Redis.current.set("Catalog:#{self.id}:Hierarchy:#{object_id}", encrypt_data(object_hierarchy)) if defined?(Redis.current)
66
+ end
54
67
 
55
68
  case object
56
69
  when :product
57
70
  if object_id.blank?
58
- stub_catalog = JSON.parse(ActiveRecord::Base.connection.execute('SELECT catalog #> \'{%s}\' AS item FROM "public"."zuora_connect_app_instances" WHERE "id" = %s' % [entity_reference, self.id]).first["item"] || "{}")
71
+ stub_catalog ||= JSON.parse(ActiveRecord::Base.connection.execute('SELECT catalog #> \'{%s}\' AS item FROM "public"."zuora_connect_app_instances" WHERE "id" = %s' % [entity_reference, self.id]).first["item"] || "{}")
59
72
  else
60
- stub_catalog = JSON.parse(ActiveRecord::Base.connection.execute('SELECT catalog #> \'{%s, %s}\' AS item FROM "public"."zuora_connect_app_instances" WHERE "id" = %s' % [entity_reference, object_id, self.id]).first["item"] || "{}")
73
+ stub_catalog ||= JSON.parse(ActiveRecord::Base.connection.execute('SELECT catalog #> \'{%s, %s}\' AS item FROM "public"."zuora_connect_app_instances" WHERE "id" = %s' % [entity_reference, object_id, self.id]).first["item"] || "{}")
74
+ Redis.current.set("Catalog:#{self.id}:#{object_id}", encrypt_data(stub_catalog)) if defined?(Redis.current)
61
75
  end
62
76
 
63
77
  if !map_lower_objects
@@ -65,9 +79,10 @@ module ZuoraConnect
65
79
  end
66
80
  when :rateplan
67
81
  if object_id.blank?
68
- stub_catalog = JSON.parse(ActiveRecord::Base.connection.execute('SELECT json_object_agg(rateplan_id, rateplan) AS item FROM "public"."zuora_connect_app_instances", jsonb_each(("public"."zuora_connect_app_instances"."catalog" #> \'{%s}\' )) AS e(product_id, product), jsonb_each(product #> \'{productRatePlans}\') AS ee(rateplan_id, rateplan) WHERE "id" = %s' % [entity_reference, self.id]).first["item"] || "{}")
82
+ stub_catalog ||= JSON.parse(ActiveRecord::Base.connection.execute('SELECT json_object_agg(rateplan_id, rateplan) AS item FROM "public"."zuora_connect_app_instances", jsonb_each(("public"."zuora_connect_app_instances"."catalog" #> \'{%s}\' )) AS e(product_id, product), jsonb_each(product #> \'{productRatePlans}\') AS ee(rateplan_id, rateplan) WHERE "id" = %s' % [entity_reference, self.id]).first["item"] || "{}")
69
83
  else
70
- stub_catalog = JSON.parse(ActiveRecord::Base.connection.execute('SELECT catalog #> \'{%s, %s, productRatePlans, %s}\' AS item FROM "public"."zuora_connect_app_instances" WHERE "id" = %s' % [entity_reference, object_hierarchy['productId'], object_id, self.id]).first["item"] || "{}")
84
+ stub_catalog ||= JSON.parse(ActiveRecord::Base.connection.execute('SELECT catalog #> \'{%s, %s, productRatePlans, %s}\' AS item FROM "public"."zuora_connect_app_instances" WHERE "id" = %s' % [entity_reference, object_hierarchy['productId'], object_id, self.id]).first["item"] || "{}")
85
+ Redis.current.set("Catalog:#{self.id}:#{object_id}", encrypt_data(stub_catalog)) if defined?(Redis.current)
71
86
  end
72
87
 
73
88
  if !map_lower_objects
@@ -75,9 +90,10 @@ module ZuoraConnect
75
90
  end
76
91
  when :charge
77
92
  if object_id.blank?
78
- stub_catalog = JSON.parse(ActiveRecord::Base.connection.execute('SELECT json_object_agg(charge_id, charge) as item FROM "public"."zuora_connect_app_instances", jsonb_each(("public"."zuora_connect_app_instances"."catalog" #> \'{%s}\' )) AS e(product_id, product), jsonb_each(product #> \'{productRatePlans}\') AS ee(rateplan_id, rateplan), jsonb_each(rateplan #> \'{productRatePlanCharges}\') AS eee(charge_id, charge) WHERE "id" = %s' % [entity_reference, self.id]).first["item"] || "{}")
93
+ stub_catalog ||= JSON.parse(ActiveRecord::Base.connection.execute('SELECT json_object_agg(charge_id, charge) as item FROM "public"."zuora_connect_app_instances", jsonb_each(("public"."zuora_connect_app_instances"."catalog" #> \'{%s}\' )) AS e(product_id, product), jsonb_each(product #> \'{productRatePlans}\') AS ee(rateplan_id, rateplan), jsonb_each(rateplan #> \'{productRatePlanCharges}\') AS eee(charge_id, charge) WHERE "id" = %s' % [entity_reference, self.id]).first["item"] || "{}")
79
94
  else
80
- stub_catalog = JSON.parse(ActiveRecord::Base.connection.execute('SELECT catalog #> \'{%s, %s, productRatePlans, %s, productRatePlanCharges, %s}\' AS item FROM "public"."zuora_connect_app_instances" WHERE "id" = %s' % [entity_reference, object_hierarchy['productId'], object_hierarchy['productRatePlanId'], object_id, self.id]).first["item"] || "{}")
95
+ stub_catalog ||= JSON.parse(ActiveRecord::Base.connection.execute('SELECT catalog #> \'{%s, %s, productRatePlans, %s, productRatePlanCharges, %s}\' AS item FROM "public"."zuora_connect_app_instances" WHERE "id" = %s' % [entity_reference, object_hierarchy['productId'], object_hierarchy['productRatePlanId'], object_id, self.id]).first["item"] || "{}")
96
+ Redis.current.set("Catalog:#{self.id}:#{object_id}", encrypt_data(stub_catalog)) if defined?(Redis.current)
81
97
  end
82
98
  end
83
99
 
@@ -1,3 +1,3 @@
1
1
  module ZuoraConnect
2
- VERSION = "1.4.13"
2
+ VERSION = "1.4.14"
3
3
  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: 1.4.13
4
+ version: 1.4.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Connect Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-19 00:00:00.000000000 Z
11
+ date: 2017-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord-session_store