Class: Badgeville::Reward

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/badgeville/reward.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#ensure_array

Constructor Details

#initialize(json = nil) ⇒ Reward

example:

{
  "name": "A Way with Words",
  "active_start_at": null,
  "image_file_name": "9fQ2IU6-0.ftbs4fsoogp3c8fr.png",
  "data": {
    "verb": "commented",
    "threshold": 2
  },
  "created_at": "2011-08-18T22:55:03-07:00",
  "image_url": "http://s3.amazonaws.com/badgeville-production-reward-definitions/images/original.png?1313733302",
  "components": "[{\"command\":\"count\",\"comparator\":{\"$gte\":2},\"config\":{},\"where\":{\"verb\":\"commented\",\"player_id\":\"%player_id\"}}]",
  "reward_template": {
    "message": ""
  },
    "_id": "4e4dfab6c47eed727b005c38",
  "tags": null,
  "id": "4e4dfab6c47eed727b005c38",
  "active_end_at": null,
  "type": "achievement",
  "hint": "Reply to 25 Comments",
  "assignable": false,
  "allow_duplicates": false,
  "site_id": "4e4d5bf5c47eed25a0000e8f",
  "active": true,
  "message": "You won the internet!"
 }


37
38
39
40
41
42
43
44
45
46
# File 'lib/badgeville/reward.rb', line 37

def initialize(json=nil)
  if json
    reward_definition = json["definition"]
    reward_definition ? init_from(reward_definition) : init_from(json)
    if json.has_key?('user_id') # it's an earned reward for a specific user
      @earned_at = DateTime.parse(json["created_at"]).to_time
      @id = json["id"]
    end
  end
end

Instance Attribute Details

#activeObject

Returns the value of attribute active.



5
6
7
# File 'lib/badgeville/reward.rb', line 5

def active
  @active
end

#definition_idObject

Returns the value of attribute definition_id.



6
7
8
# File 'lib/badgeville/reward.rb', line 6

def definition_id
  @definition_id
end

#earned_atObject

Returns the value of attribute earned_at.



5
6
7
# File 'lib/badgeville/reward.rb', line 5

def earned_at
  @earned_at
end

#hintObject

Returns the value of attribute hint.



5
6
7
# File 'lib/badgeville/reward.rb', line 5

def hint
  @hint
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/badgeville/reward.rb', line 5

def id
  @id
end

#image_url(format = :original) ⇒ Object



48
49
50
# File 'lib/badgeville/reward.rb', line 48

def image_url(format = :original)
  @image_url.sub('original', format.to_s)
end

#messageObject

Returns the value of attribute message.



5
6
7
# File 'lib/badgeville/reward.rb', line 5

def message
  @message
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/badgeville/reward.rb', line 5

def name
  @name
end

#tagsObject

Returns the value of attribute tags.



6
7
8
# File 'lib/badgeville/reward.rb', line 6

def tags
  @tags
end

#thresholdObject

Returns the value of attribute threshold.



6
7
8
# File 'lib/badgeville/reward.rb', line 6

def threshold
  @threshold
end

#verbObject

Returns the value of attribute verb.



6
7
8
# File 'lib/badgeville/reward.rb', line 6

def verb
  @verb
end

Instance Method Details

#grayscale_urlObject

DEPRECATED: Please use image_url('grayscale') instead.



53
54
55
56
# File 'lib/badgeville/reward.rb', line 53

def grayscale_url
  warn "[DEPRECATION] `grayscale_url` is deprecated.  Please use `image_url(:grayscale)` instead."
  image_url(:grayscale)
end