Class: Jav::Licensing::HQ
- Inherits:
-
Object
- Object
- Jav::Licensing::HQ
- Defined in:
- lib/jav/licensing/h_q.rb
Constant Summary collapse
- ENDPOINT =
"https://javhq.io/api/v1/licenses/check".freeze
- REQUEST_TIMEOUT =
seconds
5- CACHE_TIME =
seconds
3600 * 12
Instance Attribute Summary collapse
-
#cache_store ⇒ Object
Returns the value of attribute cache_store.
-
#current_request ⇒ Object
Returns the value of attribute current_request.
Class Method Summary collapse
Instance Method Summary collapse
- #cached_response ⇒ Object
- #clear_response ⇒ Object
-
#expire_cache_if_overdue ⇒ Object
Some cache stores don't auto-expire their keys and payloads so we need to do it for them.
- #fresh_response ⇒ Object
-
#initialize(current_request = nil) ⇒ HQ
constructor
A new instance of HQ.
- #jav_metadata ⇒ Object
- #payload ⇒ Object
- #response ⇒ Object
Constructor Details
Instance Attribute Details
#cache_store ⇒ Object
Returns the value of attribute cache_store.
4 5 6 |
# File 'lib/jav/licensing/h_q.rb', line 4 def cache_store @cache_store end |
#current_request ⇒ Object
Returns the value of attribute current_request.
4 5 6 |
# File 'lib/jav/licensing/h_q.rb', line 4 def current_request @current_request end |
Class Method Details
Instance Method Details
#cached_response ⇒ Object
121 122 123 124 |
# File 'lib/jav/licensing/h_q.rb', line 121 def cached_response response # cache_store.read self.class.cache_key end |
#clear_response ⇒ Object
59 60 61 |
# File 'lib/jav/licensing/h_q.rb', line 59 def clear_response # cache_store.delete self.class.cache_key end |
#expire_cache_if_overdue ⇒ Object
Some cache stores don't auto-expire their keys and payloads so we need to do it for them
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/jav/licensing/h_q.rb', line 42 def expire_cache_if_overdue return unless cached_response.present? return unless cached_response["fetched_at"].present? allowed_time = 1.hour parsed_time = Time.parse(cached_response["fetched_at"].to_s) time_has_passed = parsed_time < Time.now - allowed_time clear_response if time_has_passed end |
#fresh_response ⇒ Object
53 54 55 56 57 |
# File 'lib/jav/licensing/h_q.rb', line 53 def fresh_response clear_response make_request end |
#jav_metadata ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/jav/licensing/h_q.rb', line 83 def resources = App.resources dashboards = App.dashboards field_definitions = resources.map(&:get_field_definitions) fields_count = field_definitions.map(&:count).sum fields_per_resource = format("%0.01f", fields_count / (resources.count + 0.0)) field_types = {} custom_fields_count = 0 field_definitions.each do |fields| fields.each do |field| field_types[field.type] ||= 0 field_types[field.type] += 1 custom_fields_count += 1 if field.custom? end end { resources_count: resources.count, dashboards_count: dashboards.count, fields_count: fields_count, fields_per_resource: fields_per_resource, custom_fields_count: custom_fields_count, field_types: field_types, **(:actions), **(:filters), main_menu_present: Jav.configuration..present?, profile_menu_present: Jav.configuration..present?, cache_store: Jav::App.cache_store&.class&.to_s, ** } rescue StandardError => e { error: e. } end |
#payload ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/jav/licensing/h_q.rb', line 63 def payload result = { license: Jav.configuration.license, license_key: Jav.configuration.license_key, jav_version: Jav::VERSION, rails_version: Rails::VERSION::STRING, ruby_version: RUBY_VERSION, environment: Rails.env, ip: current_request&.ip, host: current_request&.host, port: current_request&.port, app_name: app_name } = result[:jav_metadata] = if [:resources_count] != 0 result end |
#response ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/jav/licensing/h_q.rb', line 21 def response { 'id' => 'pro', 'valid' => true, 'payload' => {}, 'expiry' => 3600, 'fetched_at' => Time.zone.now, 'license' => 'pro', 'license_key' => nil } # expire_cache_if_overdue # ::Rails.cache.fetch(self.class.cache_key) do # { 'id' => 'pro', # 'valid' => true, # 'payload' => {}, # 'expiry' => 3600, # 'fetched_at' => Time.zone.now, # 'license' => 'pro', # 'license_key' => nil } # end end |