Class: Avo::Licensing::HQ
- Inherits:
-
Object
- Object
- Avo::Licensing::HQ
- Defined in:
- lib/avo/licensing/h_q.rb
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.
17 18 19 20 |
# File 'lib/avo/licensing/h_q.rb', line 17 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
78 79 80 |
# File 'lib/avo/licensing/h_q.rb', line 78 def cached_response cache_store.read self.class.cache_key end |
#clear_response ⇒ Object
52 53 54 |
# File 'lib/avo/licensing/h_q.rb', line 52 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
37 38 39 40 41 42 43 44 |
# File 'lib/avo/licensing/h_q.rb', line 37 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
46 47 48 49 50 |
# File 'lib/avo/licensing/h_q.rb', line 46 def fresh_response clear_response make_request end |
#payload ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/avo/licensing/h_q.rb', line 56 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 } # metadata = Avo::Services::DebugService.avo_metadata # if metadata[:resources_count] != 0 # result[:avo_metadata] = "metadata" # end result end |
#response ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/avo/licensing/h_q.rb', line 22 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: adrian@avohq.io # ------------------------------------------------------------------ make_request end |