mogli 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/mogli.rb CHANGED
@@ -6,6 +6,7 @@ require "httparty"
6
6
  require "hashie"
7
7
 
8
8
 
9
+ require "mogli/authenticator"
9
10
  require "mogli/model"
10
11
  require "mogli/fetching_array"
11
12
  require "mogli/action"
@@ -0,0 +1,21 @@
1
+ require "cgi"
2
+ module Mogli
3
+ class Authenticator
4
+ attr_reader :client_id, :secret, :callback_url
5
+
6
+ def initialize(client_id,secret,callback_url)
7
+ @client_id = client_id
8
+ @secret = secret
9
+ @callback_url = callback_url
10
+ end
11
+
12
+ def authorize_url
13
+ "https://graph.facebook.com/oauth/authorize?client_id=#{client_id}&redirect_uri=#{CGI.escape(callback_url)}"
14
+ end
15
+
16
+ def access_token_url(code)
17
+ "https://graph.facebook.com/oauth/access_token?client_id=#{client_id}&redirect_uri=#{CGI.escape(callback_url)}&client_secret=#{secret}&code=#{CGI.escape(code)}"
18
+ end
19
+
20
+ end
21
+ end
data/lib/mogli/client.rb CHANGED
@@ -19,6 +19,20 @@ module Mogli
19
19
  @default_params = @access_token ? {:access_token=>access_token} : {}
20
20
  end
21
21
 
22
+ def self.get_access_token_for_code_and_authenticator(code,authenticator)
23
+ post_data = get(authenticator.access_token_url(code))
24
+ parts = post_data.split("&")
25
+ hash = {}
26
+ parts.each do |p| (k,v) = p.split("=")
27
+ hash[k]=v
28
+ end
29
+ hash["access_token"]
30
+ end
31
+
32
+ def self.create_from_code_and_authenticator(code,authenticator)
33
+ new(get_access_token_for_code_and_authenticator(code,authenticator))
34
+ end
35
+
22
36
  def get_and_map(path,klass=nil)
23
37
  data = self.class.get(api_path(path),:query=>default_params)
24
38
  map_data(data,klass)
@@ -36,7 +50,6 @@ module Mogli
36
50
  hash_or_array
37
51
  end
38
52
 
39
-
40
53
  #protected
41
54
 
42
55
  def extract_hash_or_array(hash_or_array,klass)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mogli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Mangino
@@ -45,6 +45,7 @@ files:
45
45
  - lib/mogli/activity.rb
46
46
  - lib/mogli/address.rb
47
47
  - lib/mogli/album.rb
48
+ - lib/mogli/authenticator.rb
48
49
  - lib/mogli/book.rb
49
50
  - lib/mogli/client/user.rb
50
51
  - lib/mogli/client.rb