facebook-cli 1.3.5 → 1.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fbcli.rb +15 -2
  3. data/lib/fbcli/facebook.rb +32 -6
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1966ca73a4bbf019fb0b165265f63c85542b5804
4
- data.tar.gz: 80c5aa0d1a796d8bd5a2d17ae3de588452235e85
3
+ metadata.gz: 222cdb626bb8d7571fefb3d44563150c1efd4307
4
+ data.tar.gz: 947dbe9be1dde3c13457e63da53e437c76c03d97
5
5
  SHA512:
6
- metadata.gz: 34f694fd22d302314e1dfe14f9963f36e31e6fe1a952befcee49d2eb55382aff5c24f6f43eb896c3c7c88e9968b245039df5ace4688fb1edfd752604fb87f2be
7
- data.tar.gz: 9c6939b9afb0397efb8432852d8048697cee7cb1fcf75b199990b1d237b6c97cc6909a7d042a5f5b613a1b5799248b987f2c359edfb068954cb10dba7d1e6ca8
6
+ metadata.gz: e7a77fbf6c34a09e2fbb3d7178505c8656d646dde49f13e2dae7faf5476ae883f59c505487e6fd7cffb8c9d5b010ede1534e5eecfeb5132120c806e41dfd0a50
7
+ data.tar.gz: 322e1f11ef30a0b856280a71b34b8e24d019c97c11e6ddee6e9de618dde65691b95eedf12a0f0e74aaa49b86740f0584fcd4da20fe88fb15dee39539c5a2408c
data/lib/fbcli.rb CHANGED
@@ -10,7 +10,7 @@ include GLI::App
10
10
 
11
11
  program_desc "Facebook command line interface"
12
12
 
13
- version '1.3.5'
13
+ version '1.3.7'
14
14
 
15
15
  flag [:token], :desc => 'Provide Facebook access token', :required => false
16
16
  flag [:pages, :p], :desc => 'Max pages', :required => false, :default_value => -1
@@ -19,6 +19,10 @@ def link(path)
19
19
  "https://www.facebook.com/#{path}"
20
20
  end
21
21
 
22
+ def link_to_post(profile_id, post_id)
23
+ link "#{profile_id}/posts/#{post_id}"
24
+ end
25
+
22
26
  # Facebook returns dates in ISO 8601 format
23
27
  def date_str(fb_date)
24
28
  Time.parse(fb_date).localtime.rfc2822
@@ -112,6 +116,15 @@ command :me do |c|
112
116
  end
113
117
  end
114
118
 
119
+ desc "Post to your timeline"
120
+ arg_name "message"
121
+ command :post do |c|
122
+ c.action do |global_options,options,args|
123
+ profile_id, post_id = FBCLI::write_post global_options, args[0]
124
+ puts "Your post: #{link_to_post profile_id, post_id}"
125
+ end
126
+ end
127
+
115
128
  desc "List the pages you have 'Liked'"
116
129
  command :likes do |c|
117
130
  c.action do |global_options,options,args|
@@ -145,7 +158,7 @@ command :feed do |c|
145
158
  profile_id, post_id = item["id"].split '_', 2
146
159
 
147
160
  puts item["message"] if item.has_key?("message")
148
- puts link "#{profile_id}/posts/#{post_id}"
161
+ puts link_to_post profile_id, post_id
149
162
  puts "Created: #{date_str(item["created_time"])}"
150
163
  end
151
164
  end
@@ -16,13 +16,28 @@ module FBCLI
16
16
  Koala::Facebook::API.new($config['access_token'])
17
17
  end
18
18
 
19
+ def self.koala_error_str(e)
20
+ str = "Koala #{e.fb_error_type}"
21
+ str << " (code #{e.fb_error_code.to_s +
22
+ (e.fb_error_subcode.nil? ? "" : ", subcode: " + e.fb_error_subcode.to_s)})"
23
+ str << " HTTP status: #{e.http_status}" unless e.http_status.nil?
24
+ str << "\n #{e.fb_error_user_msg.nil? ? e.fb_error_message : e.fb_error_user_msg}"
25
+ str << " (FB trace id: #{e.fb_error_trace_id})"
26
+
27
+ str
28
+ end
29
+
19
30
  def self.request_object(global_options, id, options = {})
20
31
  if @@api.nil?
21
32
  @@api = init_api(global_options)
22
33
  end
23
34
 
24
- @@api.get_object(id, options) do |data|
25
- yield data
35
+ begin
36
+ @@api.get_object(id, options) do |data|
37
+ yield data
38
+ end
39
+ rescue Koala::Facebook::APIError => e
40
+ exit_now! koala_error_str e
26
41
  end
27
42
  end
28
43
 
@@ -34,10 +49,7 @@ module FBCLI
34
49
  begin
35
50
  data = @@api.get_connections("me", cmd)
36
51
  rescue Koala::Facebook::APIError => e
37
- exit_now! \
38
- "Koala #{e.fb_error_type} (code #{e.fb_error_code})" +
39
- if not e.http_status.nil? then " HTTP status: #{e.http_status}" else "" end +
40
- "\n #{e.fb_error_message}"
52
+ exit_now! koala_error_str e
41
53
  end
42
54
 
43
55
  data
@@ -66,4 +78,18 @@ module FBCLI
66
78
  items = items.next_page
67
79
  end
68
80
  end
81
+
82
+ def self.write_post(global_options, msg)
83
+ if @@api.nil?
84
+ @@api = init_api(global_options)
85
+ end
86
+
87
+ begin
88
+ profile_id, post_id = @@api.put_wall_post(msg)['id'].split '_', 2
89
+ rescue Koala::Facebook::APIError => e
90
+ exit_now! koala_error_str e
91
+ end
92
+
93
+ [profile_id, post_id]
94
+ end
69
95
  end
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.5
4
+ version: 1.3.7
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-26 00:00:00.000000000 Z
11
+ date: 2016-09-27 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
@@ -41,7 +41,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
41
41
  version: '0'
42
42
  requirements: []
43
43
  rubyforge_project:
44
- rubygems_version: 2.5.1
44
+ rubygems_version: 2.6.6
45
45
  signing_key:
46
46
  specification_version: 4
47
47
  summary: Facebook command line utility