Class: WackyGraph::GraphRequest

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(oauth_token) ⇒ GraphRequest

Returns a new instance of GraphRequest.



10
11
12
# File 'lib/wacky_graph/request.rb', line 10

def initialize(oauth_token)
  @oauth_token = oauth_token
end

Instance Attribute Details

#oauth_tokenObject

Returns the value of attribute oauth_token.



8
9
10
# File 'lib/wacky_graph/request.rb', line 8

def oauth_token
  @oauth_token
end

Instance Method Details

#get(path, options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/wacky_graph/request.rb', line 14

def get(path, options = {})
  uri = build_uri(path, options)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true if uri.scheme == 'https'
  request = Net::HTTP::Get.new(uri.request_uri)
  response = http.request(request)
  data = JSON.parse(response.body)
  case response
  when Net::HTTPOK
    return data
  when Net::HTTPBadRequest
    exception = GraphError.new(data["error"]["message"], data["error"]["type"], data["error"]["code"], data["error"]["error_subcode"])
    raise exception
  else
    raise "Unhandled response from Facebook Graph API"
  end
end

#post(path, params) ⇒ Object



32
33
34
# File 'lib/wacky_graph/request.rb', line 32

def post(path, params) 

end