Method: Osm::Event#update

Defined in:
lib/osm/event.rb

#update(api) ⇒ Boolean

Update event in OSM

Parameters:

  • api (Osm::Api)

    The api to use to make the request

Returns:

  • (Boolean)

    whether the update succedded



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/osm/event.rb', line 190

def update(api)
  require_ability_to(api, :write, :events, section_id)

  to_update = changed_attributes

  data = api.perform_query("events.php?action=addEvent&sectionid=#{section_id}", {
    'eventid' => id,
    'name' => name,
    'location' => location,
    'startdate' => start? ? start.strftime(Osm::OSM_DATE_FORMAT) : '',
    'enddate' => finish? ? finish.strftime(Osm::OSM_DATE_FORMAT) : '',
    'cost' => cost_tbc? ? '-1' : cost,
    'notes' => notes,
    'starttime' => start? ? start.strftime(Osm::OSM_TIME_FORMAT) : '',
    'endtime' => finish? ? finish.strftime(Osm::OSM_TIME_FORMAT) : '',
    'confdate' => confirm_by_date? ? confirm_by_date.strftime(Osm::OSM_DATE_FORMAT) : '',
    'allowChanges' => allow_changes ? 'true' : 'false',
    'disablereminders' => !reminders ? 'true' : 'false',
    'attendancelimit' => attendance_limit,
    'attendancereminder' => attendance_reminder,
    'limitincludesleaders' => attendance_limit_includes_leaders ? 'true' : 'false',
    'allowbooking' => allow_booking ? 'true' : 'false',
  })

  api.perform_query("events.php?action=saveNotepad&sectionid=#{section_id}", {
    'eventid' => id,
    'notepad' => notepad,
  }) if to_update.include?('notepad')

  api.perform_query("events.php?action=saveNotepad&sectionid=#{section_id}", {
    'eventid' => id,
    'pnnotepad' => public_notepad,
  }) if to_update.include?('public_notepad')

  if data.is_a?(Hash) && (data['id'].to_i == id)
    reset_changed_attributes
    # The cached event will be out of date - remove it
    cache_delete(api, ['event', id])
    return true
  else
    return false
  end
end