Class: HubriseApp::Refresher::AppInstance

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

Constant Summary

Constants inherited from Base

Base::REFRESH_THRESHOLD

Class Method Summary collapse

Methods inherited from Base

from_api_client

Class Method Details

.default_callback_events(app_instance) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/lib/hubrise_app/refresher/app_instance.rb', line 39

def default_callback_events(app_instance)
  events = {}

  if app_instance.location
    events[:location] = [:update]
  end

  if app_instance.catalog
    events[:catalog] = [:update]
  end

  if app_instance.customer_list
    events[:customer_list] = [:update]
  end

  events
end

.from_event(resource, event_params, api_client) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/lib/hubrise_app/refresher/app_instance.rb', line 25

def from_event(resource, event_params, api_client)
  case event_params["resource_type"]
  when "account"
    HubriseApp::Refresher::Account.from_event(resource., event_params, api_client)
  when "location"
    HubriseApp::Refresher::Location.from_event(resource.location, event_params, api_client)
    HubriseApp::Refresher::Account.from_event(resource., event_params, api_client)
  when "catalog"
    HubriseApp::Refresher::Catalog.from_event(resource.catalog, event_params, api_client)
  when "customer_list"
    HubriseApp::Refresher::CustomerList.from_event(resource.customer_list, event_params, api_client)
  end
end

.run(resource, api_client, **refresher_args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/lib/hubrise_app/refresher/app_instance.rb', line 6

def run(resource, api_client, **refresher_args)
  resource.update!(
    access_token: api_client.access_token,
    account: HubriseApp::Refresher::Account.from_api_client(
      api_client, **refresher_args
    ),
    location: HubriseApp::Refresher::Location.from_api_client(
      api_client, **refresher_args
    ),
    catalog: HubriseApp::Refresher::Catalog.from_api_client(
      api_client, **refresher_args
    ),
    customer_list: HubriseApp::Refresher::CustomerList.from_api_client(
      api_client, **refresher_args
    )
  )
  resource
end