Skip to content
This repository was archived by the owner on Mar 5, 2026. It is now read-only.

Commit b7db989

Browse files
committed
Fixes bin/buffer and updates conventions
Buffer's Ruby Client was written by a less experienced me. Changes: - Fixes issue with ARGF usage pointed out by @boscomonkey in #4. No, there was never an ARGF that allowed #chomp. Whoops ¯\_(ツ)_/¯! - Switches from YAML file to more 12-factor app configuration (ie ENV variables). Thurs `~/.bufferapprc` is no more, and `BUFFER_ACCESS_TOKEN` and `BUFFER_PROFILE_ID` must be set in environment. - Refactors code based on cleaner style.
1 parent 2214e22 commit b7db989

4 files changed

Lines changed: 29 additions & 23 deletions

File tree

.ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ruby-2.0.0-p195
1+
2.1.5

bin/buffer

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
11
#!/usr/bin/env ruby
22

3-
$LOAD_PATH.unshift(File.dirname(__FILE__), '..', 'lib')
4-
53
require 'buffer'
4+
require 'logger'
65

7-
begin
8-
require 'yaml'
6+
log_level = ENV['BUFFER_DEBUG'] ? Logger::INFO : Logger::ERROR
97

10-
rc_file_path = File.expand_path('~/.bufferapprc')
11-
raise Errno::ENOENT unless File.exists?(rc_file_path)
8+
LOG = Logger.new(STDOUT) { |l| l.log_level = log_level }
129

13-
options = YAML.load_file(File.expand_path('~/.bufferapprc'))
14-
if options.class == String
15-
options_str = options.dup
16-
options = Hash.new
17-
options['access_token'], options['profile_index'] = options_str.split
18-
options['verion'] = '0.0.0'
10+
def gather_message(argv)
11+
args = argv.dup
12+
case args.count
13+
when 0 then abort("Please supply a message for Buffer Post.")
14+
when 1 then args.first
15+
else
16+
args.join(" ")
1917
end
20-
rescue Errno::ENOENT
21-
puts "You're missing the ~/.bufferapprc file. See the README for info."
22-
exit 1
23-
rescue
24-
puts "Please upgrade from older config file structure" if ENV['BUFF_DEBUG']
2518
end
2619

27-
client = Buffer::Client.new(options['access_token'])
28-
id = client.profiles[options['profile_index'].to_i].id
20+
def main
21+
token = Env.BUFFER_ACCESS_TOKEN
22+
profile = Integer(Env.BUFFER_PROFILE_ID)
23+
24+
message = gather_message(ARGV)
25+
client = Buffer::Client.new(token)
26+
profile_id = client.profiles[profile].id
27+
post_args = {text: message, profile_ids: [profile_id]}
28+
LOG.info('#main.post_args') { post_args }
29+
unless ENV['BUFFER_DEBUG']
30+
client.create_update(body: post_args)
31+
puts "Posted message."
32+
end
33+
end
2934

30-
response = client.create_update(body: {text: ARGF.chomp, profile_ids: [ id ] } )
31-
puts response if ENV['BUFF_DEBUG']
35+
main

buffer.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Gem::Specification.new do |gem|
2323
gem.add_development_dependency 'guard-bundler'
2424
gem.add_development_dependency 'rb-fsevent'
2525
gem.add_development_dependency 'growl'
26-
gem.add_development_dependency 'pry-full'
26+
gem.add_development_dependency 'pry-uber'
2727

2828
gem.add_runtime_dependency 'multi_json'
2929
gem.add_runtime_dependency 'yajl-ruby'
@@ -32,4 +32,5 @@ Gem::Specification.new do |gem|
3232
gem.add_runtime_dependency 'hashie'
3333
gem.add_runtime_dependency 'rake'
3434
gem.add_runtime_dependency 'addressable'
35+
gem.add_runtime_dependency 'environs'
3536
end

lib/buffer.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require "json"
44
require "hashie/mash"
55
require "addressable/uri"
6+
require 'environs'
67

78
require "buffer/version"
89
require "buffer/core"

0 commit comments

Comments
 (0)