facebook_light 0.0.1dev

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in facebook_light.gemspec
4
+ gemspec
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = Facebook Light
2
+
3
+ TODO: write a description
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "facebook_light/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "facebook_light"
7
+ s.version = FacebookLight::VERSION
8
+ s.author = "Daniel Mircea"
9
+ s.email = ["daniel@viseztrance.com"]
10
+ s.homepage = "https://github.com/viseztrance/facebook_light"
11
+ s.summary = "Facebook Light"
12
+ s.description = "A transparent facebook api implementation that doesn't obscure requests"
13
+
14
+ s.rubyforge_project = "facebook_light"
15
+ s.requirements << "curl"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_runtime_dependency "json"
23
+ s.add_runtime_dependency "cocaine"
24
+ end
@@ -0,0 +1,56 @@
1
+ module FacebookLight
2
+
3
+ class Client
4
+
5
+ attr_accessor :access_token
6
+
7
+ class << self
8
+
9
+ def authorize_url(options = {})
10
+ redirect_uri = options[:redirect_uri] || raise("Redirect URI must be specified")
11
+ scope = options[:scope] || "email"
12
+ url = "https://www.facebook.com/dialog/oauth?client_id=%s&redirect_uri=%s&scope=%s" %
13
+ [FacebookLight.settings[:app_id], redirect_uri, scope]
14
+ end
15
+
16
+ def get_access_token(code, redirect_uri)
17
+ url = "https://graph.facebook.com/oauth/access_token?client_id=%s&redirect_uri=%s&client_secret=%s&code=%s" %
18
+ [FacebookLight.settings[:app_id], redirect_uri, FacebookLight.settings[:app_secret], code]
19
+ token = CGI.parse(Request.new(url).run)["access_token"].first
20
+ new token
21
+ end
22
+
23
+ def parse_signed_request(code)
24
+ base64_url_decode = lambda { |value|
25
+ value += "=" * (4 - value.length.modulo(4))
26
+ Base64.decode64(value.tr("-_", "+/"))
27
+ }
28
+ # Facebook's signed requests come in two parts - the signature and the data payload
29
+ # see http://developers.facebook.com/docs/authentication/canvas
30
+ encoded_sig, payload = code.split(".")
31
+ sig = base64_url_decode.call(encoded_sig)
32
+
33
+ # If the signature matches, return the data, decoded and parsed as JSON.
34
+ if OpenSSL::HMAC.digest("sha256", FacebookLight.settings[:app_secret], payload) == sig
35
+ token = JSON.parse(base64_url_decode.call(payload))["oauth_token"]
36
+ new token
37
+ else
38
+ nil
39
+ end
40
+ end
41
+
42
+ end
43
+
44
+ def initialize(access_token)
45
+ self.access_token = access_token
46
+ end
47
+
48
+ def get(query, options = {})
49
+ host = options[:site] || FacebookLight.settings[:site]
50
+ url = "#{host}#{query}?access_token=#{access_token}"
51
+ Request.new(url).run
52
+ end
53
+
54
+ end
55
+
56
+ end
@@ -0,0 +1,23 @@
1
+ module FacebookLight
2
+
3
+ class Request
4
+
5
+ attr_accessor :dispatcher, :command
6
+
7
+ def initialize(url, options = {})
8
+ args = {
9
+ :timeout => "2",
10
+ :retries => "3",
11
+ :method => "GET",
12
+ :url => url
13
+ }
14
+ self.dispatcher = Cocaine::CommandLine.new("curl", "-X :method --connect-timeout :timeout --retry :retries :url", args)
15
+ end
16
+
17
+ def run
18
+ self.dispatcher.run
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,3 @@
1
+ module FacebookLight
2
+ VERSION = "0.0.1dev"
3
+ end
@@ -0,0 +1,19 @@
1
+ require "base64"
2
+ require "openssl"
3
+ require "facebook_light/version"
4
+ require "facebook_light/request"
5
+ require "facebook_light/client"
6
+
7
+ module FacebookLight
8
+
9
+ def self.settings
10
+ @@settings ||= {
11
+ :site => "https://graph.facebook.com"
12
+ }
13
+ end
14
+
15
+ def self.settings=(settings)
16
+ @@settings = settings
17
+ end
18
+
19
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: facebook_light
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1dev
5
+ prerelease: 5
6
+ platform: ruby
7
+ authors:
8
+ - Daniel Mircea
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-23 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: &19613680 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *19613680
25
+ - !ruby/object:Gem::Dependency
26
+ name: cocaine
27
+ requirement: &19613260 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *19613260
36
+ description: A transparent facebook api implementation that doesn't obscure requests
37
+ email:
38
+ - daniel@viseztrance.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - README.rdoc
46
+ - Rakefile
47
+ - facebook_light.gemspec
48
+ - lib/facebook_light.rb
49
+ - lib/facebook_light/client.rb
50
+ - lib/facebook_light/request.rb
51
+ - lib/facebook_light/version.rb
52
+ homepage: https://github.com/viseztrance/facebook_light
53
+ licenses: []
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>'
68
+ - !ruby/object:Gem::Version
69
+ version: 1.3.1
70
+ requirements:
71
+ - curl
72
+ rubyforge_project: facebook_light
73
+ rubygems_version: 1.8.10
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Facebook Light
77
+ test_files: []