zuora_connect 1.4.18 → 1.4.19

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: b75d35b09f956f5cec172619e5b99bdf662ba515
4
- data.tar.gz: 8a9772a56149ca8a0db7e8572b63e5a450c46123
3
+ metadata.gz: d2c8abab6cf7e7fd8a8d5d6e7129786f9c122b56
4
+ data.tar.gz: bb6c4243981df05e1644709372da01c6c5c29747
5
5
  SHA512:
6
- metadata.gz: 5137f8fa5e1f055b8c2169e271cc19d8032e97afe4d0cf94ed928233303aa4dd08a040569def7623c1d62d436008dda289092934a620bea8a38a86334f3f885a
7
- data.tar.gz: 163ca2467f6ea16e9457f2ed553dd0f8383dd7ada5df35efaf2737cb59e918804ff0b54478f2d74e9e52e4eb02c1bf7d0a8d492bff53957a7a008a4f91de0709
6
+ metadata.gz: faf7703043dcde6ed961e71a766efcf34b6a781cf52c5a6a2c3b46a856a32250e5450af65dcb1f355c9b4015de4166b4588eb7c9c33d00feb256ba2e0efd2c15
7
+ data.tar.gz: a6930436912bec778ff6d76ebb30d2800be21a2dc6d2db52ac76c0e0960a6675c384d61c78b9011bfef72fe4b063570d2f534c046be4d041b229ba790641e7e3
@@ -52,43 +52,140 @@ module ZuoraConnect
52
52
  return self.catalog_updated_at.blank? || (self.catalog_updated_at < time)
53
53
  end
54
54
 
55
- def catalog_lookup(entity_id: nil, object: :product, object_id: nil)
55
+ # Catalog lookup provides method to lookup zuora catalog efficiently.
56
+ # entity_id: If the using catalog json be field to store multiple entity product catalogs.
57
+ # object: The Object class desired to be returned. Available [:product, :rateplan, :charge]
58
+ # object_id: The id or id's of the object/objects to be returned.
59
+ # child_objects: Whether to include child objects of the object in question.
60
+ # cache: Store individual "1" object lookup in redis for caching.
61
+ def catalog_lookup(entity_id: nil, object: :product, object_id: nil, child_objects: false, cache: false)
56
62
  entity_reference = entity_id.blank? ? 'Default' : entity_id
57
63
 
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}"))
64
+ if object_id.present? && ![Array, String].include?(object_id.class)
65
+ raise "Object Id can only be a string or an array of strings"
66
+ end
67
+
68
+ if defined?(Redis.current) && object_id.present? && object_id.class == String
69
+ stub_catalog = decrypt_data(Redis.current.get("Catalog:#{self.id}:#{object_id}:Children:#{child_objects}"))
70
+ object_hierarchy = decrypt_data(Redis.current.get("Catalog:#{self.id}:#{object_id}:Hierarchy"))
61
71
  end
62
72
 
63
73
  if defined?(object_hierarchy)
64
74
  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
75
  end
67
76
 
68
77
  case object
69
78
  when :product
70
79
  if object_id.blank?
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"] || "{}")
80
+ string =
81
+ "SELECT "\
82
+ "json_object_agg(product_id, product #{child_objects ? '' : '- \'productRatePlans\''}) AS item "\
83
+ "FROM "\
84
+ "\"public\".\"zuora_connect_app_instances\", "\
85
+ "jsonb_each((\"public\".\"zuora_connect_app_instances\".\"catalog\" #> '{%s}' )) AS e(product_id, product) "\
86
+ "WHERE "\
87
+ "\"id\" = %s" % [entity_reference, self.id]
72
88
  else
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)
89
+ if object_id.class == String
90
+ string =
91
+ "SELECT "\
92
+ "(catalog #> '{%s, %s}') #{child_objects ? '' : '- \'productRatePlans\''} AS item "\
93
+ "FROM "\
94
+ "\"public\".\"zuora_connect_app_instances\" "\
95
+ "WHERE "\
96
+ "\"id\" = %s" % [entity_reference, object_id, self.id]
97
+ elsif object_id.class == Array
98
+ string =
99
+ "SELECT "\
100
+ "json_object_agg(product_id, product #{child_objects ? '' : '- \'productRatePlans\''}) AS item "\
101
+ "FROM "\
102
+ "\"public\".\"zuora_connect_app_instances\", "\
103
+ "jsonb_each((\"public\".\"zuora_connect_app_instances\".\"catalog\" #> '{%s}' )) AS e(product_id, product) "\
104
+ "WHERE "\
105
+ "\"product_id\" IN (\'%s\') AND "\
106
+ "\"id\" = %s" % [entity_reference, object_id.join("\',\'"), self.id]
107
+ end
75
108
  end
76
109
 
77
110
  when :rateplan
78
111
  if object_id.blank?
