Class: Forem::BadgeAchievement

Inherits:
APIResource show all
Extended by:
APIOperations::Create, APIOperations::List, APIOperations::Retrieve
Includes:
APIOperations::Delete
Defined in:
lib/forem/resources/badge_achievement.rb

Overview

Represents a badge awarded to a specific user.

Creating a badge achievement awards a badge; deleting one revokes it. There is no update endpoint.

Available operations (via mixins):

- +List+     — GET /api/badge_achievements
- +Create+   — POST /api/badge_achievements
- +Retrieve+ — GET /api/badge_achievements/:id
- +Delete+   — class- and instance-level delete (DELETE /api/badge_achievements/:id)

BadgeAchievement Fields

  • id (Integer) — Assigned by the API; not writable
  • user_id (Integer) — The user the badge was awarded to
  • badge_id (Integer) — The badge that was awarded
  • rewarder_id (Integer) — The awarding user; not writable, so always null on achievements created through the API
  • rewarding_context_message_markdown (String) — Message shown with the award, in markdown
  • rewarding_context_message (String) — Rendered from rewarding_context_message_markdown by the API; not writable
  • include_default_description (Boolean) — Whether the badge description accompanies the message
  • metadata (ForemObject) — Arbitrary key/value data supplied for context. Defaults to {}.
  • created_at / updated_at (String) — ISO 8601 timestamps; not writable

Authentication

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

Pagination

list returns a fixed 50 records per page.

Examples:

Award a badge

achievement = client.badge_achievements.create(
  user_id: 123,
  badge_id: 45
)
puts achievement.id

Award a badge with caller-supplied metadata

client.badge_achievements.create(
  user_id: 123,
  badge_id: 45,
  metadata: { entitlement_id: "01a0…", source: "core" }
)

Revoke a badge

client.badge_achievements.delete(9876)

See Also:

Constant Summary collapse

OBJECT_NAME =
"badge_achievement"
RESOURCE_PATH =
"/api/badge_achievements"

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::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