Method: Osm::Activity#update

Defined in:
lib/osm/activity.rb

#update(api, section, secret_update = false) ⇒ Boolean

Update this activity in OSM

Parameters:

  • api (Osm::Api)

    The api to use to make the request

  • section (Osm::Section, Fixnum, #to_i)

    The Section (or it’s ID)

  • secret_update (Boolean) (defaults to: false)

    Whether this is a secret update

Returns:

  • (Boolean)

    Whether the activity was successfully added

Raises:



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/osm/activity.rb', line 233

def update(api, section, secret_update=false)
  raise Osm::ObjectIsInvalid, 'activity is invalid' unless valid?
  raise Osm::Forbidden, "You are not allowed to update this activity" unless self.editable

  data = api.perform_query("programme.php?action=update", {
    'title' => title,
    'description' => description,
    'resources' => resources,
    'instructions' => instructions,
    'id' => id,
    'files' => files.map{|f| f.id }.join(','),
    'time' => running_time.to_s,
    'location' => location,
    'sections' => sections.to_json,
    'tags' => tags.to_json,
    'links' => badges.map{ |b|
      {
        'badge_id' => b.badge_id.to_s,
        'badge_version' => b.badge_version.to_s,
        'column_id' => b.requirement_id.to_s,
        'badge' => nil,
        'badgeLongName' => b.badge_name,
        'columnname' => nil,
        'columnnameLongName' => b.requirement_label,
        'data' => b.data,
        'section' => b.badge_section,
        'sectionLongName' => nil,
        'sections' => sections.map{ |s| s.to_s },
        'badgetype' => b.badge_type.to_s,
        'badgetypeLongName' => nil,
      }
    }.to_json,
    'shared' => shared,
    'sectionid' => section.to_i,
    'secretEdit' => secret_update,
  })

  if (data == {'result'=>true})
    # The cached activity will be out of date - remove it
    cache_delete(api, ['activity', self.id])
    return true
  else
    return false
  end
end