Class: Serel::Badge

Inherits:
Base
  • Object
show all
Defined in:
lib/serel/badge.rb

Overview

The Badge class represents a Stack Exchange badge object.

Finding Badges

Badges can be retrieved using any of the standard finder methods: all, get & find.

all

Serel::Badge.all

Unlike several of the other classes (Answer, Comment, Question etc) where the usage of all is recommended against, all is probably the most useful finder method for retrieving badges, since a partial set of badges is probably not useful, and only a few pages have to be retrieved each time this is called. At the time of writing this, Stack Overflow required 17 pages to be retrieved, Server Fault required 2, and Gaming required 1, and shouldn’t make too much of a dent in your quota.

find

Serel::Badge.find(id)

Retrieves a badge or badges by ID.

get

Serel::Badge.get

Retrieves a page of badge results, applying any scopes that have previously been defined.

Badge.named

Serel::Badge.named.get

See the documentation for Badge.named below.

Badge.recipients

Serel::Badge.recipients.get
Serel::Badge.recipients(1).get
Serel::Badge.recipients(1,2,3).get

See the documentation for Badge.recipients below.

Badge.tags

Serel::Badge.tags.get

See the documentation for Badge.tags below.

Class Method Summary collapse

Methods inherited from Base

#[], #[]=, #all, associations, attribute, config, #find, finder_methods, #get, #initialize, #inspect, #meth, method_missing, #network, network_wide, new_relation, request, respond_to?, #type, with_ids

Constructor Details

This class inherits a constructor from Serel::Base

Class Method Details

.namedSerel::Relation

Retrieves only badges that are explicitly defined. This is a scoping method, meaning that it can be used around/with other scoping methods, for example:

Serel::Badge.pagesize(5).named.get
Serel::Badge.named.sort('gold').get

Returns:



64
65
66
# File 'lib/serel/badge.rb', line 64

def self.named
  url("badges/name")
end

.recipients(*ids) ⇒ Serel::Relation

Retrieves recently awarded badges.

Serel::Badge.recipients.get
Serel::Badge.recipients(1).get
Serel::Badge.recipients(1,2,3).get

This is a scoping method and can be combined with other scoping methods.

Parameters:

  • ids (Array)

    The ID or IDs of the badges you want information on. Not passing an ID means all recently awarded badges will be returned.

Returns:



78
79
80
81
82
83
84
85
# File 'lib/serel/badge.rb', line 78

def self.recipients(*ids)
  if ids.length > 0
    arg = ids.length > 1 ? ids.join(';') : ids.pop
    url("badges/#{arg}/recipients")
  else
    url("badges/recipients")
  end
end

.tagsSerel::Relation

Retrieves only badges that have been awarded due to participation in a tag.

Serel::Badge.tags.get

This is a scoping method and can be combined with other scoping methods.

Returns:



92
93
94
# File 'lib/serel/badge.rb', line 92

def self.tags
  url("badges/tags")
end