Class: ServiceFlows::Eventbrite::Events
Constant Summary
collapse
- @@base_uri =
'https://www.eventbriteapi.com/v3'
Instance Attribute Summary
Attributes inherited from ServiceFlow
#flow, #service
Instance Method Summary
collapse
Methods inherited from ServiceFlow
#initialize, #load_data
Constructor Details
This class inherits a constructor from ServiceFlow
Instance Method Details
#copy_data(opts) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'app/lib/service_flows/eventbrite/events.rb', line 21
def copy_data(opts)
return nil if opts.nil?
ids = opts[:ids]
service_flow_data = ServiceFlowData.find_by(service: @service, flow: @flow)
return nil if service_flow_data.nil?
activities = service_flow_data.data.values.flatten
.select { |event| ids.include? event[:id] }
.collect { |event| event_to_activity(event) }
Activity.upsert_all(activities, returning: %w[service_id id], unique_by: %i[service_id id])
end
|
#fetch_data ⇒ Object
10
11
12
13
14
15
16
17
18
19
|
# File 'app/lib/service_flows/eventbrite/events.rb', line 10
def fetch_data(*)
response = Http.json.get("#{@@base_uri}/users/me/organizations/", { token: @service.token })
return nil if response.status != 200
data = response.body['organizations']
.reduce({}) { |organizations, organization| fetch_events(organizations, organization) }
service_flow_data = { service_id: @service.id, flow: @flow, data: data }
ServiceFlowData.upsert(service_flow_data, returning: %w[data], unique_by: :unique_service_flow_data_index)
end
|