wacky_graph 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ require 'wacky_graph/error.rb'
2
+ require 'wacky_graph/request.rb'
@@ -0,0 +1,15 @@
1
+ module WackyGraph
2
+ class GraphError < StandardError
3
+ attr_accessor :message, :type, :code, :error_subcode
4
+ # attr_accessor :type
5
+ # attr_accessor :code
6
+ # attr_accessor :error_subcode
7
+
8
+ def initialize(message, type, code, error_subcode)
9
+ @message = message
10
+ @type = type
11
+ @code = code
12
+ @error_subcode = error_subcode
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,51 @@
1
+ require 'net/http'
2
+
3
+ module WackyGraph
4
+ GRAPH_BASE_URI = 'http://graph.facebook.com'
5
+ SECURE_GRAPH_BASE_URI = 'https://graph.facebook.com'
6
+
7
+ class GraphRequest
8
+ attr_accessor :oauth_token
9
+
10
+ def initialize(oauth_token)
11
+ @oauth_token = oauth_token
12
+ end
13
+
14
+ def get(path, options = {})
15
+ uri = build_uri(path, options)
16
+ http = Net::HTTP.new(uri.host, uri.port)
17
+ http.use_ssl = true if uri.scheme == 'https'
18
+ request = Net::HTTP::Get.new(uri.request_uri)
19
+ response = http.request(request)
20
+ data = JSON.parse(response.body)
21
+ case response
22
+ when Net::HTTPOK
23
+ return data
24
+ when Net::HTTPBadRequest
25
+ exception = GraphError.new(data["error"]["message"], data["error"]["type"], data["error"]["code"], data["error"]["error_subcode"])
26
+ raise exception
27
+ else
28
+ raise "Unhandled response from Facebook Graph API"
29
+ end
30
+ end
31
+
32
+ def post(path, params)
33
+
34
+ end
35
+
36
+ private
37
+
38
+ def build_uri(path, options)
39
+ options[:params] = {} if options[:params].nil?
40
+ if options[:no_authorization] || @oauth_token.nil?
41
+ base_uri = GRAPH_BASE_URI
42
+ else
43
+ base_uri = SECURE_GRAPH_BASE_URI
44
+ options[:params][:access_token] = @oauth_token
45
+ end
46
+ uri = URI(base_uri + path)
47
+ uri.query = URI.encode_www_form(options[:params])
48
+ uri
49
+ end
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wacky_graph
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matt Rushton
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-26 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Wacky Graph is a gem extracted from Wacky Words Friends for using the
15
+ Facebook graph API.
16
+ email:
17
+ - mrushton7@yahoo.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - lib/wacky_graph.rb
23
+ - lib/wacky_graph/error.rb
24
+ - lib/wacky_graph/request.rb
25
+ homepage: http://www.wackywordsfriends.com
26
+ licenses: []
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ none: false
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 1.8.24
46
+ signing_key:
47
+ specification_version: 3
48
+ summary: Gem for the Facebook graph API.
49
+ test_files: []