facebook-cli 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/fbcli.rb +79 -29
- data/lib/fbcli/facebook.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85e2fd8af22474966be9457355cc77a65c17d9a8
|
4
|
+
data.tar.gz: a2bef3fc01f49f721a2a35e8ea44130493a83cda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e4fb9deef5f748bb72d23f088bd1f8d2e1c8bb032709cb9c57717fb7bbe88339c3d0ca6e23ab950e7be74540799df3494559d07a6584778fa206da5be430329
|
7
|
+
data.tar.gz: 6a6dfbd622ada5a5627e00729ec08a0c315344bb34cf97985a2063c4df3a7b11ae67237e8da7f709e60fe9599296373758c425a0cd8fdc38a1e05a796a5196fa
|
data/lib/fbcli.rb
CHANGED
@@ -4,45 +4,84 @@ require 'fbcli/auth'
|
|
4
4
|
require 'fbcli/format'
|
5
5
|
require 'fbcli/facebook'
|
6
6
|
|
7
|
-
|
7
|
+
APP_NAME = File.split($0)[1]
|
8
|
+
CONFIG_FILE = File.join(ENV['HOME'], ".#{APP_NAME}rc")
|
8
9
|
|
9
10
|
include GLI::App
|
10
11
|
|
11
12
|
program_desc "Facebook command line interface"
|
12
13
|
|
13
|
-
version '1.
|
14
|
+
version '1.1.0'
|
14
15
|
|
15
16
|
flag [:token], :desc => 'Provide Facebook access token', :required => false
|
16
17
|
flag [:format], :desc => 'Output format (values: text, html)', :default_value => "text"
|
17
18
|
|
19
|
+
def print_header
|
20
|
+
if $format == 'html'
|
21
|
+
puts <<~EOM
|
22
|
+
<!doctype html>
|
23
|
+
<html lang=en>
|
24
|
+
<head>
|
25
|
+
<meta charset=utf-8>
|
26
|
+
</head>
|
27
|
+
<body>
|
28
|
+
EOM
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def print_footer
|
33
|
+
if $format == 'html'
|
34
|
+
puts <<~EOM
|
35
|
+
</body>
|
36
|
+
</html>
|
37
|
+
EOM
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
formattable_commands = [
|
42
|
+
:me,
|
43
|
+
:likes,
|
44
|
+
:feed,
|
45
|
+
:friends,
|
46
|
+
:photos,
|
47
|
+
:photosof
|
48
|
+
]
|
49
|
+
|
50
|
+
def save_config
|
51
|
+
File.open(CONFIG_FILE, 'w') do |f|
|
52
|
+
f.write $config.to_yaml
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
18
56
|
pre do |global_options,command|
|
19
|
-
|
57
|
+
if command.name == :config
|
58
|
+
$config = {}
|
59
|
+
else
|
60
|
+
begin
|
61
|
+
$config = YAML.load_file(CONFIG_FILE)
|
62
|
+
rescue
|
63
|
+
exit_now! <<~EOM
|
64
|
+
It looks like you are running #{APP_NAME} for the first time.
|
20
65
|
|
21
|
-
|
22
|
-
exit_now! <<~EOM
|
23
|
-
It looks like you are running #{$0} for the first time.
|
66
|
+
The following steps are necessary to use the Facebook API:
|
24
67
|
|
25
|
-
|
68
|
+
- Create a new application at: https://developers.facebook.com/apps
|
69
|
+
- In the Settings tab, add "localhost" to the App Domains
|
70
|
+
- Save the App ID and App Secret by running:
|
26
71
|
|
27
|
-
|
28
|
-
- In the Settings tab, add "localhost" to the App Domains
|
29
|
-
- Save the App ID and App Secret in "config.yml"
|
72
|
+
#{APP_NAME} config --appid=<app-id> --appsecret=<app-secret>
|
30
73
|
|
31
|
-
|
32
|
-
|
74
|
+
After that, acquire an access token by running:
|
75
|
+
|
76
|
+
#{APP_NAME} login
|
77
|
+
EOM
|
78
|
+
end
|
33
79
|
end
|
34
80
|
|
35
81
|
$format = global_options[:format]
|
36
82
|
|
37
|
-
if
|
38
|
-
|
39
|
-
<!doctype html>
|
40
|
-
<html lang=en>
|
41
|
-
<head>
|
42
|
-
<meta charset=utf-8>
|
43
|
-
</head>
|
44
|
-
<body>
|
45
|
-
EOM
|
83
|
+
if formattable_commands.include?(command.name)
|
84
|
+
print_header
|
46
85
|
end
|
47
86
|
|
48
87
|
# Success
|
@@ -50,11 +89,8 @@ pre do |global_options,command|
|
|
50
89
|
end
|
51
90
|
|
52
91
|
post do |global_options,command|
|
53
|
-
if
|
54
|
-
|
55
|
-
</body>
|
56
|
-
</html>
|
57
|
-
EOM
|
92
|
+
if formattable_commands.include?(command.name)
|
93
|
+
print_footer
|
58
94
|
end
|
59
95
|
end
|
60
96
|
|
@@ -65,6 +101,22 @@ on_error do |exception|
|
|
65
101
|
false
|
66
102
|
end
|
67
103
|
|
104
|
+
desc "Save Facebook application ID and secret"
|
105
|
+
command :config do |c|
|
106
|
+
c.flag [:appid], :desc => 'Facebook application ID'
|
107
|
+
c.flag [:appsecret], :desc => 'Facebook application secret'
|
108
|
+
c.action do |global_options,options,args|
|
109
|
+
$config['app_id'] = options['appid'].to_i
|
110
|
+
$config['app_secret'] = options['appsecret']
|
111
|
+
|
112
|
+
save_config
|
113
|
+
|
114
|
+
puts "Configuration saved to #{CONFIG_FILE}"
|
115
|
+
puts
|
116
|
+
puts "To acquire a Facebook access token, run: #{APP_NAME} login"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
68
120
|
desc "Log into Facebook and receive an access token"
|
69
121
|
command :login do |c|
|
70
122
|
c.flag [:port], :desc => 'Local TCP port to serve Facebook login redirect page', :default_value => '3333'
|
@@ -74,9 +126,7 @@ command :login do |c|
|
|
74
126
|
if not token.nil?
|
75
127
|
$config['access_token'] = token
|
76
128
|
|
77
|
-
|
78
|
-
f.write $config.to_yaml
|
79
|
-
end
|
129
|
+
save_config
|
80
130
|
|
81
131
|
puts "Your access token: #{token}"
|
82
132
|
puts
|
data/lib/fbcli/facebook.rb
CHANGED
@@ -2,12 +2,13 @@ require 'koala'
|
|
2
2
|
|
3
3
|
module FBCLI
|
4
4
|
def self.init_api(global_options)
|
5
|
+
# Access token passed from the command line takes precedence
|
5
6
|
if not global_options[:token].nil?
|
6
7
|
$config['access_token'] = global_options[:token]
|
7
8
|
end
|
8
9
|
|
9
10
|
if $config['access_token'].nil? or $config['access_token'].empty?
|
10
|
-
exit_now! "You must first acquire an access token; run: #{
|
11
|
+
exit_now! "You must first acquire an access token; run: #{APP_NAME} login"
|
11
12
|
end
|
12
13
|
|
13
14
|
Koala::Facebook::API.new($config['access_token'])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: facebook-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ildar Sagdejev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A limited command line interface to the Facebook Graph API
|
14
14
|
email: specious@gmail.com
|