fbrails 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -4,3 +4,4 @@ Gemfile.lock
4
4
  pkg/*
5
5
  lib/*.swp
6
6
  *.swp
7
+ .redcar
data/README CHANGED
@@ -17,6 +17,6 @@ Fbrails::Auth.token_valid?(token,expire_time) # return true of false
17
17
 
18
18
 
19
19
 
20
- @graph = Fbrails::Graph.new(token)
20
+ graph = Fbrails::Graph.new(token)
21
21
 
22
- @graph.me # return hash with your info or false
22
+ graph.me # return hash with your info or false
data/fbrails.gemspec CHANGED
@@ -6,7 +6,7 @@ require "fbrails/version"
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "fbrails"
8
8
  s.version = Fbrails::VERSION
9
- s.authors = ["Dmitry Gruzd", "Vitaly Mineev"]
9
+ s.authors = ["Dmitry Gruzd", "Vitaly Mineev", "Ivan Shamatov"]
10
10
  s.email = ["donotsendhere@gmail.com"]
11
11
  s.homepage = ""
12
12
  s.summary = %q{Small gem for auth & getting info from facebook}
@@ -0,0 +1,52 @@
1
+ module Fbrails
2
+ class Auth
3
+ def initialize(app_id, secret, app_url)
4
+ @app_id = app_id
5
+ @app_url = app_url
6
+ @secret = secret
7
+ end
8
+
9
+ def redirect_url
10
+ if !@app_id.blank? && !@app_url.blank?
11
+ "https://www.facebook.com/dialog/oauth?client_id=#{@app_id}&redirect_uri=#{@app_url}"
12
+ else
13
+ ""
14
+ end
15
+ end
16
+
17
+ def token(code)
18
+ url = "https://graph.facebook.com/oauth/access_token?client_id=#{@app_id}&redirect_uri=#{@app_url}&client_secret=#{@secret}&code=#{code}"
19
+ resp = Fbrails.get(url,true)
20
+ if resp.include?("access_token=")
21
+ hash = Hash.new
22
+ expire = resp.scan(/\d+/).last.to_i
23
+ hash[:expires] = Time.new + expire
24
+ hash[:token] = resp.gsub(/access_token=/, "").gsub(/&expires=\d+/,"")
25
+ return hash
26
+ else
27
+ nil
28
+ end
29
+ end
30
+
31
+ def self.token_valid?(token,expires = false)
32
+ if expires.class == Time && expires < Time.new
33
+ return false
34
+ end
35
+
36
+ url = "https://graph.facebook.com/me/?access_token=#{token}"
37
+ begin
38
+ result = Fbrails.get(url)
39
+ rescue
40
+ return false
41
+ end
42
+ if result == false
43
+ return false
44
+ elsif result.has_key?("id")
45
+ return true
46
+ else
47
+ return nil
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,28 @@
1
+ module Fbrails
2
+ class Graph
3
+ def initialize(token)
4
+ @token = token
5
+ end
6
+
7
+ def get_object(obj = "")
8
+ url = "https://graph.facebook.com/me/#{obj}?access_token=#{@token}"
9
+ Fbrails.get(url)
10
+ end
11
+
12
+
13
+ #graph.get_picture(ID,TYPE)
14
+ #TYPE can be square (50x50), small (50 pixels wide, variable height), normal (100 pixels wide, variable height), large (about 200 pixels wide, variable height)
15
+ def get_picture(id,type=nil)
16
+ first = "http://graph.facebook.com/#{id}/picture"
17
+ if type.blank?
18
+ return first
19
+ elsif type == 'square' || type = 'small' || type == 'normal' || type == 'large'
20
+ return first + "?type=#{type}"
21
+ end
22
+ end
23
+
24
+
25
+
26
+
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module Fbrails
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/fbrails.rb CHANGED
@@ -1,78 +1,13 @@
1
1
  require "fbrails/version"
2
2
  require 'net/https'
3
3
  require 'json'
4
+
4
5
  module Fbrails
5
6
 
6
7
  class FailedToGet < StandardError
7
8
  end
8
9
 
9
-
10
- class Auth
11
- def initialize(app_id, secret, app_url)
12
- @app_id = app_id
13
- @app_url = app_url
14
- @secret = secret
15
- end
16
-
17
- def token(code)
18
- url = "https://graph.facebook.com/oauth/access_token?client_id=#{@app_id}&redirect_uri=#{@app_url}&client_secret=#{@secret}&code=#{code}"
19
- resp = Fbrails.get(url,true)
20
- if resp.include?("access_token=")
21
- hash = Hash.new
22
- expire = resp.scan(/\d+/).last.to_i
23
- hash[:expires] = Time.new + expire
24
- hash[:token] = resp.gsub(/access_token=/, "").gsub(/&expires=\d+/,"")
25
- return hash
26
- else
27
- nil
28
- end
29
- end
30
-
31
- def self.token_valid?(token,expires = false)
32
- if expires.class == Time && expires < Time.new
33
- return false
34
- end
35
-
36
- url = "https://graph.facebook.com/me/?access_token=#{token}"
37
- begin
38
- result = Fbrails.get(url)
39
- rescue
40
- return false
41
- end
42
- if result == false
43
- return false
44
- elsif result.has_key?("id")
45
- return true
46
- else
47
- return nil
48
- end
49
-
50
- end
51
-
52
- def redirect_url
53
- if !@app_id.blank? && !@app_url.blank?
54
- "https://www.facebook.com/dialog/oauth?client_id=#{@app_id}&redirect_uri=#{@app_url}"
55
- else
56
- ""
57
- end
58
- end
59
- end
60
-
61
- class Graph
62
- def initialize(token)
63
- @token = token
64
- end
65
-
66
-
67
-
68
- def me
69
- url = "https://graph.facebook.com/me/?access_token=#{@token}"
70
- Fbrails.get(url)
71
- end
72
- end
73
-
74
-
75
- def self.get(url,raw = false)
10
+ def self.get(url,raw = false)
76
11
  uri = URI.parse(url)
77
12
  http = Net::HTTP.new(uri.host,uri.port)
78
13
  http.use_ssl = true
@@ -89,6 +24,10 @@ end
89
24
  else
90
25
  return result
91
26
  end
92
- end
27
+ end
28
+
29
+ require 'fbrails/auth'
30
+
31
+ require 'fbrails/graph'
93
32
 
94
33
  end
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fbrails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Dmitry Gruzd
9
9
  - Vitaly Mineev
10
+ - Ivan Shamatov
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2011-10-03 00:00:00.000000000Z
14
+ date: 2011-10-06 00:00:00.000000000Z
14
15
  dependencies: []
15
16
  description: Small gem for auth & getting info from facebook
16
17
  email:
@@ -25,6 +26,8 @@ files:
25
26
  - Rakefile
26
27
  - fbrails.gemspec
27
28
  - lib/fbrails.rb
29
+ - lib/fbrails/auth.rb
30
+ - lib/fbrails/graph.rb
28
31
  - lib/fbrails/version.rb
29
32
  homepage: ''
30
33
  licenses: []