facebook-cli 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b43e88b0462f22b153e6b31aa3f14ab6e3129aab
4
- data.tar.gz: 3b39f775a897e4e5c9ab3cb7bb0310ddbcd28092
3
+ metadata.gz: 913ff712708e17df232c742939c4cc18cea5c778
4
+ data.tar.gz: c64f49dcae20930df01d415358ffc68fd6d1d184
5
5
  SHA512:
6
- metadata.gz: 8730da7429b2dcb7c57677bb450083430fbac028962cc042ff0be74031dd9eaf7f6d075918d231be046ad6f7368a8cd77313f35cf3c4d6fb87deb726a30c9570
7
- data.tar.gz: 4149d6345806ee902dfb37947f485a80bd7d1c50a548d02fc0d1e542de14b93f93b75c58e568d2836a2e829868b1f3d183b3f178269dcac21b9d1802e4739cbe
6
+ metadata.gz: ba53901c3d6b794d415c0204b51549da1a6dce324c0318d4a739def77eec36bdf644416888d330737a94bb7778988152094c5baf1fd5489bb747313ce7258dff
7
+ data.tar.gz: 487076f9c7d7cd4093ca288723ab544dfcaf6f8ddcd9ba70c413f16ed7cf65976c472baf6cee9360c7edc525f867c769cc160b25151a5e89a2fe10db86430bc8
data/lib/fbcli.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require 'gli'
2
2
  require 'yaml'
3
3
  require 'fbcli/auth'
4
- require 'fbcli/format'
5
4
  require 'fbcli/facebook'
6
5
 
7
6
  APP_NAME = File.split($0)[1]
@@ -11,43 +10,18 @@ include GLI::App
11
10
 
12
11
  program_desc "Facebook command line interface"
13
12
 
14
- version '1.2.0'
13
+ version '1.3.0'
15
14
 
16
15
  flag [:token], :desc => 'Provide Facebook access token', :required => false
17
- flag [:format], :desc => 'Output format (values: text, html)', :default_value => "text"
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
16
 
32
- def print_footer
33
- if $format == 'html'
34
- puts <<~EOM
35
- </body>
36
- </html>
37
- EOM
38
- end
17
+ def link(path)
18
+ "https://www.facebook.com/#{path}"
39
19
  end
40
20
 
41
- formattable_commands = [
42
- :me,
43
- :likes,
44
- :feed,
45
- :friends,
46
- :photos,
47
- :photosof,
48
- :events,
49
- :pastevents
50
- ]
21
+ # Facebook returns dates in ISO 8601 format
22
+ def date_str(fb_date)
23
+ Time.parse(fb_date).localtime.rfc2822
24
+ end
51
25
 
52
26
  def save_config
53
27
  File.open(CONFIG_FILE, 'w') do |f|
@@ -80,22 +54,10 @@ pre do |global_options,command|
80
54
  end
81
55
  end
82
56
 
83
- $format = global_options[:format]
84
-
85
- if formattable_commands.include?(command.name)
86
- print_header
87
- end
88
-
89
57
  # Success
90
58
  true
91
59
  end
92
60
 
93
- post do |global_options,command|
94
- if formattable_commands.include?(command.name)
95
- print_footer
96
- end
97
- end
98
-
99
61
  on_error do |exception|
100
62
  puts exception.message
101
63
 
@@ -105,8 +67,8 @@ end
105
67
 
106
68
  desc "Save Facebook application ID and secret"
107
69
  command :config do |c|
108
- c.flag [:appid], :desc => 'Facebook application ID'
109
- c.flag [:appsecret], :desc => 'Facebook application secret'
70
+ c.flag [:appid], :desc => 'Facebook application ID', :required => true
71
+ c.flag [:appsecret], :desc => 'Facebook application secret', :required => true
110
72
  c.action do |global_options,options,args|
111
73
  $config['app_id'] = options['appid'].to_i
112
74
  $config['app_secret'] = options['appsecret']
@@ -143,18 +105,17 @@ desc "Show your name and profile ID"
143
105
  command :me do |c|
144
106
  c.action do |global_options,options,args|
145
107
  data = FBCLI::request_data global_options, ""
146
- FBCLI::write "Name: #{data["name"]}"
147
- FBCLI::write "Your profile ID: #{data["id"]}"
108
+ puts "Name: #{data["name"]}"
109
+ puts "Your profile ID: #{data["id"]}"
148
110
  end
149
111
  end
150
112
 
151
113
  desc "List the pages you have 'Liked'"
152
114
  command :likes do |c|
153
115
  c.action do |global_options,options,args|
154
- FBCLI::page_items global_options, "likes" do |item|
155
- FBCLI::write item["name"]
156
- FBCLI::write FBCLI::link item["id"]
157
- FBCLI::write
116
+ FBCLI::page_items global_options, 'likes', '' do |item|
117
+ puts item["name"]
118
+ puts link item["id"]
158
119
  end
159
120
  end
160
121
  end
@@ -169,8 +130,8 @@ long_desc <<~EOM
169
130
  EOM
170
131
  command :friends do |c|
171
132
  c.action do |global_options,options,args|
172
- FBCLI::page_items global_options, "invitable_friends" do |item|
173
- FBCLI::write item["name"]
133
+ FBCLI::page_items global_options, 'invitable_friends' do |item|
134
+ puts item['name']
174
135
  end
175
136
  end
176
137
  end
@@ -178,42 +139,40 @@ end
178
139
  desc "List the posts on your profile"
179
140
  command :feed do |c|
180
141
  c.action do |global_options,options,args|
