fbdoorman 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.md +14 -2
  2. data/Rakefile +1 -1
  3. data/VERSION +1 -1
  4. data/lib/facebook_helpers.rb +65 -0
  5. metadata +4 -4
data/README.md CHANGED
@@ -39,6 +39,13 @@ Facebook controller inside the gem upon sign_in or session close. The facebook_j
39
39
 
40
40
  Installation
41
41
  ------------
42
+
43
+ Install the following gems required by minifb ([sudo] gem install [gemname])
44
+
45
+ * hashie
46
+ * rest-client
47
+ * json
48
+
42
49
  Same as clearance 0.8.8 this works with versions of Rails greater than 2.3.
43
50
 
44
51
  gem install fbdoorman
@@ -47,6 +54,10 @@ Make sure the development database exists and run the generator.
47
54
 
48
55
  script/generate fbdoorman
49
56
 
57
+ Add the gem dependency inside the config/environment.rb (Otherwise you'll get an error about Clearance constant not being initialized)
58
+
59
+ gem.config "fbdoorman"
60
+
50
61
  This:
51
62
 
52
63
  * inserts Clearance::User into your User model
@@ -82,7 +93,7 @@ method in a before_filter.
82
93
  Known-issue with "Missing host to link to"
83
94
  ---------
84
95
 
85
- Since Clearance tries to send confirmation mails and maybe Mailer settings are not defined in your app, you might run with and error. I'm not really sure why it happens but there's a solution if you just want to try clearance without the email confirmation.
96
+ Since Clearance tries to send confirmation mails and maybe Mailer settings are not defined in your app, you might run with an error. I'm not really sure why it happens but there's a solution if you just want to try clearance without the email confirmation.
86
97
 
87
98
  Check this link for how I solved it. If this is some mistake of mine please tell me how to solve it and I'll just edit de code right away!
88
99
 
@@ -92,7 +103,8 @@ Other helpers
92
103
  -----------
93
104
  Note: I didn't have that much time to create some fancy and useful helper's, hopefully in a next version!
94
105
 
95
- The user Facebook pic url in square format is returned by the helper facebook_pic_url
106
+ * The user Facebook pic url in square format is returned by the helper facebook_pic_url
107
+ * The amount of likes for a given link is return by like_count(url) (NO error management for this yet)
96
108
 
97
109
  Also the user name is added in a column inside user, so you can get that anytime with current_user.name
98
110
 
data/Rakefile CHANGED
@@ -18,7 +18,7 @@ Jeweler::Tasks.new do |gem|
18
18
  gem.summary = "Rails authentication with facebook single sign-on OR email & password."
19
19
  gem.description = "Painless user registration and sign-in using Facebook single sign-on with JS. Typical email login still works too."
20
20
  gem.email = "pelaez89@gmail.com"
21
- gem.version = "0.0.2"
21
+ gem.version = "0.0.3"
22
22
  gem.homepage = "http://github.com/davidpelaez/minifb-clearance"
23
23
  gem.authors = ["Fbdoorman: David Pelaez","MiniFB: Appoxy","Clearance: Thoughtbot"]
24
24
  gem.files = FileList["[A-Z]*", "{app,config,generators,lib,shoulda_macros,rails}/**/*"]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -46,3 +46,68 @@ end
46
46
  def facebook_pic_url
47
47
  return "http://graph.facebook.com/#{current_user.fbid}/picture?type=square"
48
48
  end
49
+
50
+ #
51
+ # CODE FOR FB LIKE
52
+ #
53
+ #query = "SELECT like_count FROM link_stat WHERE url=#{myurl}"
54
+
55
+ def like_count(myurl)
56
+ #myurl = "http://challenge.mistter.me:3000/projects/1"
57
+ query = "SELECT like_count FROM link_stat WHERE url=\"#{myurl}\""
58
+ return facebook_fql(query)[0].like_count
59
+ end
60
+
61
+ # Executes an FQL query
62
+ def facebook_fql(fql_query, options={})
63
+ url = "https://api.facebook.com/method/fql.query"
64
+ params = options[:params] || {}
65
+ params["metadata"] = "1" if options[:metadata]
66
+ params["format"] = "JSON"
67
+ params["query"] = fql_query
68
+ options[:params] = params
69
+ return fetch_url(url, options)
70
+ end
71
+
72
+ #Fetch something fro FB
73
+ def fetch_url(url, options={})
74
+ begin
75
+ if options[:method] == :post
76
+ puts 'url_post=' + url #if @@logging
77
+ resp = RestClient.post url, options[:params]
78
+ else
79
+ if options[:params] && options[:params].size > 0
80
+ url += '?' + options[:params].map { |k, v| URI.escape("%s=%s" % [k, v]) }.join('&')
81
+ end
82
+ puts 'url_get=' + url #if @@logging
83
+ resp = RestClient.get url
84
+ end
85
+
86
+ puts 'resp=' + resp.to_s #if @@logging
87
+
88
+ begin
89
+ res_hash = JSON.parse(resp.to_s)
90
+ rescue
91
+ # quick fix for things like stream.publish that don't return json
92
+ res_hash = JSON.parse("{\"response\": #{resp.to_s}}")
93
+ end
94
+
95
+ if res_hash.is_a? Array # fql return this
96
+ res_hash.collect! { |x| Hashie::Mash.new(x) }
97
+ else
98
+ res_hash = Hashie::Mash.new(res_hash)
99
+ end
100
+
101
+ if res_hash.include?("error_msg")
102
+ raise FaceBookError.new(res_hash["error_code"] || 1, res_hash["error_msg"])
103
+ end
104
+
105
+ return res_hash
106
+ rescue RestClient::Exception => ex
107
+ puts ex.http_code.to_s
108
+ puts 'ex.http_body=' + ex.http_body #if @@logging
109
+ res_hash = JSON.parse(ex.http_body) # probably should ensure it has a good response
110
+ raise MiniFB::FaceBookError.new(ex.http_code, "#{res_hash["error"]["type"]}: #{res_hash["error"]["message"]}")
111
+ end
112
+
113
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fbdoorman
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Fbdoorman: David Pelaez"
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-07-28 00:00:00 -05:00
20
+ date: 2010-07-31 00:00:00 -05:00
21
21
  default_executable:
22
22
  dependencies: []
23
23