Class: ActionNetworkRest::Events

Inherits:
Base
  • Object
show all
Defined in:
lib/action_network_rest/events.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#all, #get, #list

Constructor Details

#initialize(client:, event_campaign_id: nil, event_id: nil) ⇒ Events

Returns a new instance of Events.



7
8
9
# File 'lib/action_network_rest/events.rb', line 7

def initialize(client:, event_campaign_id: nil, event_id: nil)
  super(client: client, event_id: event_id, event_campaign_id: event_campaign_id)
end

Instance Attribute Details

#event_campaign_idObject

Returns the value of attribute event_campaign_id.



5
6
7
# File 'lib/action_network_rest/events.rb', line 5

def event_campaign_id
  @event_campaign_id
end

#event_idObject

Returns the value of attribute event_id.



5
6
7
# File 'lib/action_network_rest/events.rb', line 5

def event_id
  @event_id
end

Instance Method Details

#attendancesObject



38
39
40
41
# File 'lib/action_network_rest/events.rb', line 38

def attendances
  @_attendances ||= ActionNetworkRest::Attendances.new(client: client, event_id: event_id,
                                                       event_campaign_id: event_campaign_id)
end

#base_pathObject



11
12
13
14
15
16
17
# File 'lib/action_network_rest/events.rb', line 11

def base_path
  if event_campaign_id.present?
    "event_campaigns/#{url_escape(event_campaign_id)}/events/"
  else
    'events/'
  end
end

#create(event_data, creator_person_id: nil, organizer_person_id: nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/action_network_rest/events.rb', line 19

def create(event_data, creator_person_id: nil, organizer_person_id: nil)
  post_body = event_data

  if creator_person_id.present?
    creator_person_url = action_network_url("/people/#{url_escape(creator_person_id)}")
    post_body['_links'] ||= {}
    post_body['_links']['osdi:creator'] = { href: creator_person_url }
  end

  if organizer_person_id.present?
    organizer_person_url = action_network_url("/people/#{url_escape(organizer_person_id)}")
    post_body['_links'] ||= {}
    post_body['_links']['osdi:organizer'] = { href: organizer_person_url }
  end

  response = client.post_request(base_path, post_body)
  object_from_response(response, action_network_id_required: true)
end

#update(id, event_data) ⇒ Object



43
44
45
46
47
# File 'lib/action_network_rest/events.rb', line 43

def update(id, event_data)
  event_path = "#{base_path}#{url_escape(id)}"
  response = client.put_request event_path, event_data
  object_from_response(response)
end