Class: HubriseApp::Refresher::Base

Inherits:
Object
  • Object
show all
Defined in:
app/lib/hubrise_app/refresher/base.rb

Direct Known Subclasses

Account, AppInstance, Catalog, CustomerList, Location, User

Constant Summary collapse

REFRESH_THRESHOLD =
1.day

Class Method Summary collapse

Class Method Details

.from_api_client(api_client, **args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'app/lib/hubrise_app/refresher/base.rb', line 8

def from_api_client(api_client, **args)
  hr_id = api_client.public_send(id_key)
  if hr_id
    run(
      model_factory.find_or_initialize_by(hr_id:),
      api_client,
      **args
    )
  end
end

.from_event(resource, event_params, api_client) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'app/lib/hubrise_app/refresher/base.rb', line 19

def from_event(resource, event_params, api_client)
  return if resource.nil?

  resource.update!(
    attributes_from_event(event_params, api_client).merge(
      refreshed_at: Time.now,
    )
  )
  resource
end

.run(resource, api_client, force: false) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'app/lib/hubrise_app/refresher/base.rb', line 30

def run(resource, api_client, force: false)
  return resource if !stale?(resource) && !force

  resource.update!(
    attributes_from_api_call(resource, api_client).merge(
      refreshed_at: Time.now,
    )
  )
  resource
end