facebookcl 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Justin Bishop
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,20 @@
1
+ FacebookCL
2
+ ==========
3
+
4
+ Installation
5
+ ------------
6
+
7
+ * git clone git@github.com:jubishop/FacebookCL.git
8
+ * cd FacebookCL
9
+ * ruby facebook.rb
10
+
11
+ ### Extra Features ###
12
+
13
+ * To print photos in ascii-art you need [jp2a](http://csl.sublevel3.org/jp2a/)
14
+
15
+ Usage
16
+ -----
17
+
18
+ * ruby facebook.rb
19
+ * help
20
+ * Hello World
data/Rakefile ADDED
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "facebookcl"
8
+ gem.summary = %Q{: one-line summary of your gem}
9
+ gem.description = %Q{: longer description of your gem}
10
+ gem.email = "jubishop@gmail.com"
11
+ gem.homepage = "http://github.com/jubishop/facebookcl"
12
+ gem.authors = ["Justin Bishop"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ # gem is a Gem::Specification...
15
+ # see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available."
20
+ puts "Install it with: gem install jeweler"
21
+ end
22
+
23
+ require 'spec/rake/spectask'
24
+ Spec::Rake::SpecTask.new(:spec) do |spec|
25
+ spec.libs << 'lib' << 'spec'
26
+ spec.spec_files = FileList['spec/**/*_spec.rb']
27
+ end
28
+
29
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
30
+ spec.libs << 'lib' << 'spec'
31
+ spec.pattern = 'spec/**/*_spec.rb'
32
+ spec.rcov = true
33
+ end
34
+
35
+ task :spec => :check_dependencies
36
+
37
+ task :default => :spec
38
+
39
+ require 'rake/rdoctask'
40
+ Rake::RDocTask.new do |rdoc|
41
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
42
+
43
+ rdoc.rdoc_dir = 'rdoc'
44
+ rdoc.title = "facebookcl #{version}"
45
+ rdoc.rdoc_files.include('README*')
46
+ rdoc.rdoc_files.include('lib/**/*.rb')
47
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/commands/base.rb ADDED
@@ -0,0 +1,7 @@
1
+ module FacebookCommands; class << self
2
+ public
3
+
4
+ def method_missing(command, *args)
5
+ puts "#{command} is not supported"
6
+ end
7
+ end; end
data/commands/help.rb ADDED
@@ -0,0 +1,18 @@
1
+ module FacebookCommands; class << self
2
+ public
3
+
4
+ def help(*args)
5
+ if (args.first == 'help')
6
+ puts 'help'
7
+ return
8
+ end
9
+
10
+ if (args.empty?)
11
+ commands = singleton_methods - ['method_missing']
12
+ puts "Type '<command> help' or 'help <command>' for details."
13
+ puts " #{commands.join("\n ")}"
14
+ else
15
+ send(args.shift, 'help')
16
+ end
17
+ end
18
+ end; end
data/commands/info.rb ADDED
@@ -0,0 +1,15 @@
1
+ module FacebookCommands; class << self
2
+ public
3
+
4
+ def info(*args)
5
+ if (args.first == 'help')
6
+ puts 'info'
7
+ return
8
+ end
9
+
10
+ info = FacebookCL.get('me')
11
+
12
+ puts "Name: #{info['name']}"
13
+ puts "Email: #{info['email']}"
14
+ end
15
+ end; end
@@ -0,0 +1,40 @@
1
+ require 'optparse'
2
+
3
+ module FacebookCommands; class << self
4
+ public
5
+
6
+ def picture(*args)
7
+ if (args.first == 'help')
8
+ puts 'picture <friend>'
9
+ PICTURE_PARAMS.each { |param|
10
+ puts " -#{param[0,1]}, --#{param} #{param.upcase}"
11
+ }
12
+ return
13
+ end
14
+
15
+ if (`which jp2a`.strip.empty?)
16
+ puts 'ERROR: You need jp2a: http://csl.sublevel3.org/jp2a/'
17
+ return
18
+ end
19
+
20
+ user = args.empty? || args.first[0,1] == '-' ? FacebookCL.uid : args.shift
21
+
22
+ parameters, option_parser = Hash.new, OptionParser.new
23
+ PICTURE_PARAMS.each { |param|
24
+ short = "-#{param[0,1]}"
25
+ long = "--#{param} #{param.upcase}"
26
+ option_parser.on(short, long) { |value|
27
+ parameters[param] = value
28
+ }
29
+ }
30
+ option_parser.parse(args)
31
+ jp2a_options = parameters.map{|key, value| "--#{key}=#{value}"}
32
+
33
+ puts `jp2a #{jp2a_options} http://graph.facebook.com/#{user}/picture`
34
+ end
35
+
36
+ private
37
+
38
+ PICTURE_PARAMS = ['width',
39
+ 'height']
40
+ end; end
@@ -0,0 +1,78 @@
1
+ require 'optparse'
2
+
3
+ module FacebookCommands; class << self
4
+ public
5
+
6
+ def stream(*args)
7
+ if args.empty?
8
+ puts 'stream by itself does nothing'
9
+ return
10
+ end
11
+
12
+ if (args.first == 'help')
13
+ puts 'stream publish'
14
+ PUBLISH_PARAMS.each { |param|
15
+ puts " -#{param[0,1]}, --#{param} #{param.upcase}"
16
+ }
17
+ puts 'stream read'
18
+ return
19
+ end
20
+
21
+ Stream.send(args.shift, *args)
22
+ end
23
+
24
+ private
25
+
26
+ PUBLISH_PARAMS = ['message',
27
+ 'picture',
28
+ 'name',
29
+ 'link',
30
+ 'caption',
31
+ 'description',
32
+ 'source']
33
+
34
+ class Stream; class << self
35
+ def publish(*args)
36
+ url, parameters, option_parser = 'me/feed', Hash.new, OptionParser.new
37
+
38
+ PUBLISH_PARAMS.each { |param|
39
+ short = "-#{param[0,1]}"
40
+ long = "--#{param} #{param.upcase}"
41
+ option_parser.on(short, long) { |value|
42
+ parameters[param] = value
43
+ }
44
+ }
45
+ option_parser.on('--friend FRIEND') { |friend|
46
+ url = "#{friend}/feed"
47
+ }
48
+ option_parser.parse(args)
49
+
50
+ unless parameters.has_key?('message')
51
+ puts 'MESSAGE is required'
52
+ return
53
+ end
54
+
55
+ result = JSON.parse(FacebookCL.post(url, parameters).body)
56
+ if (result.has_key?('id'))
57
+ puts "Success! Post id is: #{result['id']}"
58
+ elsif (result.has_key?('error'))
59
+ puts 'Bummer. Error:'
60
+ puts result['error']['message']
61
+ else
62
+ puts 'Unknown error..'
63
+ end
64
+ end
65
+
66
+ def read(*args)
67
+ stream = FacebookCL.get('me/feed')['data']
68
+ stream.each { |post|
69
+ puts post['message']
70
+ puts "\n------------------------------------------------------------\n"
71
+ }
72
+ end
73
+
74
+ def method_missing(verb, *args)
75
+ puts "#{verb} is not an action on stream"
76
+ end
77
+ end; end
78
+ end; end
data/commands/wall.rb ADDED
@@ -0,0 +1,37 @@
1
+ module FacebookCommands; class << self
2
+ public
3
+
4
+ def wall(*args)
5
+ if args.empty?
6
+ puts 'wall by itself does nothing'
7
+ return
8
+ end
9
+
10
+ if (args.first == 'help')
11
+ puts 'wall post <friend>'
12
+ PUBLISH_PARAMS.each { |param|
13
+ puts " -#{param[0,1]}, --#{param} #{param.upcase}"
14
+ }
15
+ return
16
+ end
17
+
18
+ Wall.send(args.shift, *args)
19
+ end
20
+
21
+ private
22
+
23
+ class Wall; class << self
24
+ def post(*args)
25
+ if (args.empty?)
26
+ puts 'wall post requires a <friend>'
27
+ return
28
+ end
29
+
30
+ Stream.publish(*args.unshift('--friend'))
31
+ end
32
+
33
+ def method_missing(verb, *args)
34
+ puts "#{verb} is not an action on wall"
35
+ end
36
+ end; end
37
+ end; end
@@ -0,0 +1,62 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{facebookcl}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Justin Bishop"]
12
+ s.date = %q{2010-06-24}
13
+ s.description = %q{: longer description of your gem}
14
+ s.email = %q{jubishop@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.markdown",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "commands/base.rb",
27
+ "commands/help.rb",
28
+ "commands/info.rb",
29
+ "commands/picture.rb",
30
+ "commands/stream.rb",
31
+ "commands/wall.rb",
32
+ "facebookcl.gemspec",
33
+ "facebookcl.rb",
34
+ "lib/facebookcl.rb",
35
+ "spec/facebookcl_spec.rb",
36
+ "spec/spec.opts",
37
+ "spec/spec_helper.rb"
38
+ ]
39
+ s.homepage = %q{http://github.com/jubishop/facebookcl}
40
+ s.rdoc_options = ["--charset=UTF-8"]
41
+ s.require_paths = ["lib"]
42
+ s.rubygems_version = %q{1.3.5}
43
+ s.summary = %q{: one-line summary of your gem}
44
+ s.test_files = [
45
+ "spec/facebookcl_spec.rb",
46
+ "spec/spec_helper.rb"
47
+ ]
48
+
49
+ if s.respond_to? :specification_version then
50
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
+ s.specification_version = 3
52
+
53
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
54
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
55
+ else
56
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
60
+ end
61
+ end
62
+
data/facebookcl.rb ADDED
@@ -0,0 +1,32 @@
1
+ require 'readline'
2
+ require 'shellwords'
3
+
4
+ require 'lib/FacebookCL.rb'
5
+ Dir.glob("commands/*.rb").each { |src| require src }
6
+
7
+ FacebookCL.authorize
8
+
9
+ HISTORY_FILENAME = "#{ENV['HOME']}/.FacebookCLHistory"
10
+ if (File.exists?(HISTORY_FILENAME))
11
+ history_text = File.open(HISTORY_FILENAME, 'r'){|file| file.read}
12
+ saved_history = JSON.parse(history_text)
13
+ saved_history.each { |historical_event|
14
+ Readline::HISTORY.push(historical_event)
15
+ }
16
+ end
17
+
18
+ at_exit {
19
+ File.open(HISTORY_FILENAME, 'w') { |file|
20
+ file.puts Readline::HISTORY.to_a.to_json
21
+ }
22
+ }
23
+
24
+ METHODS = FacebookCommands.singleton_methods - ['method_missing']
25
+ Readline.completion_proc = proc {|s|
26
+ METHODS.grep(/^#{Regexp.escape(s)}/)
27
+ }
28
+
29
+ while line = Readline::readline('[FacebookCL] ', true)
30
+ args = Shellwords.shellwords(line)
31
+ FacebookCommands.send(args.shift, *args)
32
+ end
data/lib/facebookcl.rb ADDED
@@ -0,0 +1,98 @@
1
+ require 'rubygems'
2
+
3
+ require 'json'
4
+ require 'net/http'
5
+ require 'net/https'
6
+ require 'open-uri'
7
+ require 'socket'
8
+ require 'uri'
9
+
10
+ module FacebookCL; class << self
11
+ public
12
+
13
+ APP_ID = 119412046078
14
+ SERVER_PORT = 6682
15
+ GRAPH_URL = 'graph.facebook.com'
16
+ NEXT_URL = 'http://www.dev.facebook.com/connect/facebook_cl.php'
17
+
18
+ attr_accessor :uid
19
+
20
+ def authorize
21
+ if (File.exists?(config_filename))
22
+ puts "Loading authentication data from #{config_filename}"
23
+ data = JSON.parse(File.open(config_filename){|file| file.read})
24
+ self.access_token = data['access_token']
25
+ self.uid = data['uid']
26
+ else
27
+ auth_url = "https://#{GRAPH_URL}/oauth/authorize?client_id=#{APP_ID}&redirect_uri=#{NEXT_URL}&scope=publish_stream,create_event,offline_access,email,read_stream,read_mailbox"
28
+
29
+ if (RUBY_PLATFORM.downcase.include?("darwin"))
30
+ `open '#{auth_url}'`
31
+ else
32
+ puts %Q{
33
+ Welcome New User! You need to auth this application. So please visit here in your browser of choice:
34
+
35
+ #{auth_url}}
36
+ end
37
+
38
+ session = TCPServer.new('127.0.0.1', SERVER_PORT).accept
39
+ session.print "HTTP/1.1 200/OK\r\nContent-type:text/html\r\n\r\n"
40
+ request = session.gets.strip
41
+
42
+ session.print 'Success! ' +
43
+ 'You can close this window and return to FacebookCL now.'
44
+ session.close
45
+
46
+ self.access_token = request.
47
+ gsub(/^GET \/\?access_token=/, '').
48
+ gsub(/ HTTP.*$/, '')
49
+
50
+ self.uid = get('me')['id']
51
+
52
+ puts "Saving authentication data to #{config_filename}"
53
+ File.open(config_filename, 'w') { |file|
54
+ data = {'access_token' => access_token,
55
+ 'uid' => uid}
56
+ file.puts data.to_json
57
+ }
58
+
59
+ puts "Type 'help' for details."
60
+ end
61
+ end
62
+
63
+ def get(url, parameters = {})
64
+ url = "https://#{GRAPH_URL}/#{url}/?access_token=#{access_token}"
65
+ parameters.each {|key, value|
66
+ url += "&#{key}=#{value}"
67
+ }
68
+ data = JSON.parse(open(URI.parse(url)).read)
69
+ return data
70
+ end
71
+
72
+ def post(url, parameters = {})
73
+ parameters['access_token'] = access_token
74
+ http = Net::HTTP.new(GRAPH_URL, 443)
75
+ http.use_ssl = true
76
+ http.post("/#{url}",
77
+ parameters.map{|key, value|"#{key}=#{value}"}.join('&'))
78
+ end
79
+
80
+ private
81
+
82
+ attr_accessor :access_token
83
+
84
+ def config_filename
85
+ "#{ENV['HOME']}/.FacebookCL"
86
+ end
87
+
88
+ def prompt_value(prompt, error_message)
89
+ print prompt
90
+ value = gets.strip
91
+ if block_given? and not yield value
92
+ puts error_message
93
+ prompt_value(prompt, error_message)
94
+ else
95
+ value
96
+ end
97
+ end
98
+ end; end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Facebookcl" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'facebookcl'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: facebookcl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Justin Bishop
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-06-24 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.9
24
+ version:
25
+ description: ": longer description of your gem"
26
+ email: jubishop@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.markdown
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.markdown
39
+ - Rakefile
40
+ - VERSION
41
+ - commands/base.rb
42
+ - commands/help.rb
43
+ - commands/info.rb
44
+ - commands/picture.rb
45
+ - commands/stream.rb
46
+ - commands/wall.rb
47
+ - facebookcl.gemspec
48
+ - facebookcl.rb
49
+ - lib/facebookcl.rb
50
+ - spec/facebookcl_spec.rb
51
+ - spec/spec.opts
52
+ - spec/spec_helper.rb
53
+ has_rdoc: true
54
+ homepage: http://github.com/jubishop/facebookcl
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options:
59
+ - --charset=UTF-8
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ requirements: []
75
+
76
+ rubyforge_project:
77
+ rubygems_version: 1.3.5
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: ": one-line summary of your gem"
81
+ test_files:
82
+ - spec/facebookcl_spec.rb
83
+ - spec/spec_helper.rb