Class: OpenSocial::FetchActivitiesRequest

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

Constant Summary collapse

SERVICE =

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

'activities'
RPC_SERVICE =

This is only necessary because of a spec inconsistency

'activity'

Instance Method Summary collapse

Constructor Details

#initialize(connection = nil, guid = '@me', selector = '@self', pid = nil) ⇒ FetchActivitiesRequest

Initializes a request to fetch activities 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.



69
70
71
72
# File 'lib/opensocial/activity.rb', line 69

def initialize(connection = nil, guid = '@me', selector = '@self',
               pid = nil)
  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.



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

def parse_rpc_response(response)
  return parse_response(response['data']['list'])
end

#sendObject

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



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

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

  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
# File 'lib/opensocial/activity.rb', line 90

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