fbm 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +45 -0
- data/bin/fbm +110 -0
- data/fbm.gemspec +23 -0
- data/lib/fbm.rb +51 -0
- metadata +98 -0
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
|
2
|
+
fbm
|
3
|
+
===
|
4
|
+
|
5
|
+
Send Facebook Messages from your terminal.
|
6
|
+
|
7
|
+
|
8
|
+
Installation
|
9
|
+
------------
|
10
|
+
|
11
|
+
gem install fbm
|
12
|
+
|
13
|
+
|
14
|
+
Usage
|
15
|
+
-----
|
16
|
+
|
17
|
+
fbm login
|
18
|
+
|
19
|
+
It will give you a link, login and copy the success URL back to the application.
|
20
|
+
|
21
|
+
fbm ls Thai
|
22
|
+
|
23
|
+
It will list all friends that contains "Thai" in their name.
|
24
|
+
|
25
|
+
echo some text | fbm send Thai
|
26
|
+
|
27
|
+
It will send "some text" to Thai. If it matches multiple Thais, nothing will be sent, you must type the full name so that
|
28
|
+
it matches one name.
|
29
|
+
|
30
|
+
|
31
|
+
More Example
|
32
|
+
------------
|
33
|
+
|
34
|
+
Sending a code snippet to Gist using [Jist](https://github.com/ConradIrwin/jist) and send via Facebook.
|
35
|
+
|
36
|
+
jist filename.c | fbm send Recipient
|
37
|
+
|
38
|
+
|
39
|
+
Contribute
|
40
|
+
----------
|
41
|
+
This is my first Gem, and I'm very new to this. However, this app does just what I want now.
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|
data/bin/fbm
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'fbm'
|
4
|
+
require 'commander/import'
|
5
|
+
|
6
|
+
program :name, 'fbm'
|
7
|
+
program :version, '0.0.1'
|
8
|
+
program :description, 'Send Facebook Message'
|
9
|
+
|
10
|
+
fbm = Fbm.new
|
11
|
+
|
12
|
+
command :login do |c|
|
13
|
+
c.syntax = 'fbm login'
|
14
|
+
c.description = 'Login to Facebook'
|
15
|
+
c.action do |args, options|
|
16
|
+
puts "Please go to"
|
17
|
+
puts " #{fbm.login_url}"
|
18
|
+
puts ""
|
19
|
+
puts "When it says success, please paste the URL."
|
20
|
+
url = ask("Success URL: ")
|
21
|
+
raise "no access token found!" unless url =~ /access_token=([^&]+)/
|
22
|
+
fbm.access_token = token = $1
|
23
|
+
me = fbm.me
|
24
|
+
puts ""
|
25
|
+
puts "Hello, #{me['name']}."
|
26
|
+
File.open("#{ENV['HOME']}/.fbm_access_token", "w", 0600) do |f|
|
27
|
+
f << token
|
28
|
+
end
|
29
|
+
puts "To send message, use `fbm send [name]`"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
command :ls do |c|
|
34
|
+
c.syntax = 'fbm ls username'
|
35
|
+
c.description = 'Find friends matching list'
|
36
|
+
c.action do |args, options|
|
37
|
+
load_access_token(fbm)
|
38
|
+
list = filter_friends(fbm.friends, args)
|
39
|
+
print_friend_list(list)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
command :send do |c|
|
44
|
+
c.syntax = 'fbm send username'
|
45
|
+
c.description = 'Send facebook message'
|
46
|
+
c.option '--all'
|
47
|
+
c.action do |args, options|
|
48
|
+
begin
|
49
|
+
text = $stdin.read.strip
|
50
|
+
raise "empty message" if text.empty?
|
51
|
+
load_access_token(fbm)
|
52
|
+
list = filter_friends(fbm.friends, args)
|
53
|
+
if list.length == 0
|
54
|
+
puts "No matching users found"
|
55
|
+
elsif options.all || list.length == 1
|
56
|
+
puts "Sending message to:"
|
57
|
+
list.each do |friend|
|
58
|
+
print_friend friend
|
59
|
+
fbm.message friend['id'], text
|
60
|
+
end
|
61
|
+
fbm.close
|
62
|
+
else
|
63
|
+
puts "Multiple matching users found:"
|
64
|
+
print_friend_list(list)
|
65
|
+
puts ""
|
66
|
+
puts "Use --all to send them all."
|
67
|
+
end
|
68
|
+
rescue RestGraph::Error::InvalidAccessToken
|
69
|
+
puts "Access token is expired. Please run: `fbm login`."
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def load_access_token(fbm)
|
75
|
+
fbm.access_token = File.read("#{ENV['HOME']}/.fbm_access_token").strip
|
76
|
+
end
|
77
|
+
|
78
|
+
def filter_friends(array, args)
|
79
|
+
array = array.dup
|
80
|
+
args.each do |arg|
|
81
|
+
regex = Regexp.new(arg, Regexp::IGNORECASE)
|
82
|
+
array.select! do |friend|
|
83
|
+
friend['name'] && (friend['name'] =~ regex or (friend['username'] && friend['username'] =~ regex))
|
84
|
+
end
|
85
|
+
end
|
86
|
+
array
|
87
|
+
end
|
88
|
+
|
89
|
+
def print_friend_list(list)
|
90
|
+
list.each do |friend|
|
91
|
+
print_friend(friend)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def print_friend(friend)
|
96
|
+
username = if friend['username'].nil? || friend['username'].empty?
|
97
|
+
""
|
98
|
+
else
|
99
|
+
" (#{friend['username']})"
|
100
|
+
end
|
101
|
+
puts "- #{friend['name']}#{username}"
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
data/fbm.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "fbm"
|
3
|
+
s.version = "0.0.1"
|
4
|
+
s.platform = Gem::Platform::RUBY
|
5
|
+
s.authors = ["Thai Pangsakulyanont"]
|
6
|
+
s.email = ["org.yi.dttvb@gmail.com"]
|
7
|
+
s.homepage = "https://github.com/dtinth/fbm"
|
8
|
+
s.summary = "Facebook Messenger CLI"
|
9
|
+
s.description = "Send Facebook messages from the command line"
|
10
|
+
s.rubyforge_project = s.name
|
11
|
+
|
12
|
+
s.required_rubygems_version = ">= 1.3.6"
|
13
|
+
|
14
|
+
s.add_runtime_dependency "xmpp4r_facebook", ">= 0.1.1"
|
15
|
+
s.add_runtime_dependency "commander", ">= 4.1.3"
|
16
|
+
s.add_runtime_dependency "rest-graph", ">= 2.0.2"
|
17
|
+
|
18
|
+
# The list of files to be contained in the gem
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.executables = ["fbm"]
|
21
|
+
|
22
|
+
s.require_path = 'lib'
|
23
|
+
end
|
data/lib/fbm.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
|
2
|
+
require 'xmpp4r_facebook'
|
3
|
+
require 'rest-graph'
|
4
|
+
|
5
|
+
class Fbm
|
6
|
+
|
7
|
+
attr_writer :access_token
|
8
|
+
|
9
|
+
APP_ID = '336967703070590'
|
10
|
+
APP_SECRET = '96f23894a4fdb0d6366fc7066f651970'
|
11
|
+
|
12
|
+
def login_url
|
13
|
+
"https://www.facebook.com/dialog/oauth?client_id=#{APP_ID}" +
|
14
|
+
"&redirect_uri=https://www.facebook.com/connect/login_success.html" +
|
15
|
+
"&scope=xmpp_login,read_mailbox,friends_online_presence&response_type=token"
|
16
|
+
end
|
17
|
+
|
18
|
+
def me
|
19
|
+
@me ||= client.get('me', :fields => 'name')
|
20
|
+
end
|
21
|
+
|
22
|
+
def friends
|
23
|
+
client.get('me/friends', :fields => 'name,username')['data']
|
24
|
+
end
|
25
|
+
|
26
|
+
def message(id, text)
|
27
|
+
to = "-#{id}@chat.facebook.com"
|
28
|
+
message = Jabber::Message.new(to, text)
|
29
|
+
jabber.send(message)
|
30
|
+
end
|
31
|
+
|
32
|
+
def close
|
33
|
+
@jabber.close if @jabber
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def client
|
38
|
+
@client ||= RestGraph.new(:access_token => @access_token)
|
39
|
+
end
|
40
|
+
|
41
|
+
def jabber
|
42
|
+
@jid ||= "-#{me['id']}@chat.facebook.com"
|
43
|
+
@jabber ||= Jabber::Client.new(Jabber::JID.new(@jid))
|
44
|
+
@jabber.connect
|
45
|
+
@jabber.auth_sasl(Jabber::SASL::XFacebookPlatform.new(@jabber, APP_ID, @access_token, APP_SECRET), nil)
|
46
|
+
@jabber
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fbm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Thai Pangsakulyanont
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: xmpp4r_facebook
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.1.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.1.1
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: commander
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 4.1.3
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 4.1.3
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rest-graph
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.0.2
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.0.2
|
62
|
+
description: Send Facebook messages from the command line
|
63
|
+
email:
|
64
|
+
- org.yi.dttvb@gmail.com
|
65
|
+
executables:
|
66
|
+
- fbm
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- README.md
|
71
|
+
- bin/fbm
|
72
|
+
- fbm.gemspec
|
73
|
+
- lib/fbm.rb
|
74
|
+
homepage: https://github.com/dtinth/fbm
|
75
|
+
licenses: []
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: 1.3.6
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project: fbm
|
94
|
+
rubygems_version: 1.8.24
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: Facebook Messenger CLI
|
98
|
+
test_files: []
|