facebookcl 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.3
1
+ 0.3.4
@@ -1,6 +1,4 @@
1
1
  module FacebookCommands; class << self
2
- public
3
-
4
2
  def method_missing(command, *args)
5
3
  puts "#{command} is not supported"
6
4
  end
@@ -1,6 +1,4 @@
1
1
  module FacebookCommands; class << self
2
- public
3
-
4
2
  def help(*args)
5
3
  if (args.first == 'help')
6
4
  puts 'help'
@@ -1,6 +1,4 @@
1
1
  module FacebookCommands; class << self
2
- public
3
-
4
2
  def info(*args)
5
3
  if (args.first == 'help')
6
4
  puts 'info'
@@ -1,8 +1,6 @@
1
1
  require 'optparse'
2
2
 
3
3
  module FacebookCommands; class << self
4
- public
5
-
6
4
  def picture(*args)
7
5
  if (args.first == 'help')
8
6
  puts 'picture <friend>'
@@ -1,8 +1,6 @@
1
1
  require 'optparse'
2
2
 
3
3
  module FacebookCommands; class << self
4
- public
5
-
6
4
  def stream(*args)
7
5
  if args.empty?
8
6
  puts 'stream by itself does nothing'
@@ -1,6 +1,4 @@
1
1
  module FacebookCommands; class << self
2
- public
3
-
4
2
  def wall(*args)
5
3
  if args.empty?
6
4
  puts 'wall by itself does nothing'
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{facebookcl}
8
- s.version = "0.3.3"
8
+ s.version = "0.3.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Justin Bishop"]
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
33
33
  "commands/stream.rb",
34
34
  "commands/wall.rb",
35
35
  "facebookcl.gemspec",
36
+ "lib/facebook_server.rb",
36
37
  "lib/facebookcl.rb"
37
38
  ]
38
39
  s.homepage = %q{http://github.com/jubishop/facebookcl}
@@ -0,0 +1,36 @@
1
+ class FacebookAuthServer < TCPServer
2
+ def serve_and_extract_access_token_from_user_agent_flow
3
+ serve_content_and_return_request(%Q{
4
+ <script>
5
+ window.location.replace(window.location.toString().replace('#', '?'));
6
+ </script>})
7
+
8
+ request = serve_content_and_return_request(%q{
9
+ Success! You can now close this window and return to FacebookCL.
10
+ <script>
11
+ window.close();
12
+ </script>})
13
+
14
+ extract_access_token_from_request(request)
15
+ end
16
+
17
+ private
18
+
19
+ HTTP_HEADER = "HTTP/1.1 200/OK\r\nContent-type:text/html\r\n\r\n"
20
+
21
+ def serve_content_and_return_request(content)
22
+ session = accept
23
+ session.print HTTP_HEADER
24
+
25
+ request = session.gets.strip
26
+
27
+ session.print(content)
28
+ session.close
29
+
30
+ request
31
+ end
32
+
33
+ def extract_access_token_from_request(request)
34
+ request.gsub(/^GET \/\?access_token=/, '').gsub(/ HTTP.*$/, '')
35
+ end
36
+ end
@@ -10,9 +10,11 @@ require 'uri'
10
10
  # runtime dependencies
11
11
  require 'json'
12
12
 
13
- module FacebookCL; class << self
14
- public
13
+ # helper libs
14
+ __DIR__ = File.dirname(__FILE__)
15
+ require __DIR__ + '/facebook_server.rb'
15
16
 
17
+ module FacebookCL; class << self
16
18
  APP_ID = 119412046078 # FacebookCL
17
19
  SERVER_PORT = 6682 # my birthday ;o)
18
20
  GRAPH_URL = 'graph.facebook.com'
@@ -52,22 +54,11 @@ module FacebookCL; class << self
52
54
  auth_url
53
55
  end
54
56
 
55
- serve_content(%Q{
56
- <script>
57
- window.location.replace(window.location.toString().replace('#', '?'));
58
- </script>})
59
-
60
- request = serve_content(%q{
61
- Success! You can now close this window and return to FacebookCL.
62
- <script>
63
- window.close();
64
- </script>})
57
+ server = FacebookAuthServer.new(NEXT_URL, SERVER_PORT)
58
+ self.access_token =
59
+ server.serve_and_extract_access_token_from_user_agent_flow
60
+ server.close
65
61
 
66
- @server.close
67
-
68
- self.access_token = request.
69
- gsub(/^GET \/\?access_token=/, '').
70
- gsub(/ HTTP.*$/, '')
71
62
  self.uid = get('me')['id']
72
63
 
73
64
  puts "Saving authentication data to #{config_filename}"
@@ -116,18 +107,4 @@ module FacebookCL; class << self
116
107
  value
117
108
  end
118
109
  end
119
-
120
- def serve_content(content)
121
- @server ||= TCPServer.new(NEXT_URL, SERVER_PORT)
122
-
123
- session = @server.accept
124
- session.print "HTTP/1.1 200/OK\r\nContent-type:text/html\r\n\r\n"
125
-
126
- request = session.gets.strip
127
-
128
- session.print content
129
- session.close
130
-
131
- request
132
- end
133
110
  end; end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facebookcl
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 3
10
- version: 0.3.3
9
+ - 4
10
+ version: 0.3.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Justin Bishop
@@ -56,6 +56,7 @@ files:
56
56
  - commands/stream.rb
57
57
  - commands/wall.rb
58
58
  - facebookcl.gemspec
59
+ - lib/facebook_server.rb
59
60
  - lib/facebookcl.rb
60
61
  has_rdoc: true
61
62
  homepage: http://github.com/jubishop/facebookcl