Class: OpenSocial::FetchAppDataRequest

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

Overview

Provides the ability to request a Collection of AppData for a given user or set of users.

The FetchAppData wraps a simple request to an OpenSocial endpoint for a Collection of AppData. As parameters, it accepts a user ID and selector. This request may be used, standalone, by calling send, or bundled into an RpcRequest.

Constant Summary collapse

SERVICE =

Defines the service fragment for use in constructing the request URL or JSON

"appdata"

Constants inherited from Request

Request::GET

Instance Attribute Summary

Attributes inherited from Request

#connection, #guid, #key, #pid, #selector

Instance Method Summary collapse

Methods inherited from Request

#send_request

Constructor Details

#initialize(connection = nil, guid = "@me", selector = "@self", aid = "@app") ⇒ FetchAppDataRequest

Initializes a request to fetch appdata for the specified user and group, or the default (@me, @self). A valid Connection is not necessary if the request is to be used as part of an RpcRequest.



65
66
67
68
# File 'lib/opensocial/appdata.rb', line 65

def initialize(connection = nil, guid = "@me", selector = "@self",
               aid = "@app")
  super(connection, guid, selector, aid)
end

Instance Method Details

#parse_rpc_response(response) ⇒ Object

Selects the appropriate fragment from the JSON response in order to create a native object.



81
82
83
# File 'lib/opensocial/appdata.rb', line 81

def parse_rpc_response(response)
  return parse_response(response["data"])
end

#send(unescape = true) ⇒ Object

Sends the request, passing in the appropriate SERVICE and specified instance variables. Accepts an unescape parameter, defaulting to true, if the returned data should be unescaped.



73
74
75
76
77
# File 'lib/opensocial/appdata.rb', line 73

def send(unescape = true)
  json = send_request(SERVICE, @guid, @selector, @pid, unescape)

  return parse_response(json["entry"])
end

#to_json(*a) ⇒ Object

Converts the request into a JSON fragment that can be used as part of a larger RpcRequest.



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/opensocial/appdata.rb', line 87

def to_json(*a)
  value = {
    "method" => SERVICE + GET,
    "params" => {
      "userId" => ["#{@guid}"],
      "groupId" => "#{@selector}",
      "appId" => "#{@pid}",
      "fields" => []
    },
    "id" => @key
  }.to_json(*a)
end