forked from bufferapp/buffer-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffer
More file actions
executable file
·50 lines (43 loc) · 1.17 KB
/
buffer
File metadata and controls
executable file
·50 lines (43 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env ruby
require 'buffer'
require 'logger'
log_level = ENV['BUFFER_DEBUG'] ? Logger::INFO : Logger::ERROR
LOG = Logger.new(STDOUT) { |l| l.log_level = log_level }
def gather_message(argv)
args = argv.dup
case args.count
when 0 then abort("Please supply a message for Buffer Post.")
when 1 then args.first
else
args.join(" ")
end
end
def parse_profile_ids(env = ENV)
profile = ENV.fetch('BUFFER_PROFILE_ID', "0")
profiles = if profile.include?(",")
profile.split(",")
else
Array(profile)
end
profiles.map { |i| Integer(i) }
end
def main
token = Env.BUFFER_ACCESS_TOKEN
message = gather_message(ARGV)
client = Buffer::Client.new(token)
all_profiles = client.profiles
desired_profiles = parse_profile_ids.map do |i|
begin
all_profiles[i]["_id"]
rescue
abort("ERROR: Unable to find all the requested profiles. Profile Index #{i} was the issue.")
end
end
post_args = {text: message, profile_ids: desired_profiles}
LOG.info('#main.post_args') { post_args }
unless ENV['BUFFER_DEBUG']
client.create_update(body: post_args)
puts "Posted message."
end
end
main