Skip to content

Commit b549152

Browse files
committed
Switching to Yaml format config file
1 parent 1afc0ab commit b549152

4 files changed

Lines changed: 43 additions & 36 deletions

File tree

.bufferapprc.template

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
SUPER_SECRET_AUTH_TOKEN
2-
0
1+
---
2+
access_token: ASDFASDFASDF
3+
profile_index: 0
4+
version: 0.0.1
35

46
# How to Get Started:
57
# Create a Developer API Token here: http://bufferapp.com/developers/apps/create.
68
# Fill in Stuff. Your answers don't matter much for the purpose of this rudimentary setup.
79
# Submit that form and wait a short period (~2 min )
810
# Visit: http://bufferapp.com/developers/apps
9-
# Gather Access Token and place it on line 1 of this file.
11+
# Gather Access Token and place it after the word "access_token"
1012
# Copy this file to the root of your user's home folder:
13+
# Set "profile_index" to 0 if you only have one account to post to. Otherwise it's more complicated ;). Find me on Twitter and I can explain (@_ZPH).
1114
# - ~/.bufferapprc
12-
# Set Line 2 to 0 if you only have one account to post to. Otherwise it's more complicated ;). Find me on Twitter and I can explain (@_ZPH).
1315

1416
# Structure:
15-
# Line 1: Access Token
16-
# Line 2: Buffer Account number, ie posting to first account in list, use 0 (ie zero)
17+
# access_token: Access Token
18+
# profile_index: Buffer Account number, ie posting to first account in list, use 0 (ie zero)
1719
#
18-
#TODO: convert to yaml and improve instructions
20+
#TODO: improve instructions
1921
# remove need for user to create their own App on bufferapp.com
2022
# Future versions will integrate with Buffer-OAuth system.
2123

README.md

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,34 +37,29 @@ Or install RubyGems version, which will receive more attention to stability:
3737

3838

3939
```
40-
ACCESS_TOKEN
41-
PROFILE_INDEX (default of 0)
40+
---
41+
ACCESS_TOKEN: (BufferApp OAuth Access Token)
42+
PROFILE_INDEX: (default of 0)
43+
VERSION: (Do not alter)
4244
43-
# Structure:
44-
# Access Token: line 1
45-
# Profile number, counting from zero
4645
```
4746

4847
## Access Token Instructions
4948

50-
How to Get Started:
49+
# How to Get Started:
5150
====
52-
* Create a Developer API Token here: http://bufferapp.com/developers/apps/create.
53-
* Fill in Stuff. Your answers don't matter much for the purpose of this rudimentary setup.
54-
* Submit that form and wait a short period (~2 min )
55-
* Visit: http://bufferapp.com/developers/apps
56-
* Gather Access Token and place it on line 1 of this file.
57-
* Copy this file to the root of your user's home folder:
58-
- ~/.bufferapprc
51+
# Create a Developer API Token here: http://bufferapp.com/developers/apps/create.
52+
# Fill in Stuff. Your answers don't matter much for the purpose of this rudimentary setup.
53+
# Submit that form and wait a short period (~2 min )
54+
# Visit: http://bufferapp.com/developers/apps
55+
# Gather Access Token and place it after the word "access_token"
56+
# Copy this file to the root of your user's home folder:
5957
* Set Line 2 to 0 if you only have one account to post to. Otherwise it's more complicated ;). Find me on Twitter and I can explain [@_ZPH](https://twitter.com/_ZPH).
58+
# - ~/.bufferapprc
6059

61-
Structure:
62-
Line 1: Access Token
63-
Line 2: Buffer Account number, ie posting to first account in list, use 0 (ie zero)
64-
65-
TODO: convert to yaml and improve instructions
66-
remove need for user to create their own App on bufferapp.com
67-
Future versions will integrate with Buffer-OAuth system.
60+
#TODO: improve instructions
61+
# remove need for user to create their own App on bufferapp.com
62+
# Future versions will integrate with Buffer-OAuth system.
6863

6964
## API Coverage
7065

bin/buff

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,20 @@ $LOAD_PATH.unshift(File.dirname(__FILE__), '..', 'lib')
44

55
require 'buff'
66

7-
access_token, profile_id = File.open(File.expand_path '~/.bufferapprc').readlines.map(&:chomp)
7+
begin
8+
require 'yaml'
89

9-
client = Buff::Client.new(access_token)
10-
id = client.profiles[profile_id.to_i].id
10+
options = YAML.load_file(File.expand_path('~/.bufferapprc'))
11+
if options.class == String
12+
options['access_token'], options['profile_index'] = options.split
13+
options['verion'] = '0.0.0'
14+
end
15+
rescue
16+
puts "Please upgrade from older config file structure" if ENV['BUFF_DEBUG']
17+
end
18+
19+
client = Buff::Client.new(options['access_token'])
20+
id = client.profiles[options['profile_index'].to_i].id
1121

1222
response = client.create_update(body: {text: ARGV.join(" "), profile_ids: [ id ] } )
1323
puts response if ENV['BUFF_DEBUG']

lib/buff/core.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
module Buff
44
begin
55
#TODO: change from #expand_path to Pathname if appropriate
6-
if File.exists?(File.expand_path("~/.bufferapprc"))
7-
ACCESS_TOKEN = File.open(File.expand_path("~/.bufferapprc")).
8-
readlines[0].chomp
9-
end
10-
rescue => x
11-
raise x, "Bufferapprc appears to be malformed"
6+
# if File.exists?(File.expand_path("~/.bufferapprc"))
7+
# ACCESS_TOKEN = File.open(File.expand_path("~/.bufferapprc")).
8+
# readlines[0].chomp
9+
# end
10+
# rescue => x
11+
# raise x, "Bufferapprc appears to be malformed"
1212
end
1313

1414
class Client

0 commit comments

Comments
 (0)