Skip to content

Commit

Permalink
Sets the new user up with an example set of agents
Browse files Browse the repository at this point in the history
- gives them a place to start from
- leverages existing code to import scenarios
  • Loading branch information
TildeWill committed Apr 2, 2016
1 parent 525f2e6 commit d9d445b
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 1 deletion.
28 changes: 28 additions & 0 deletions app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
# You should configure your model like this:
# devise :omniauthable, omniauth_providers: [:twitter]

# You should also create an action method in this controller like this:
# def twitter
# end

# More info at:
# https://github.com/plataformatec/devise#omniauth

# GET|POST /resource/auth/twitter
# def passthru
# super
# end

# GET|POST /users/auth/twitter/callback
# def failure
# super
# end

# protected

# The path used when OmniAuth fails
# def after_omniauth_failure_path_for(scope)
# super(scope)
# end
end
13 changes: 13 additions & 0 deletions app/controllers/users/registrations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Users::RegistrationsController < Devise::RegistrationsController
after_action :create_default_scenario, only: :create

private

def create_default_scenario
scenario_import = ScenarioImport.new()
scenario_import.set_user(@user)
scenario_import.file = File.open(File.join(Rails.root, "data", "default_scenario.json"), "r")
raise "Not vaild" unless scenario_import.valid?
scenario_import.import
end
end
5 changes: 4 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@
post "/users/:user_id/update_location/:secret" => "web_requests#update_location" # legacy

devise_for :users,
controllers: { omniauth_callbacks: 'omniauth_callbacks' },
controllers: {
omniauth_callbacks: 'omniauth_callbacks',
registrations: 'users/registrations'
},
sign_out_via: [:post, :delete]

if Rails.env.development?
Expand Down
122 changes: 122 additions & 0 deletions data/default_scenario.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{
"schema_version": 1,
"name": "Default Scenario",
"description": "This scenario has a few agents to get you started. Feel free to change them or delete them as you see fit!",
"source_url": false,
"guid": "ebc484c8df1c34b676e57167fbbce2c9",
"tag_fg_color": "#ffffff",
"tag_bg_color": "#5bc0de",
"exported_at": "2016-04-02T23:27:09Z",
"agents": [
{
"type": "Agents::EmailDigestAgent",
"name": "Morning Digest",
"disabled": false,
"guid": "09cc84cfdd3f37651c5fe251674cef8f",
"options": {
"subject": "Your Morning Digest",
"expected_receive_period_in_days": "30"
},
"schedule": "6am",
"propagate_immediately": false
},
{
"type": "Agents::WeatherAgent",
"name": "SF Weather Agent",
"disabled": false,
"guid": "4a8f43d4946c5de02a4cd808b6c1066b",
"options": {
"location": "94103",
"api_key": "PUT YOUR API KEY HERE",
"service": "wunderground"
},
"schedule": "10pm",
"keep_events_for": 0
},
{
"type": "Agents::TriggerAgent",
"name": "Rain Notifier",
"disabled": false,
"guid": "82cef3953daac06905d3a065df444bd1",
"options": {
"expected_receive_period_in_days": "2",
"rules": [
{
"type": "regex",
"value": "rain|storm",
"path": "conditions"
}
],
"message": "Just so you know, it looks like '{{conditions}}' tomorrow in {{location}}"
},
"keep_events_for": 0,
"propagate_immediately": false
},
{
"type": "Agents::WebsiteAgent",
"name": "XKCD Source",
"disabled": false,
"guid": "a3504e6827d008e9cc7cb682229585e4",
"options": {
"url": "http://xkcd.com",
"mode": "on_change",
"expected_update_period_in_days": 5,
"extract": {
"url": {
"css": "#comic img",
"value": "@src"
},
"title": {
"css": "#comic img",
"value": "@alt"
},
"hovertext": {
"css": "#comic img",
"value": "@title"
}
}
},
"schedule": "every_1d",
"keep_events_for": 0,
"propagate_immediately": false
},
{
"type": "Agents::EventFormattingAgent",
"name": "Comic Formatter",
"disabled": false,
"guid": "d86b069650edadfc61db9df767c8b65c",
"options": {
"instructions": {
"message": "<h2>{{title}}</h2><img src=\"{{url}}\"/> <p>{{hovertext}}</p>"
},
"matchers": [

],
"mode": "clean"
},
"keep_events_for": 2592000,
"propagate_immediately": false
}
],
"links": [
{
"source": 1,
"receiver": 2
},
{
"source": 2,
"receiver": 0
},
{
"source": 3,
"receiver": 4
},
{
"source": 4,
"receiver": 0
}
],
"control_links": [

]
}

0 comments on commit d9d445b

Please sign in to comment.