Class: FbGraph::Achievement

Inherits:
Node
  • Object
show all
Defined in:
lib/fb_graph/achievement.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#access_token, #endpoint, #identifier, #raw_attributes

Instance Method Summary collapse

Methods inherited from Node

#connection, fetch, #fetch, #update

Methods included from Comparison

#==

Constructor Details

#initialize(identifier, attributes = {}) ⇒ Achievement

Returns a new instance of Achievement.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fb_graph/achievement.rb', line 5

def initialize(identifier, attributes = {})
  super

  # TODO: Handle data, context in smarter way.
  [:type, :title, :url, :description, :data, :context].each do |key|
    send "#{key}=", attributes[key]
  end

  if self.data
    @points = self.data[:points]
  end

  if self.context
    @display_order = self.context[:display_order]
  end

  @images = []
  if _images_ = attributes[:image]
    _images_.each do |_image_|
      @images << _image_[:url]
    end
  end
  @image = @images.first

  if application = attributes[:application]
    application[:link] = application[:url] # for some reason, FB uses "url" only here..
    @application = Application.new(application[:id], application)
  end

  if attributes[:updated_time]
    @updated_time = Time.parse(attributes[:updated_time]).utc
  end
end

Instance Attribute Details

#applicationObject

Returns the value of attribute application.



3
4
5
# File 'lib/fb_graph/achievement.rb', line 3

def application
  @application
end

#contextObject

Returns the value of attribute context.



3
4
5
# File 'lib/fb_graph/achievement.rb', line 3

def context
  @context
end

#dataObject

Returns the value of attribute data.



3
4
5
# File 'lib/fb_graph/achievement.rb', line 3

def data
  @data
end

#descriptionObject

Returns the value of attribute description.



3
4
5
# File 'lib/fb_graph/achievement.rb', line 3

def description
  @description
end

#display_orderObject

Returns the value of attribute display_order.



3
4
5
# File 'lib/fb_graph/achievement.rb', line 3

def display_order
  @display_order
end

#imageObject

Returns the value of attribute image.



3
4
5
# File 'lib/fb_graph/achievement.rb', line 3

def image
  @image
end

#imagesObject

Returns the value of attribute images.



3
4
5
# File 'lib/fb_graph/achievement.rb', line 3

def images
  @images
end

#pointsObject

Returns the value of attribute points.



3
4
5
# File 'lib/fb_graph/achievement.rb', line 3

def points
  @points
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/fb_graph/achievement.rb', line 3

def title
  @title
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/fb_graph/achievement.rb', line 3

def type
  @type
end

#updated_timeObject

Returns the value of attribute updated_time.



3
4
5
# File 'lib/fb_graph/achievement.rb', line 3

def updated_time
  @updated_time
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/fb_graph/achievement.rb', line 3

def url
  @url
end

Instance Method Details

#destroy(options = {}) ⇒ Object



39
40
41
42
# File 'lib/fb_graph/achievement.rb', line 39

def destroy(options = {})
  options[:access_token] ||= self.access_token
  application.unregister_achievement!(url, options)
end