Class: ActionKitApi::EventCampaign

Inherits:
ApiDataModel show all
Includes:
Searchable
Defined in:
lib/action_kit_api/event_campaign.rb

Instance Attribute Summary collapse

Attributes inherited from ApiDataModel

#created_at, #updated_at

Instance Method Summary collapse

Methods included from Searchable

included

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_privateObject

Other/Active



11
12
13
# File 'lib/action_kit_api/event_campaign.rb', line 11

def allow_private
  @allow_private
end

#default_event_sizeObject

Other/Active



11
12
13
# File 'lib/action_kit_api/event_campaign.rb', line 11

def default_event_size
  @default_event_size
end

#default_titleObject

Other/Active



11
12
13
# File 'lib/action_kit_api/event_campaign.rb', line 11

def default_title
  @default_title
end

#idObject

Required



8
9
10
# File 'lib/action_kit_api/event_campaign.rb', line 8

def id
  @id
end

#max_event_sizeObject

Other/Active



11
12
13
# File 'lib/action_kit_api/event_campaign.rb', line 11

def max_event_size
  @max_event_size
end

#nameObject

Required



8
9
10
# File 'lib/action_kit_api/event_campaign.rb', line 8

def name
  @name
end

#public_create_pageObject

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_pageObject

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_confirmationObject

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_approvalObject

Other/Active



11
12
13
# File 'lib/action_kit_api/event_campaign.rb', line 11

def require_staff_approval
  @require_staff_approval
end

#show_address1Object

Other/Active



11
12
13
# File 'lib/action_kit_api/event_campaign.rb', line 11

def show_address1
  @show_address1
end

#show_public_descriptionObject

Other/Active



11
12
13
# File 'lib/action_kit_api/event_campaign.rb', line 11

def show_public_description
  @show_public_description
end

#show_stateObject

Other/Active



11
12
13
# File 'lib/action_kit_api/event_campaign.rb', line 11

def show_state
  @show_state
end

#show_titleObject

Other/Active



11
12
13
# File 'lib/action_kit_api/event_campaign.rb', line 11

def show_title
  @show_title
end

#show_venueObject

Other/Active



11
12
13
# File 'lib/action_kit_api/event_campaign.rb', line 11

def show_venue
  @show_venue
end

#show_zipObject

Other/Active



11
12
13
# File 'lib/action_kit_api/event_campaign.rb', line 11

def show_zip
  @show_zip
end

#starts_atObject

Other/Active



11
12
13
# File 'lib/action_kit_api/event_campaign.rb', line 11

def starts_at
  @starts_at
end

#titleObject

Required



8
9
10
# File 'lib/action_kit_api/event_campaign.rb', line 8

def title
  @title
end

#use_start_dateObject

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_timeObject

Other/Active



11
12
13
# File 'lib/action_kit_api/event_campaign.rb', line 11

def use_start_time
  @use_start_time
end

#use_titleObject

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_saveObject

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

   = "#{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().nil?
       = ActionKitApi::EventSignupPage.new(:name => , :title => "{self.title} - Attend", :campaign_id => self.id)
      .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

#statsObject



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