-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #182 from aspc/feature/import-engage-events
Implement engage_events_service.rb to pull events from Engage API
- Loading branch information
Showing
6 changed files
with
74 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# app/services/engage_events_service.rb | ||
|
||
class EngageEventsService | ||
def initialize() | ||
end | ||
|
||
def get_events() | ||
headers = { | ||
"Accept" => "application/json", | ||
"X-Engage-Api-Key" => Rails.application.credentials.engage_api[:production] | ||
} | ||
|
||
start_time = Time.now.to_i * 1000 # in milliseconds | ||
end_time = start_time + 30*24*3600*1000 # +30 days | ||
|
||
query = { | ||
"startDate" => start_time, | ||
"endDate" => end_time | ||
} | ||
|
||
response = HTTParty.get(Rails.application.credentials.engage_api[:url], :headers => headers, :query => query) | ||
|
||
engage_events = response["items"] # @events is a list of hashes, each of which is an event | ||
|
||
# save to db on the fly, then let events_controller pull from db | ||
engage_events.each do |event| | ||
# if event is marked for organisation only, then skip | ||
if event["typeName"] == "Organization Only" | ||
next | ||
end | ||
|
||
# if event already exists in database (checking with eventUrl), then skip | ||
if Event.exists?(details_url: event["eventUrl"]) | ||
next | ||
end | ||
|
||
# if an event starts 12pm PST, the controller expects an input of 12pm UTC (rather than 8pm UTC) | ||
# need to manually offset time | ||
offset = Time.now.in_time_zone("America/Los_Angeles").utc_offset | ||
start_time = Time.at(event["startDateTime"].to_i / 1000) + offset | ||
end_time = Time.at(event["endDateTime"].to_i / 1000) + offset | ||
|
||
# remove HTML tags from description | ||
description = ActionView::Base.full_sanitizer.sanitize(event["description"]) | ||
|
||
@event = Event.new( | ||
:name => event["eventName"], | ||
:location => event["locationName"].presence || "N/A", # return "N/A" if locationName is blank | ||
:description => description, | ||
:host => event["organizationName"], | ||
:details_url => event["eventUrl"], | ||
:start => start_time, | ||
:end => end_time | ||
) | ||
|
||
@event.approve! | ||
|
||
res = @event.save! | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
Be2ogp7UV42tavtmO5pmn/cVJ/5TbiSbbyzsrH9SZBE6eRxsAvTpGtKsT7mVi4IPBxkcdeiOcGM55z3wIiUE0ymNTG7MgFf0duIaiTS6yJNXNdpjIRpKNipLW2CGFLWFOZzJrRRziVfCHGeX51Mvm2mkxHOdn1sINiHg3dgNDvvQedUKxomPIRmqHNJFx9wvYnb0W7CoxzlVjpOJW8qKqIeR/n+KsXVWwE5ImLmCRQelrs5AG1Bg7+1EmQENlacaIuwdnDbnq4HlxFiXhtUzT4bbnNfKmWaTogcL7wfIx3Ubdf+5xREj1pLBv1xeWfNPziHq2Zfj7BnAx8ltbLUe/oa4XRZm6z6XD20A/22l0BdfNpFIGjx8Qi9fHuxgVgzsC/8FbhUad2m77CxlsxvaWaxWe3hbdIKOnxF8x4Xpssn5GeAzKO4jfjY59mwgc55wzwEfQ1RJpyhnc5QJyYbXTuqSood06jCeCocg9qfYYWtw7qgnpk73Zi7PYKaAn+rwwkO19cru79aKDPcfDaPc6Vhbx5WmuYQbDb10qA5ysexQvqH5vRNIM0ObfdJUfLV3/0uzvivklCEP64jxastttpY35a0fg/qwYe7Whwq5HrUpLr5zq/eqz3m/YzaHp4S8hiYSln/6VWT5vzdqaQQsGE8w6jvi4sFoQHNfrko1r9pdnv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0vcRVJA41PCjNdkhHkYcYRlfezqs9Eeld5ln8nqZeIebxIQyYOalP6Tn3ih3fU9/X2RTHUGTtqWlzbEfl82NpBervn413Vtwe3pNtfpFQFqp1PH9e+FW6NwQvR/crsOYzUtbOXiauiaecHAxcifDS/5ceQ0yc+JVNss0lmeILct4+CVHV3agu/EC0/z7RE6BN4x8sPu+NjZSW37MaAlZxVaQ38uJA8L4weN4IYLGtIxGRbQK13BiSLDV5yUkxn2rhdijAgkHMuvDpjcXt+OVVYZiWcjkxyrBksM7q39oS7Av0TTZGbAhLTETi6IEoRT8p5+LIARGiY7Vc7h/hAxRAAQnWsVvGmWdwsr2GOui7O0pPdR44bwdk5MaHPrpKaJE1jCuE6qsVJSx8nD8dzPUx5yft7jZ2/Wjbpxq8RCsmdK7aFvXVsnSk7y/KNG8E6U5hiRM4/jRWUVLyQAswQagXIgYokCK1IprmKFu7fHXq/ElSDl8+rLEtJWeigFEoIZZ8bA8i9SB2rHqEFQNTNOk4zpoHYzixbTUMbBe6XoEwOetej+aG73Ng40hFGZISbnSf7Tr8Kk3l3n+IucpL4fDKBTStfv2L0UymNHZXiBdEfhkXY7GrQHcJtRi23CMtMNvDlGpJyE/hicZE1zLPjOG4V5gnYFf6jsryAR7XLrXsXNPdHdBJkRg9AxT8BYoJrnshPatFOuat8P6BddP3/1OzalOWGd1Sx0=--FSUcmECmmRsCh4rg--61ONmcZVU8+5FGvHOouL8w== |
5 changes: 5 additions & 0 deletions
5
db/migrate/20191201230018_change_submitted_by_user_fk_column_on_users.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class ChangeSubmittedByUserFkColumnOnUsers < ActiveRecord::Migration[5.2] | ||
def change | ||
change_column_null :events, :submitted_by_user_fk, true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters