Class: Avo::Licensing::HQ
- Inherits:
-
Object
- Object
- Avo::Licensing::HQ
- Defined in:
- lib/avo/licensing/h_q.rb
Defined Under Namespace
Classes: RESPONSE_STRUCT
Constant Summary collapse
- ENDPOINT =
"https://v3.avohq.io/api/v3/licenses/check".freeze
- REQUEST_TIMEOUT =
seconds
5- CACHE_TIME =
seconds
6.hours.to_i
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.
- #payload ⇒ Object
- #response ⇒ Object
Constructor Details
#initialize(current_request = nil) ⇒ HQ
Returns a new instance of HQ.
31 32 33 34 |
# File 'lib/avo/licensing/h_q.rb', line 31 def initialize(current_request = nil) @current_request = current_request @cache_store = Avo.cache_store end |
Instance Attribute Details
#cache_store ⇒ Object
Returns the value of attribute cache_store.
5 6 7 |
# File 'lib/avo/licensing/h_q.rb', line 5 def cache_store @cache_store end |
#current_request ⇒ Object
Returns the value of attribute current_request.
4 5 6 |
# File 'lib/avo/licensing/h_q.rb', line 4 def current_request @current_request end |
Class Method Details
Instance Method Details
#cached_response ⇒ Object
98 99 100 |
# File 'lib/avo/licensing/h_q.rb', line 98 def cached_response cache_store.read self.class.cache_key end |
#clear_response ⇒ Object
66 67 68 |
# File 'lib/avo/licensing/h_q.rb', line 66 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
51 52 53 54 55 56 57 58 |
# File 'lib/avo/licensing/h_q.rb', line 51 def expire_cache_if_overdue return unless cached_response.present? || cached_response&.fetch(:fetched_at, nil).present? parsed_time = Time.parse(cached_response["fetched_at"].to_s) cache_should_expire = parsed_time < Time.now - CACHE_TIME clear_response if cache_should_expire end |
#fresh_response ⇒ Object
60 61 62 63 64 |
# File 'lib/avo/licensing/h_q.rb', line 60 def fresh_response clear_response make_request end |
#payload ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/avo/licensing/h_q.rb', line 70 def payload result = { license: Avo.configuration.license, license_key: Avo.configuration.license_key, avo_version: Avo::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 } begin = Avo::Services::DebugService. rescue => error = { error_message: error., error: "Failed to generate the Avo metadata" } end result[:avo_metadata] = result end |
#response ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/avo/licensing/h_q.rb', line 36 def response expire_cache_if_overdue # ------------------------------------------------------------------ # You could set this to true to become a pro user for free. # I'd rather you didn't. Avo takes time & love to build, # and I can't do that if it doesn't pay my bills! # # If you want Pro, help pay for its development. # Can't afford it? Get in touch: [email protected] # ------------------------------------------------------------------ make_request end |