zuora_connect 1.4.4 → 1.4.5

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: 1410ae4de73fd8f7f2e6fef3027fed7db4cfdefd
4
- data.tar.gz: f6e58da4ef1ef843ad3ae375cdec9efcbe035f2b
3
+ metadata.gz: b71ed8ef8cd914b208e867b6e68873beb0f5de11
4
+ data.tar.gz: 68770c0e6a652a46c21e8b0fe8c6c095505324ad
5
5
  SHA512:
6
- metadata.gz: 883f282baf0cf7e989e923b01c9f469adf5134d380cb7a28c440aa5fb8ca2de3e6229f56288c722a0a0aa535bbbd66aa8b3052d4ae1a29a62d427a369bb65740
7
- data.tar.gz: 21d6572bcc331ee83af35852ed64bd1cc3bd5ae953a5894237b58ff3cf163c32a0999d9d9706ecb60ed92f1baf4d8fae4ba68dc4d9be2ae0646107fa2d20e8e2
6
+ metadata.gz: d9211986730903e4e0e6ac0e32e7fc1555eb4459c1c96dbc2dac4ad3f8dfa37452deaedbb95fe9589412c97cf3b6c814284eeb10836f9880fd74d53c17b1f319
7
+ data.tar.gz: 28ed8d8df382e5c8398afd664b78d0dd0281419620b3e2d18221c372c7d580bdced516a2eb485c2e32e225e58aa36a0994e1f3183977f376f06873aaed7f9b6c
@@ -1,5 +1,6 @@
1
1
  module ZuoraConnect
2
2
  class AppInstanceBase < ActiveRecord::Base
3
+ default_scope {select(ZuoraConnect::AppInstance.column_names.delete_if {|x| ["catalog_mapping", "catalog"].include?(x) }) }
3
4
  after_initialize :init
4
5
  self.table_name = "zuora_connect_app_instances"
5
6
  attr_accessor :options, :mode, :logins, :valid, :task_data, :last_refresh, :username, :password, :s3_client, :api_version
@@ -47,22 +48,39 @@ module ZuoraConnect
47
48
  return self.catalog_updated_at.blank? || (self.catalog_updated_at < Time.now - 12.hours)
48
49
  end
49
50
 
50
- def catalog_lookup(entity_id: nil, object: :product, map_lower_objects: true)
51
+ def catalog_lookup(entity_id: nil, object: :product, object_id: nil, map_lower_objects: true)
51
52
  entity_reference = entity_id.blank? ? 'Default' : entity_id
52
- stub_catalog = ((self.catalog || {})[entity_reference] || {})
53
+ object_hierarchy = ZuoraConnect::AppInstance.unscoped.select("catalog_mapping -> '#{entity_reference}' as item").where(id: self.id).first.item[object_id]
54
+
53
55
  case object
54
56
  when :product
57
+ if object_id.blank?
58
+ stub_catalog = (ZuoraConnect::AppInstance.unscoped.select("catalog -> '#{entity_reference}' as item").where(id: self.id).first.item || {})
59
+ else
60
+ stub_catalog = (ZuoraConnect::AppInstance.unscoped.select("catalog #> '{#{entity_reference}, #{object_id}}' as item").where(id: self.id).first.item || {})
61
+ end
62
+
55
63
  if !map_lower_objects
56
64
  stub_catalog = stub_catalog.map{|k,v| [k,v.except("productRatePlans").merge({"productRatePlans" => v["productRatePlans"].map {|k,v| v.except("productRatePlanCharges").merge({"productRatePlanCharges" => v["productRatePlanCharges"].map {|k,v| v}})}})]}.to_h
57
65
  end
58
66
  when :rateplan
59
- stub_catalog = stub_catalog.map {|k,x| x["productRatePlans"] }.reduce({}, :merge)
67
+ if object_id.blank?
68
+ stub_catalog = (ActiveRecord::Base.connection.execute("SELECT \"value\" #>'{productRatePlans}' as \"rateplan\" from \"public\".\"zuora_connect_app_instances\", json_each((\"public\".\"zuora_connect_app_instances\".\"catalog\"::json -> '#{entity_reference}')) AS e(key, value) WHERE \"id\" = #{self.id}") || {}).map {|rp| JSON.parse(rp["rateplan"])}.reduce({}, :merge)
69
+ else
70
+ stub_catalog = (ZuoraConnect::AppInstance.unscoped.select("catalog #> '{#{entity_reference}, #{object_hierarchy['productId']}, productRatePlans, #{object_id}}' as item").where(id: self.id).first.item || {})
71
+ end
60
72
 
61
73
  if !map_lower_objects
