Skip to content

Commit 1bc7545

Browse files
committed
Add multiple profiles feature to CLI
Feature request: came in through Twitter Added support so that user can supply a BUFFER_PROFILE_ID="0,1" and the CLI will parse that out into an Int[0,1], so that we can use it for the profile_ids field in post_args.
1 parent 180ce71 commit 1bc7545

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

bin/buffer

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,29 @@ def gather_message(argv)
1717
end
1818
end
1919

20+
def parse_profile_ids(env = ENV)
21+
profile = ENV.fetch('BUFFER_PROFILE_ID', "0")
22+
profiles = if profile.include?(",")
23+
profile.split(",")
24+
else
25+
Array(profile)
26+
end
27+
profiles.map { |i| Integer(i) }
28+
end
29+
2030
def main
2131
token = Env.BUFFER_ACCESS_TOKEN
22-
profile = Integer(ENV.fetch('BUFFER_PROFILE_ID', "0"))
23-
2432
message = gather_message(ARGV)
2533
client = Buffer::Client.new(token)
26-
profile_id = client.profiles[profile].id
27-
post_args = {text: message, profile_ids: [profile_id]}
34+
all_profiles = client.profiles
35+
desired_profiles = parse_profile_ids.map do |i|
36+
begin
37+
all_profiles[i]["_id"]
38+
rescue
39+
abort("ERROR: Unable to find all the requested profiles. Profile Index #{i} was the issue.")
40+
end
41+
end
42+
post_args = {text: message, profile_ids: desired_profiles}
2843
LOG.info('#main.post_args') { post_args }
2944
unless ENV['BUFFER_DEBUG']
3045
client.create_update(body: post_args)

0 commit comments

Comments
 (0)