Class: ActionKitApi::EventCampaign
- Inherits:
-
ApiDataModel
- Object
- ApiDataModel
- ActionKitApi::EventCampaign
- Includes:
- Searchable
- Defined in:
- lib/action_kit_api/event_campaign.rb
Instance Attribute Summary collapse
-
#allow_private ⇒ Object
Other/Active.
-
#default_event_size ⇒ Object
Other/Active.
-
#default_title ⇒ Object
Other/Active.
-
#id ⇒ Object
Required.
-
#max_event_size ⇒ Object
Other/Active.
-
#name ⇒ Object
Required.
-
#public_create_page ⇒ Object
Other/Active.
-
#public_search_page ⇒ Object
Other/Active.
-
#require_email_confirmation ⇒ Object
Other/Active.
-
#require_staff_approval ⇒ Object
Other/Active.
-
#show_address1 ⇒ Object
Other/Active.
-
#show_public_description ⇒ Object
Other/Active.
-
#show_state ⇒ Object
Other/Active.
-
#show_title ⇒ Object
Other/Active.
-
#show_venue ⇒ Object
Other/Active.
-
#show_zip ⇒ Object
Other/Active.
-
#starts_at ⇒ Object
Other/Active.
-
#title ⇒ Object
Required.
-
#use_start_date ⇒ Object
Other/Active.
-
#use_start_time ⇒ Object
Other/Active.
-
#use_title ⇒ Object
Other/Active.
Attributes inherited from ApiDataModel
Instance Method Summary collapse
-
#after_save ⇒ Object
After creating a new event campaign we need to create the associated signup and hosting pages.
- #create_event(*args) ⇒ Object
-
#find_local_events(zip, radius) ⇒ Object
Uses public_search so is subject those limitations.
-
#initialize(*args) ⇒ EventCampaign
constructor
A new instance of EventCampaign.
-
#public_search(*args) ⇒ Object
Will not return private events, events that are full, deleted, or in the past and doesn’t return extra fields.
- #stats ⇒ Object
Methods included from Searchable
Methods inherited from ApiDataModel
#save, #to_hash, #update, #valid?
Constructor Details
#initialize(*args) ⇒ EventCampaign
Returns a new instance of EventCampaign.
19 20 21 22 23 24 25 26 27 |
# File 'lib/action_kit_api/event_campaign.rb', line 19 def initialize(*args) @required_attrs = [:name, :title] super @default_title ||= @title @default_event_size ||= 35 @show_address1 ||= true end |
Instance Attribute Details
#allow_private ⇒ Object
Other/Active
11 12 13 |
# File 'lib/action_kit_api/event_campaign.rb', line 11 def allow_private @allow_private end |
#default_event_size ⇒ Object
Other/Active
11 12 13 |
# File 'lib/action_kit_api/event_campaign.rb', line 11 def default_event_size @default_event_size end |
#default_title ⇒ Object
Other/Active
11 12 13 |
# File 'lib/action_kit_api/event_campaign.rb', line 11 def default_title @default_title end |
#id ⇒ Object
Required
8 9 10 |
# File 'lib/action_kit_api/event_campaign.rb', line 8 def id @id end |
#max_event_size ⇒ Object
Other/Active
11 12 13 |
# File 'lib/action_kit_api/event_campaign.rb', line 11 def max_event_size @max_event_size end |
#name ⇒ Object
Required
8 9 10 |
# File 'lib/action_kit_api/event_campaign.rb', line 8 def name @name end |
#public_create_page ⇒ Object
Other/Active
11 12 13 |
# File 'lib/action_kit_api/event_campaign.rb', line 11 def public_create_page @public_create_page end |
#public_search_page ⇒ Object
Other/Active
11 12 13 |
# File 'lib/action_kit_api/event_campaign.rb', line 11 def public_search_page @public_search_page end |
#require_email_confirmation ⇒ Object
Other/Active
11 12 13 |
# File 'lib/action_kit_api/event_campaign.rb', line 11 def require_email_confirmation @require_email_confirmation end |
#require_staff_approval ⇒ Object
Other/Active
11 12 13 |
# File 'lib/action_kit_api/event_campaign.rb', line 11 def require_staff_approval @require_staff_approval end |
#show_address1 ⇒ Object
Other/Active
11 12 13 |
# File 'lib/action_kit_api/event_campaign.rb', line 11 def show_address1 @show_address1 end |
#show_public_description ⇒ Object
Other/Active
11 12 13 |
# File 'lib/action_kit_api/event_campaign.rb', line 11 def show_public_description @show_public_description end |
#show_state ⇒ Object
Other/Active
11 12 13 |
# File 'lib/action_kit_api/event_campaign.rb', line 11 def show_state @show_state end |
#show_title ⇒ Object
Other/Active
11 12 13 |
# File 'lib/action_kit_api/event_campaign.rb', line 11 def show_title @show_title end |
#show_venue ⇒ Object
Other/Active
11 12 13 |
# File 'lib/action_kit_api/event_campaign.rb', line 11 def show_venue @show_venue end |
#show_zip ⇒ Object
Other/Active
11 12 13 |
# File 'lib/action_kit_api/event_campaign.rb', line 11 def show_zip @show_zip end |
#starts_at ⇒ Object
Other/Active
11 12 13 |
# File 'lib/action_kit_api/event_campaign.rb', line 11 def starts_at @starts_at end |
#title ⇒ Object
Required
8 9 10 |
# File 'lib/action_kit_api/event_campaign.rb', line 8 def title @title end |
#use_start_date ⇒ Object
Other/Active
11 12 13 |
# File 'lib/action_kit_api/event_campaign.rb', line 11 def use_start_date @use_start_date end |
#use_start_time ⇒ Object
Other/Active
11 12 13 |
# File 'lib/action_kit_api/event_campaign.rb', line 11 def use_start_time @use_start_time end |
#use_title ⇒ Object
Other/Active
11 12 13 |
# File 'lib/action_kit_api/event_campaign.rb', line 11 def use_title @use_title end |
Instance Method Details
#after_save ⇒ Object
After creating a new event campaign we need to create the associated signup and hosting pages. These will follow the ActionKit convention to prevent them from getting wise. This is so we don’t have to use that sketchy part of their API
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/action_kit_api/event_campaign.rb', line 33 def after_save # Only continue if we have a valid id if self.id.nil? return end signup_page_name = "#{self.name}_signup" create_page_name = "#{self.name}_create" # These two calls trigger an exception EVEN IF THEY SUCCEED, since there # won't be any events for them yet :-/ begin if ActionKitApi::Page.find_by_name(signup_page_name).nil? signup_page = ActionKitApi::EventSignupPage.new(:name => signup_page_name, :title => "{self.title} - Attend", :campaign_id => self.id) signup_page.save end rescue end begin if ActionKitApi::Page.find_by_name(create_page_name).nil? create_page = ActionKitApi::EventCreatePage.new(:name => create_page_name, :title => "{self.title} - Host", :campaign_id => self.id) create_page.save end rescue end end |
#create_event(*args) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/action_kit_api/event_campaign.rb', line 61 def create_event(*args) raise "EventCampaign needs to be saved before Event creation" if self.id.nil? (args[0]).merge(:campaign_id => self.id) event = ActionKitApi::Event.new(*args) event.save result = ActionKitApi.connection.call("EventCreate.create", {:event_id => event.id}) event end |
#find_local_events(zip, radius) ⇒ Object
Uses public_search so is subject those limitations
75 76 77 |
# File 'lib/action_kit_api/event_campaign.rb', line 75 def find_local_events(zip, radius) self.public_search(:zip => zip, :radius => radius) end |
#public_search(*args) ⇒ Object
Will not return private events, events that are full, deleted, or in the past and doesn’t return extra fields
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/action_kit_api/event_campaign.rb', line 81 def public_search(*args) args[0][:campaign] ||= self.id results = ActionKitApi.connection.call("EventCampaign.public_search", args) results.map do |r| Event.new(r) end results end |
#stats ⇒ Object
92 93 94 95 96 |
# File 'lib/action_kit_api/event_campaign.rb', line 92 def stats raise "EventCampaign needs to be saved before retrieving stats" if self.id.nil? ActionKitApi.connection.call("EventCampaign.stats", {:id => self.id}) end |