Sha256: 989fad8c6ee9a30c9af4808463758726d96cd125a7f1a727805de8641acc8d62

Contents?: true

Size: 1.08 KB

Versions: 8

Compression:

Stored size: 1.08 KB

Contents

module FbGraph
  class UserAchievement < Node
    include Connections::Comments
    include Connections::Likes

    attr_accessor :from, :created_time, :application, :achievement

    def initialize(identifier, attributes = {})
      super

      if from = attributes[:from]
        @from = User.new(from[:id], from)
      end
      if created_time = attributes[:created_time] || attributes[:publish_time]
        @created_time = Time.parse(created_time).utc
      end
      if application = attributes[:application]
        application[:link] = application[:url] # for some reason, FB uses "url" only here..
        @application = Application.new(application[:id], application)
      end
      if achievement = attributes[:achievement]
        @achievement = Achievement.new(achievement[:id], achievement)
      end

      # cached connection
      @_likes_ = Collection.new(attributes[:likes])
      @_comments_ = Collection.new(attributes[:comments])
    end

    def destroy(options = {})
      options[:access_token] ||= self.access_token
      from.unachieve!(achievement.url, options)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
fb_graph-2.2.0.alpha2 lib/fb_graph/user_achievement.rb
fb_graph-2.2.0.alpha lib/fb_graph/user_achievement.rb
fb_graph-2.1.13 lib/fb_graph/user_achievement.rb
fb_graph-2.1.12 lib/fb_graph/user_achievement.rb
fb_graph-2.1.11 lib/fb_graph/user_achievement.rb
fb_graph-2.1.10 lib/fb_graph/user_achievement.rb
fb_graph-2.1.9 lib/fb_graph/user_achievement.rb
fb_graph-2.1.8 lib/fb_graph/user_achievement.rb