62
74
  stub_catalog = stub_catalog.map {|k,v| [k,v.except("productRatePlanCharges").merge({"productRatePlanCharges" => v["productRatePlanCharges"].map {|k,v| v}})]}.to_h
63
75
  end
64
76
  when :charge
65
- stub_catalog = stub_catalog.map {|k,x| x["productRatePlans"].map{|k,x| x["productRatePlanCharges"] }.reduce({}, :merge)}.reduce({}, :merge)
77
+ if object_id.blank?
78
+ #Still Needs Fixing
79
+ stub_catalog = (ActiveRecord::Base.connection.execute("SELECT \"value\" #>'{productRatePlans}' as \"rateplan\" from \"public\".\"zuora_connect_app_instances\", json_each((\"public\".\"zuora_connect_app_instances\".\"catalog\"::json -> '#{entity_reference}')) AS e(key, value) WHERE \"id\" = #{self.id}") || {}).map {|rp| JSON.parse(rp["rateplan"])}.reduce({}, :merge)
80
+ stub_catalog = stub_catalog.map{|k,x| x["productRatePlanCharges"] }.reduce({}, :merge)
81
+ else
82
+ stub_catalog = (ZuoraConnect::AppInstance.unscoped.select("catalog #> '{#{entity_reference}, #{object_hierarchy['productId']}, productRatePlans, #{object_hierarchy['productRatePlanId']}, productRatePlanCharges, #{object_id}}' as item").where(id: self.id).first.item || {})
83
+ end
66
84
  end
67
85
 
68
86
  return stub_catalog
@@ -80,6 +98,7 @@ module ZuoraConnect
80
98
  return results
81
99
  end
82
100
 
101
+
83
102
  def get_catalog(zuora_login: self.login_lookup.first, force_update: false, entity_id: nil)
84
103
  entity_reference = entity_id.blank? ? 'Default' : entity_id
85
104
  Rails.logger.debug("Fetching catalog for default") if entity_id.blank?
@@ -87,13 +106,20 @@ module ZuoraConnect
87
106
  if catalog_outdated? || force_update
88
107
  Rails.logger.debug("Fetch Catalog")
89
108
  self.update_column(:catalog_updated_at, Time.now.utc)
90
- products = zuora_login.client(entity_reference).get_catalog
91
- self.catalog = {} if self.catalog.blank? || self.catalog.class == Array
92
- self.catalog[entity_reference] = products.blank? ? {} : products
93
- self.update_column(:catalog, self.catalog)
109
+ products, catalog_mapping = zuora_login.client(entity_reference).get_catalog
110
+
111
+ # Update this entity
112
+ ActiveRecord::Base.connection.execute("UPDATE \"public\".\"zuora_connect_app_instances\" SET \"catalog\" = jsonb_set(\"catalog\", '{#{entity_reference}}', '#{products.to_json}') where \"id\" = #{self.id}")
113
+
114
+ # Update this entity mapping
115
+ ActiveRecord::Base.connection.execute("UPDATE \"public\".\"zuora_connect_app_instances\" SET \"catalog_mapping\" = jsonb_set(\"catalog_mapping\", '{#{entity_reference}}', '#{catalog_mapping.to_json}') where \"id\" = #{self.id}")
116
+
94
117
  self.touch
95
118
  end
96
- return self.catalog[entity_reference]
119
+
120
+ # DO NOT RETURN CATALOG. THIS IS NOT SCALABLE WITH LARGE CATALOGS. USE THE
121
+ # return self.catalog[entity_reference]
122
+ return true
97
123
  end
98
124
 
99
125
  def new_session(session: self.data_lookup, username: self.access_token, password: self.refresh_token)
@@ -0,0 +1,5 @@
1
+ class AddCatalogMappingsToAppInstance < ActiveRecord::Migration
2
+ def change
3
+ add_column :zuora_connect_app_instances, :catalog_mapping, :jsonb, default: {} unless column_exists? :zuora_connect_app_instances, :catalog_mapping
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module ZuoraConnect
2
- VERSION = "1.4.4"
2
+ VERSION = "1.4.5"
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.4
4
+ version: 1.4.5
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-16 00:00:00.000000000 Z
11
+ date: 2017-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord-session_store
@@ -218,6 +218,7 @@ files:
218
218
  - db/migrate/20110411200303_add_expiration_to_app_instance.rb
219
219
  - db/migrate/20110413191512_add_new_api_token.rb
220
220
  - db/migrate/20110503003602_add_catalog_data_to_app_instance.rb
221
+ - db/migrate/20110503003603_add_catalog_mappings_to_app_instance.rb
221
222
  - lib/tasks/zuora_connect_tasks.rake
222
223
  - lib/zuora_connect.rb
223
224
  - lib/zuora_connect/configuration.rb