Class: OpenSocial::Request

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

Constant Summary collapse

GET =
".get"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection = nil, guid = nil, selector = nil, pid = nil) ⇒ Request

Initializes a request using the optionally supplied connection, guid, selector, and pid.



49
50
51
52
53
54
# File 'lib/opensocial/request.rb', line 49

def initialize(connection = nil, guid = nil, selector = nil, pid = nil)
  @connection = connection
  @guid = guid
  @selector = selector
  @pid = pid
end

Instance Attribute Details

#connectionObject

Defines the connection that will be used in the request.



33
34
35
# File 'lib/opensocial/request.rb', line 33

def connection
  @connection
end

#guidObject

Defines the guid for the request.



36
37
38
# File 'lib/opensocial/request.rb', line 36

def guid
  @guid
end

#keyObject

Defines the key used to lookup the request result in an RPC request.



45
46
47
# File 'lib/opensocial/request.rb', line 45

def key
  @key
end

#pidObject

Defines the pid for the request.



42
43
44
# File 'lib/opensocial/request.rb', line 42

def pid
  @pid
end

#selectorObject

Defines the selector for the request.



39
40
41
# File 'lib/opensocial/request.rb', line 39

def selector
  @selector
end

Instance Method Details

#send_request(service, guid, selector = nil, pid = nil, unescape = false, extra_fields = {}) ⇒ Object

Generates a request given the service, guid, selector, and pid, to the OpenSocial endpoint by constructing the service URI and dispatching the request. When data is returned, it is parsed as JSON after being optionally unescaped.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/opensocial/request.rb', line 60

def send_request(service, guid, selector = nil, pid = nil,
                 unescape = false, extra_fields = {})
  if !@connection
    raise RequestException.new("Request requires a valid connection.")
  end

  uri = @connection.service_uri(@connection.container[:rest] + service,
                                guid, selector, pid, extra_fields)
  data = dispatch(uri)

  if unescape
    JSON.parse(os_unescape(data))
  else
    JSON.parse(data)
  end
end