Class: OpenSocial::AppData

Inherits:
Base
  • Object
show all
Defined in:
lib/opensocial/appdata.rb

Overview

Acts as a wrapper for an OpenSocial appdata entry.

The AppData class takes a person’s ID and input JSON as initialization parameters, and iterates through each of the key/value pairs of that JSON. For each key that is found, an attr_accessor is constructed (except for :id which is preconstructed, and required), allowing direct access to the value. Each value is stored in the attr_accessor, either as a String, Fixnum, Hash, or Array.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#add_attr

Constructor Details

#initialize(id, json) ⇒ AppData

Initializes the AppData entry based on the provided id and json fragment. If no JSON is provided, an empty object (with only an ID) is created.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/opensocial/appdata.rb', line 32

def initialize(id, json)
  @id = id

  if json
    json.each do |key, value|
      begin
        self.send("#{key}=", value)
      rescue NoMethodError
        add_attr(key)
        self.send("#{key}=", value)
      end
    end
  end
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



28
29
30
# File 'lib/opensocial/appdata.rb', line 28

def id
  @id
end