Class: OpenSocial::FetchPeopleRequest
- Defined in:
- lib/opensocial/person.rb
Overview
Provides the ability to request a Collection of people by describing their relationship to a single person.
The FetchPeopleRequests wraps a simple request to an OpenSocial
endpoint for a Collection of people. 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
"people"
Constants inherited from Request
Instance Attribute Summary
Attributes inherited from Request
#connection, #guid, #key, #pid, #selector
Instance Method Summary collapse
-
#initialize(connection = nil, guid = "@me", selector = "@friends", extra_fields = {}) ⇒ FetchPeopleRequest
constructor
Initializes a request to the specified user’s group, or the default (@me, @friends).
-
#parse_rpc_response(response) ⇒ Object
Selects the appropriate fragment from the JSON response in order to create a native object.
-
#send ⇒ Object
Sends the request, passing in the appropriate SERVICE and specified instance variables.
-
#to_json(*a) ⇒ Object
Converts the request into a JSON fragment that can be used as part of a larger RPC request.
Methods inherited from Request
Constructor Details
#initialize(connection = nil, guid = "@me", selector = "@friends", extra_fields = {}) ⇒ FetchPeopleRequest
Initializes a request to the specified user’s group, or the default (@me, @friends). A valid Connection is not necessary if the request is to be used as part of an RpcRequest.
151 152 153 154 |
# File 'lib/opensocial/person.rb', line 151 def initialize(connection = nil, guid = "@me", selector = "@friends", extra_fields = {}) super @extra_fields = extra_fields end |
Instance Method Details
#parse_rpc_response(response) ⇒ Object
Selects the appropriate fragment from the JSON response in order to create a native object.
167 168 169 |
# File 'lib/opensocial/person.rb', line 167 def parse_rpc_response(response) return parse_response(response["data"]["list"]) end |
#send ⇒ Object
Sends the request, passing in the appropriate SERVICE and specified instance variables.
158 159 160 161 162 163 |
# File 'lib/opensocial/person.rb', line 158 def send @extra_fields[:fields] ||= FetchPersonRequest::DEFAULT_FIELDS.join(",") json = send_request(SERVICE, @guid, @selector, nil, false, @extra_fields) 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 RPC request.
173 174 175 176 177 178 179 180 181 182 |
# File 'lib/opensocial/person.rb', line 173 def to_json(*a) value = { "method" => SERVICE + GET, "params" => { "userId" => ["#{@guid}"], "groupId" => "#{@selector}" }, "id" => @key }.to_json(*a) end |