Class: Forem::Badge

Overview

Represents a badge that can be awarded to users on a Forem instance.

Badges are awards that can be given to users. Badges support full CRUD operations.

Available operations (via mixins):

- +List+     — GET /api/badges
- +Create+   — POST /api/badges
- +Retrieve+ — GET /api/badges/:id
- +Update+   — PUT /api/badges/:id
- +Delete+   — class- and instance-level delete (DELETE /api/badges/:id)
- +Save+     — instance-level save (create or update)

Badge Fields

  • id (Integer) — Assigned by the API; not writable
  • title (String) — Badge title; unique across the instance
  • slug (String) — Generated from title by the API; not writable
  • description (String) — Badge description
  • badge_image (String) — Badge image URL; set on write with remote_badge_image_url
  • credits_awarded (Integer) — Credits granted alongside the badge
  • allow_multiple_awards (Boolean) — Whether the badge can be awarded to the same user more than once
  • created_at / updated_at (String) — ISO 8601 timestamps; not writable

Authentication

All badge endpoints require an admin API key, reads included.

Pagination

list returns a fixed 50 records per page.

Examples:

List every badge

page = 1
loop do
  badges = client.badges.list(page: page)
  break if badges.data.empty?
  badges.data.each { |b| puts "#{b.id}: #{b.title}" }
  page += 1
end

Retrieve a badge by ID

badge = client.badges.retrieve(45)
puts badge.title

See Also:

Constant Summary collapse

OBJECT_NAME =
"badge"
RESOURCE_PATH =
"/api/badges"

Instance Attribute Summary

Attributes inherited from ForemObject

#requestor

Method Summary

Methods included from APIOperations::Create

create

Methods included from APIOperations::List

list

Methods included from APIOperations::Retrieve

retrieve

Methods included from APIOperations::Update

update

Methods included from APIOperations::Save

#save

Methods included from APIOperations::Delete

#delete, included

Methods inherited from APIResource

#refresh, resource_path, #resource_url

Methods inherited from ForemObject

#==, #[], #[]=, construct_from, cursor_list, #initialize, #inspect, #method_missing, paginated_list, #respond_to_missing?, #to_hash

Methods included from APIOperations::Request

included, #request

Constructor Details

This class inherits a constructor from Forem::ForemObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Forem::ForemObject