facebook-cli 1.4.3 → 1.4.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fbcli.rb +46 -26
- data/lib/fbcli/auth.rb +1 -7
- data/lib/fbcli/facebook.rb +8 -0
- data/lib/fbcli/version.rb +3 -0
- metadata +47 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60c619d0469bcc50c00c8a968131e0609150ccf8
|
4
|
+
data.tar.gz: e710d5ec2df9539a36a72a6d07565110a9df222b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6115894a6a4f6a7c7288ad6bfbb1b8d04cea11d51fe9be61365f71f2cdd45ebd98a04814ba42758a365ed1054d2320f656b122bc747f0a9b6c474f0878fb2e1b
|
7
|
+
data.tar.gz: 1eea4da386c871b6885e110c82896235bc2e87d46895d5abd2f45bd1871fdf126e94180621d13584b520a8a37a9f395a5b7c98f09b091f58ad0df9fa40fb8480
|
data/lib/fbcli.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
require 'gli'
|
2
2
|
require 'yaml'
|
3
3
|
require 'fbcli/auth'
|
4
|
+
require 'fbcli/version'
|
4
5
|
require 'fbcli/facebook'
|
5
6
|
|
6
|
-
APP_NAME
|
7
|
+
APP_NAME = File.basename($0, File.extname($0))
|
7
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
|
14
|
+
version FBCLI::VERSION
|
14
15
|
|
15
16
|
flag [:token], :desc => 'Provide Facebook access token', :required => false
|
16
17
|
flag [:pages, :p], :desc => 'Max pages', :required => false, :type => Integer, :default_value => -1
|
@@ -24,10 +25,12 @@ def link_to_post(full_post_id)
|
|
24
25
|
link "#{profile_id}/posts/#{post_id}"
|
25
26
|
end
|
26
27
|
|
27
|
-
# Facebook returns dates in ISO 8601
|
28
|
-
def date_str(
|
28
|
+
# Facebook returns dates in ISO 8601 or unix timestamp format
|
29
|
+
def date_str(date)
|
30
|
+
t = (date.is_a? Integer) ? Time.at(date) : Time.parse(date).localtime
|
31
|
+
|
29
32
|
# Convert to human friendly representation in user's time zone (almost RFC 2822)
|
30
|
-
|
33
|
+
t.strftime('%a, %-d %b %Y %H:%M:%S %Z')
|
31
34
|
end
|
32
35
|
|
33
36
|
def save_config
|
@@ -48,23 +51,23 @@ pre do |global_options, command|
|
|
48
51
|
begin
|
49
52
|
$config = YAML.load_file(CONFIG_FILE)
|
50
53
|
rescue
|
51
|
-
exit_now!
|
52
|
-
|
54
|
+
exit_now! <<-EOM
|
55
|
+
It looks like you are running #{APP_NAME} for the first time.
|
53
56
|
|
54
|
-
|
57
|
+
The following steps are necessary to use the Facebook API:
|
55
58
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
- Create a new application at: https://developers.facebook.com/apps
|
60
|
+
- In the Settings tab, set "Site URL" to "http://localhost" and
|
61
|
+
then under "App Domains" add "localhost", and click "Save"
|
62
|
+
- In the "App Review" tab, flip the switch to make your app live.
|
63
|
+
- Save the App ID and App Secret by running:
|
61
64
|
|
62
|
-
|
65
|
+
#{APP_NAME} config --appid=<app-id> --appsecret=<app-secret>
|
63
66
|
|
64
|
-
|
67
|
+
After that, acquire an access token by running:
|
65
68
|
|
66
|
-
|
67
|
-
|
69
|
+
#{APP_NAME} login
|
70
|
+
EOM
|
68
71
|
end
|
69
72
|
end
|
70
73
|
|
@@ -103,19 +106,36 @@ end
|
|
103
106
|
desc "Log into Facebook and receive an access token"
|
104
107
|
command :login do |c|
|
105
108
|
c.flag [:port], :desc => 'Local TCP port to serve Facebook login redirect page', :default_value => '3333'
|
109
|
+
c.switch [:info], :desc => 'Show information about the current access token and exit', :negatable => false
|
106
110
|
c.action do |global_options, options|
|
107
|
-
|
111
|
+
if options['info']
|
112
|
+
begin
|
113
|
+
FBCLI::request_token_info do |data|
|
114
|
+
puts "Your access token was issued on: #{date_str(data['issued_at'])}"
|
115
|
+
puts
|
116
|
+
puts "It is valid until: #{date_str(data['expires_at'])}"
|
117
|
+
puts
|
118
|
+
puts "Permissions:\n - #{data['scopes'].join("\n - ")}"
|
119
|
+
end
|
120
|
+
rescue
|
121
|
+
puts "Your access token does not appear to be valid for this application."
|
122
|
+
end
|
123
|
+
else
|
124
|
+
token = FBCLI::listen_for_auth_code(options['port'], $config['app_id'], $config['app_secret'])
|
108
125
|
|
109
|
-
|
110
|
-
|
126
|
+
if not token.nil?
|
127
|
+
$config['access_token'] = token
|
111
128
|
|
112
|
-
|
129
|
+
save_config
|
113
130
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
131
|
+
puts "Your access token: #{token}"
|
132
|
+
puts
|
133
|
+
puts "To find out when it is scheduled to expire, run:"
|
134
|
+
puts
|
135
|
+
puts " #{APP_NAME} login --info"
|
136
|
+
puts
|
137
|
+
puts "Have fun!"
|
138
|
+
end
|
119
139
|
end
|
120
140
|
end
|
121
141
|
end
|
data/lib/fbcli/auth.rb
CHANGED
@@ -59,12 +59,6 @@ module FBCLI
|
|
59
59
|
res = Net::HTTP.get_response(URI.parse(auth_uri))
|
60
60
|
res = JSON.parse(res.body)
|
61
61
|
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
def self.expiration_str(seconds)
|
66
|
-
h, m = seconds.divmod(60 * 3600)
|
67
|
-
|
68
|
-
"#{h} hours and #{m.div 3600} minutes"
|
62
|
+
res["access_token"]
|
69
63
|
end
|
70
64
|
end
|
data/lib/fbcli/facebook.rb
CHANGED
@@ -36,6 +36,14 @@ module FBCLI
|
|
36
36
|
api_call lambda { |api| api.delete_object("me/permissions") }
|
37
37
|
end
|
38
38
|
|
39
|
+
def self.request_token_info
|
40
|
+
api_call lambda { |api|
|
41
|
+
api.debug_token $config['access_token'] do |res|
|
42
|
+
yield res['data']
|
43
|
+
end
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
39
47
|
def self.request_object(id, options = {})
|
40
48
|
api_call lambda { |api|
|
41
49
|
api.get_object(id, options) do |data|
|
metadata
CHANGED
@@ -1,15 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: facebook-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.9
|
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-10-
|
12
|
-
dependencies:
|
11
|
+
date: 2016-10-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: koala
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: gli
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.14'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.14'
|
13
55
|
description: A limited command line interface to Facebook
|
14
56
|
email: specious@gmail.com
|
15
57
|
executables:
|
@@ -21,6 +63,7 @@ files:
|
|
21
63
|
- lib/fbcli.rb
|
22
64
|
- lib/fbcli/auth.rb
|
23
65
|
- lib/fbcli/facebook.rb
|
66
|
+
- lib/fbcli/version.rb
|
24
67
|
homepage: https://github.com/specious/facebook-cli
|
25
68
|
licenses:
|
26
69
|
- MIT
|
@@ -33,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
33
76
|
requirements:
|
34
77
|
- - ">="
|
35
78
|
- !ruby/object:Gem::Version
|
36
|
-
version: '
|
79
|
+
version: '0'
|
37
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
81
|
requirements:
|
39
82
|
- - ">="
|