Module: Unloq::Achievements

Included in:
Client
Defined in:
lib/unloq/achievements.rb

Instance Method Summary collapse

Instance Method Details

#create_achievement(verb, observation_count, author: nil, recipient: nil, author_type: nil, recipient_type: nil, points: nil, image_path: nil) ⇒ Object

Create an achievement via the Unloq API

Parameters:

  • verb (String)

    The verb for which this achievement should be unlocked

  • observation_count (Integer)

    The number of times the event must occur to unlock this achievement

  • author (Unloq::Entity) (defaults to: nil)

    An individual author, if passed this achievement will only be attainable by this author. Required if author_type is not defined.

  • recipient (Unloq::Entity) (defaults to: nil)

    An individual recipient that must be acted on to attain this achievement. Required if recipient_type is not defined.

  • author_type (String) (defaults to: nil)

    An individual author type, if passed this achievement will only be attaintable by authors of this type. Required if author is not defined.

  • recipient_type (String) (defaults to: nil)

    An individual recipient type that must be acted on to attain this achievement. Required if recipient is not defined.

  • points (Integer) (defaults to: nil)

    The number of points that will be awarded when this achievement is attained.

  • image_path (String) (defaults to: nil)

    An image path representing this achievement.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/unloq/achievements.rb', line 15

def create_achievement verb, observation_count, 
                       author: nil, recipient: nil, author_type: nil, recipient_type: nil, 
                       points: nil, image_path: nil

  author_type, author_id       = extract_entity_details(author, author_type)
  recipient_type, recipient_id = extract_entity_details(recipient, recipient_type)

  body_to_post = {
    verb: verb,
    observation_count: observation_count,
    author_id: author_id,
    author_type: author_type,
    recipient_id: recipient_id,
    recipient_type: recipient_type,
    points: points,
    image_path: image_path
  }

  post('/achievements', body_to_post)
end