181
- FBCLI::page_items global_options, "feed" do |item|
142
+ FBCLI::page_items global_options, "feed", '- - -' do |item|
182
143
  profile_id, post_id = item["id"].split '_', 2
183
144
 
184
- FBCLI::write item["message"] if item.has_key?("message")
185
- FBCLI::write FBCLI::link "#{profile_id}/posts/#{post_id}"
186
- FBCLI::write "Created: #{FBCLI::date(item["created_time"])}"
187
- FBCLI::write "--"
145
+ puts item["message"] if item.has_key?("message")
146
+ puts link "#{profile_id}/posts/#{post_id}"
147
+ puts "Created: #{date_str(item["created_time"])}"
188
148
  end
189
149
  end
190
150
  end
191
151
 
192
152
  consumePhoto = Proc.new do |item|
193
- FBCLI::write item["name"] unless not item.key?("name")
194
- FBCLI::write FBCLI::link "#{item["id"]}"
195
- FBCLI::write "Created: #{FBCLI::date(item["created_time"])}"
196
- FBCLI::write "--"
153
+ puts item["name"] unless not item.key?("name")
154
+ puts link "#{item["id"]}"
155
+ puts "Created: #{date_str(item["created_time"])}"
197
156
  end
198
157
 
199
158
  desc "List photos you have uploaded"
200
159
  command :photos do |c|
201
160
  c.action do |global_options,options,args|
202
- FBCLI::page_items global_options, "photos?type=uploaded", &consumePhoto
161
+ FBCLI::page_items global_options, "photos?type=uploaded", '- - -', &consumePhoto
203
162
  end
204
163
  end
205
164
 
206
165
  desc "List photos you are tagged in"
207
166
  command :photosof do |c|
208
167
  c.action do |global_options,options,args|
209
- FBCLI::page_items global_options, "photos", &consumePhoto
168
+ FBCLI::page_items global_options, "photos", '- - -', &consumePhoto
210
169
  end
211
170
  end
212
171
 
213
172
  def list_events(global_options, past = false)
214
173
  now = Time.new
215
174
 
216
- FBCLI::page_items global_options, "events" do |item|
175
+ FBCLI::page_items global_options, "events", "\n- - -\n\n" do |item|
217
176
  starts = Time.parse(item['start_time'])
218
177
 
219
178
  if (past and starts < now) ^ (not past and starts > now)
@@ -222,17 +181,16 @@ def list_events(global_options, past = false)
222
181
  duration = ends - starts
223
182
  end
224
183
 
225
- FBCLI::write "#{item['name']} (#{item['id']})"
226
- FBCLI::write
227
- FBCLI::write "Location: #{item['place']['name']}" unless item['place'].nil?
228
- FBCLI::write "Date: #{FBCLI::date(item['start_time'])}"
229
- FBCLI::write "Duration: #{duration / 3600} hours" if defined?(duration) and not duration.nil?
230
- FBCLI::write "RSVP: #{item['rsvp_status'].sub(/unsure/, "maybe")}"
231
- FBCLI::write
232
- FBCLI::write FBCLI::link "events/#{item['id']}"
233
- FBCLI::write
234
- FBCLI::write item['description']
235
- FBCLI::write "---------------------------------"
184
+ puts "#{item['name']} (#{item['id']})"
185
+ puts
186
+ puts "Location: #{item['place']['name']}" unless item['place'].nil?
187
+ puts "Date: #{date_str(item['start_time'])}"
188
+ puts "Duration: #{duration / 3600} hours" if defined?(duration) and not duration.nil?
189
+ puts "RSVP: #{item['rsvp_status'].sub(/unsure/, 'maybe')}"
190
+ puts
191
+ puts link "events/#{item['id']}"
192
+ puts
193
+ puts item['description']
236
194
  end
237
195
  end
238
196
  end
@@ -29,12 +29,16 @@ module FBCLI
29
29
  data
30
30
  end
31
31
 
32
- def self.page_items(global_options, cmd)
32
+ def self.page_items(global_options, cmd, separator = nil)
33
33
  items = request_data(global_options, cmd)
34
34
 
35
35
  while not items.nil? do
36
- items.each { |item|
36
+ items.each_with_index { |item, idx|
37
37
  yield item
38
+
39
+ unless separator.nil? or idx == items.size - 1
40
+ puts separator
41
+ end
38
42
  }
39
43
 
40
44
  items = items.next_page
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.2.0
4
+ version: 1.3.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-22 00:00:00.000000000 Z
11
+ date: 2016-09-23 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
@@ -21,7 +21,6 @@ files:
21
21
  - lib/fbcli.rb
22
22
  - lib/fbcli/auth.rb
23
23
  - lib/fbcli/facebook.rb
24
- - lib/fbcli/format.rb
25
24
  homepage: https://github.com/specious/facebook-cli
26
25
  licenses:
27
26
  - MIT
data/lib/fbcli/format.rb DELETED
@@ -1,27 +0,0 @@
1
- module FBCLI
2
- # Facebook returns dates in ISO 8601 format
3
- def self.date(fb_date)
4
- Time.parse(fb_date).localtime.rfc2822
5
- end
6
-
7
- def self.link(path, format = $format)
8
- url = "https://www.facebook.com/#{path}"
9
-
10
- case format
11
- when "html"
12
- "<a href=\"#{url}\">#{url}</a>"
13
- else
14
- url
15
- end
16
- end
17
-
18
- def self.write(str = "", format = $format)
19
- str = "" if str.nil?
20
-
21
- if format == "html"
22
- str = " " + str + "<br>"
23
- end
24
-
25
- puts str.encode('utf-8')
26
- end
27
- end