Class: OpenSocial::FetchPersonRequest

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

Overview

Provides the ability to request a single Person.

The FetchPeopleRequests wraps a simple request to an OpenSocial endpoint for a single person. As parameters, it accepts a user ID and selector and optionally an ID of a particular person, in order to display the user ID“s view of that person. 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"
@@default_fields =
[:id, :dateOfBirth, :name, :emails, :gender, :state, :postalCode, :ethnicity, :relationshipStatus, :thumbnailUrl, :displayName]

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") ⇒ FetchPersonRequest

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



96
97
98
# File 'lib/opensocial/person.rb', line 96

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

Instance Method Details

#parse_rpc_response(response) ⇒ Object

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



110
111
112
# File 'lib/opensocial/person.rb', line 110

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

#sendObject

Sends the request, passing in the appropriate SERVICE and specified instance variables.



102
103
104
105
106
# File 'lib/opensocial/person.rb', line 102

def send
  json = send_request(SERVICE, @guid, @selector, nil, false, :fields => @@default_fields.join(","))

  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.



116
117
118
119
120
121
122
123
124
125
# File 'lib/opensocial/person.rb', line 116

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