facebook-cli 1.3.0 → 1.3.3

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fbcli.rb +66 -17
  3. data/lib/fbcli/facebook.rb +28 -8
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 913ff712708e17df232c742939c4cc18cea5c778
4
- data.tar.gz: c64f49dcae20930df01d415358ffc68fd6d1d184
3
+ metadata.gz: 680c68383186dc7064cdfe6947e825a4d91803ec
4
+ data.tar.gz: 121ab05a54b57245edd58cae227ef84ecdee9a4e
5
5
  SHA512:
6
- metadata.gz: ba53901c3d6b794d415c0204b51549da1a6dce324c0318d4a739def77eec36bdf644416888d330737a94bb7778988152094c5baf1fd5489bb747313ce7258dff
7
- data.tar.gz: 487076f9c7d7cd4093ca288723ab544dfcaf6f8ddcd9ba70c413f16ed7cf65976c472baf6cee9360c7edc525f867c769cc160b25151a5e89a2fe10db86430bc8
6
+ metadata.gz: d9d9855b3a79ae2bb72f2476536a038b16bfdd26c959c08c8c7e28e25ba070491673ceb1c78123fdb74e23980fd039c32072d1be16e447a626c393e5611927ba
7
+ data.tar.gz: f3929fde6a2f3889d1ff5c5ce10cdd4de975a319ef9eac75faeac8af65730a8d49f94825a29482a95431e9ee2f1b5d1d06815e35eb288e1bce5c7b893bf30248
@@ -10,7 +10,7 @@ include GLI::App
10
10
 
11
11
  program_desc "Facebook command line interface"
12
12
 
13
- version '1.3.0'
13
+ version '1.3.3'
14
14
 
15
15
  flag [:token], :desc => 'Provide Facebook access token', :required => false
16
16
 
@@ -172,26 +172,27 @@ end
172
172
  def list_events(global_options, past = false)
173
173
  now = Time.new
174
174
 
175
- FBCLI::page_items global_options, "events", "\n- - -\n\n" do |item|
175
+ filter = lambda { |item|
176
176
  starts = Time.parse(item['start_time'])
177
+ not ((past and starts < now) ^ (not past and starts > now))
178
+ }
177
179
 
178
- if (past and starts < now) ^ (not past and starts > now)
179
- unless item['end_time'].nil?
180
- ends = Time.parse(item['end_time'])
181
- duration = ends - starts
182
- end
180
+ FBCLI::page_items global_options, "events", '- - -', filter do |item|
181
+ starts = Time.parse(item['start_time'])
183
182
 
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']
183
+ unless item['end_time'].nil?
184
+ ends = Time.parse(item['end_time'])
185
+ duration = ends - starts
194
186
  end
187
+
188
+ puts "#{item['name']} (#{item['id']})"
189
+ puts
190
+ puts "Location: #{item['place']['name']}" unless item['place'].nil?
191
+ puts "Date: #{date_str(item['start_time'])}"
192
+ puts "Duration: #{duration / 3600} hours" if defined?(duration) and not duration.nil?
193
+ puts "RSVP: #{item['rsvp_status'].sub(/unsure/, 'maybe')}"
194
+ puts
195
+ puts link "events/#{item['id']}"
195
196
  end
196
197
  end
197
198
 
@@ -209,4 +210,52 @@ command :pastevents do |c|
209
210
  end
210
211
  end
211
212
 
213
+ desc "Show event details"
214
+ arg_name "[ids...]"
215
+ command :event do |c|
216
+ c.action do |global_options,options,args|
217
+ args.each_with_index do |id, index|
218
+ FBCLI::request_object(
219
+ global_options,
220
+ id,
221
+ :fields => 'name,description,place,owner,start_time,end_time,attending_count,interested_count,declined_count,maybe_count,is_canceled'
222
+ ) do |item|
223
+ starts = Time.parse(item['start_time'])
224
+
225
+ unless item['end_time'].nil?
226
+ ends = Time.parse(item['end_time'])
227
+ duration = ends - starts
228
+ end
229
+
230
+ puts "#{item['name']} (#{item['id']})"
231
+
232
+ if item['is_canceled']
233
+ puts "CANCELED"
234
+ puts
235
+ end
236
+
237
+ puts
238
+ puts "Location: #{item['place']['name']}" unless item['place'].nil?
239
+ puts "Date: #{date_str(item['start_time'])}"
240
+ puts "Duration: #{duration / 3600} hours" if defined?(duration) and not duration.nil?
241
+ puts "Created by: #{item['owner']['name']}"
242
+ puts
243
+ puts "Attending: #{item['attending_count']}"
244
+ puts "Interested: #{item['interested_count']}"
245
+ puts "Maybe: #{item['maybe_count']}"
246
+ puts "Declined: #{item['declined_count']}"
247
+ puts
248
+ puts link "events/#{item['id']}"
249
+
250
+ if not item['description'].empty?
251
+ puts
252
+ puts item['description']
253
+ end
254
+
255
+ puts "- - -" unless index == args.size - 1
256
+ end
257
+ end
258
+ end
259
+ end
260
+
212
261
  exit run(ARGV)
@@ -1,6 +1,8 @@
1
1
  require 'koala'
2
2
 
3
3
  module FBCLI
4
+ @@api = nil
5
+
4
6
  def self.init_api(global_options)
5
7
  # Access token passed from the command line takes precedence
6
8
  if not global_options[:token].nil?
@@ -14,11 +16,23 @@ module FBCLI
14
16
  Koala::Facebook::API.new($config['access_token'])
15
17
  end
16
18
 
17
- def self.request_data(global_options, cmd)
18
- api = init_api(global_options)
19
+ def self.request_object(global_options, id, options = {})
20
+ if @@api.nil?
21
+ @@api = init_api(global_options)
22
+ end
23
+
24
+ @@api.get_object(id, options) do |data|
25
+ yield data
26
+ end
27
+ end
28
+
29
+ def self.request_personal_connections(global_options, cmd)
30
+ if @@api.nil?
31
+ @@api = init_api(global_options)
32
+ end
19
33
 
20
34
  begin
21
- data = api.get_connections("me", cmd)
35
+ data = @@api.get_connections("me", cmd)
22
36
  rescue Koala::Facebook::APIError => e
23
37
  exit_now! \
24
38
  "Koala #{e.fb_error_type} (code #{e.fb_error_code})" +
@@ -29,15 +43,21 @@ module FBCLI
29
43
  data
30
44
  end
31
45
 
32
- def self.page_items(global_options, cmd, separator = nil)
33
- items = request_data(global_options, cmd)
46
+ def self.page_items(global_options, cmd, separator = nil, filter = nil)
47
+ items = request_personal_connections(global_options, cmd)
48
+
49
+ virgin = true
34
50
 
35
51
  while not items.nil? do
36
52
  items.each_with_index { |item, idx|
37
- yield item
53
+ if filter.nil? or not filter.call(item)
54
+ unless separator.nil? or virgin
55
+ puts separator
56
+ end
57
+
58
+ yield item
38
59
 
39
- unless separator.nil? or idx == items.size - 1
40
- puts separator
60
+ virgin = false
41
61
  end
42
62
  }
43
63
 
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.3.0
4
+ version: 1.3.3
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-23 00:00:00.000000000 Z
11
+ date: 2016-09-24 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