79
- 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"] || "{}")
112
+ string =
113
+ "SELECT "\
114
+ "json_object_agg(rateplan_id, rateplan #{child_objects ? '' : '- \'productRatePlanCharges\''}) AS item "\
115
+ "FROM "\
116
+ "\"public\".\"zuora_connect_app_instances\", "\
117
+ "jsonb_each((\"public\".\"zuora_connect_app_instances\".\"catalog\" #> '{%s}' )) AS e(product_id, product), "\
118
+ "jsonb_each(product #> '{productRatePlans}') AS ee(rateplan_id, rateplan) "\
119
+ "WHERE "\
120
+ "\"id\" = %s" % [entity_reference, self.id]
80
121
  else
81
- 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"] || "{}")
82
- Redis.current.set("Catalog:#{self.id}:#{object_id}", encrypt_data(stub_catalog)) if defined?(Redis.current)
122
+ if object_id.class == String
123
+ string =
124
+ "SELECT "\
125
+ "(catalog #> '{%s, %s, productRatePlans, %s}') #{child_objects ? '' : '- \'productRatePlanCharges\''} AS item "\
126
+ "FROM "\
127
+ "\"public\".\"zuora_connect_app_instances\" "\
128
+ "WHERE "\
129
+ "\"id\" = %s" % [entity_reference, object_hierarchy['productId'], object_id, self.id]
130
+ elsif object_id.class == Array
131
+ string =
132
+ "SELECT "\
133
+ "json_object_agg(rateplan_id, rateplan #{child_objects ? '' : '- \'productRatePlanCharges\''}) AS item "\
134
+ "FROM "\
135
+ "\"public\".\"zuora_connect_app_instances\", "\
136
+ "jsonb_each((\"public\".\"zuora_connect_app_instances\".\"catalog\" #> '{%s}' )) AS e(product_id, product), "\
137
+ "jsonb_each(product #> '{productRatePlans}') AS ee(rateplan_id, rateplan) "\
138
+ "WHERE "\
139
+ "\"rateplan_id\" IN (\'%s\') AND "\
140
+ "\"id\" = %s" % [entity_reference, object_id.join("\',\'"), self.id]
141
+ end
83
142
  end
84
143
 
85
144
  when :charge
86
145
  if object_id.blank?
87
- 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"] || "{}")
146
+ string =
147
+ "SELECT "\
148
+ "json_object_agg(charge_id, charge) as item "\
149
+ "FROM "\
150
+ "\"public\".\"zuora_connect_app_instances\", "\
151
+ "jsonb_each((\"public\".\"zuora_connect_app_instances\".\"catalog\" #> '{%s}' )) AS e(product_id, product), "\
152
+ "jsonb_each(product #> '{productRatePlans}') AS ee(rateplan_id, rateplan), "\
153
+ "jsonb_each(rateplan #> '{productRatePlanCharges}') AS eee(charge_id, charge) "\
154
+ "WHERE "\
155
+ "\"id\" = %s" % [entity_reference, self.id]
88
156
  else
89
- 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"] || "{}")
90
- Redis.current.set("Catalog:#{self.id}:#{object_id}", encrypt_data(stub_catalog)) if defined?(Redis.current)
157
+ if object_id.class == String
158
+ string =
159
+ "SELECT "\
160
+ "catalog #> '{%s, %s, productRatePlans, %s, productRatePlanCharges, %s}' AS item "\
161
+ "FROM "\
162
+ "\"public\".\"zuora_connect_app_instances\" "\
163
+ "WHERE "\
164
+ "\"id\" = %s" % [entity_reference, object_hierarchy['productId'], object_hierarchy['productRatePlanId'], object_id, self.id]
165
+
166
+ elsif object_id.class == Array
167
+ string =
168
+ "SELECT "\
169
+ "json_object_agg(charge_id, charge) AS item "\
170
+ "FROM "\
171
+ "\"public\".\"zuora_connect_app_instances\", "\
172
+ "jsonb_each((\"public\".\"zuora_connect_app_instances\".\"catalog\" #> '{%s}' )) AS e(product_id, product), "\
173
+ "jsonb_each(product #> '{productRatePlans}') AS ee(rateplan_id, rateplan), "\
174
+ "jsonb_each(rateplan #> '{productRatePlanCharges}') AS eee(charge_id, charge) "\
175
+ "WHERE "\
176
+ "\"charge_id\" IN (\'%s\') AND "\
177
+ "\"id\" = %s" % [entity_reference, object_id.join("\',\'"), self.id]
178
+ end
91
179
  end
180
+ else
181
+ raise "Available objects include [:product, :rateplan, :charge]"
182
+ end
183
+
184
+ stub_catalog ||= JSON.parse(ActiveRecord::Base.connection.execute(string).first["item"] || "{}")
185
+
186
+ if defined?(Redis.current) && object_id.present? && object_id.class == String
187
+ Redis.current.set("Catalog:#{self.id}:#{object_id}:Hierarchy", encrypt_data(object_hierarchy))
188
+ Redis.current.set("Catalog:#{self.id}:#{object_id}:Children:#{child_objects}", encrypt_data(stub_catalog)) if cache
92
189
  end
93
190
 
94
191
  return stub_catalog
@@ -1,3 +1,3 @@
1
1
  module ZuoraConnect
2
- VERSION = "1.4.18"
2
+ VERSION = "1.4.19"
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.18
4
+ version: 1.4.19
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-20 00:00:00.000000000 Z
11
+ date: 2017-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord-session_store