Class: OpenSocial::FetchAppDataRequest

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

Constant Summary collapse

SERVICE =

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

'appdata'

Instance Method Summary collapse

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.



68
69
70
71
# File 'lib/opensocial/appdata.rb', line 68

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.



84
85
86
# File 'lib/opensocial/appdata.rb', line 84

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.



76
77
78
79
80
# File 'lib/opensocial/appdata.rb', line 76

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.



90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/opensocial/appdata.rb', line 90

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