Permalink
Browse files

adding Pingfm::Config.[]=(key, value)

  • Loading branch information...
1 parent ae32d62 commit 0ac7618cb9c7813d78b6d0b02cbce5a59ad8a502 @Oshuma committed Jun 12, 2011
Showing with 39 additions and 10 deletions.
  1. +16 −4 README.rdoc
  2. +11 −0 Rakefile
  3. +4 −2 bin/pingfm
  4. +1 −1 lib/pingfm.rb
  5. +7 −3 lib/pingfm/config.rb
View
@@ -21,6 +21,19 @@
pingfm.tpost('The message here.', '#something_custom', 'Optional Title')
# => {'status' => 'OK'} # if success, otherwise 'FAIL'
+You can also manage the configuration file through <tt>Pingfm::Config</tt>.
+
+ # Load from an existing config file (defaults to $HOME/.pingfm.yml).
+ begin
+ app_key = Pingfm::Config['app_key']
+ rescue Pingfm::ConfigNotFound # This is raised if the config file can't be found.
+ # Helper method to get user app key from STDIN:
+ app_key = Pingfm::Config.ask_for_app_key!
+
+ # Or just assign a value to 'app_key' (this will automatically save the config file):
+ Pingfm::Config['app_key'] = 'YOUR_USER_APP_KEY'
+ end
+
Check the {documentation}[http://rdoc.info/projects/Oshuma/pingfm] for more details.
== Shell Usage
@@ -29,18 +42,17 @@ Check the {documentation}[http://rdoc.info/projects/Oshuma/pingfm] for more deta
Everything after the '<tt>pingfm</tt>' command is what will be posted to the service. You
may also include the message within quotes (ex. using the client within a shell script).
+Run with '<tt>--help</tt>' to list all command-line options.
If your key has not been stored, it will ask for it. This key will be saved
in a YAML file in your home directory and you won't be asked for it again.
-You can obtain your key here:
-
-* User API Key - {http://ping.fm/key/}[http://ping.fm/key/]
+You can obtain your key here: {http://ping.fm/key/}[http://ping.fm/key/]
== Authors
-* {Dale Campbell}[http://oshuma.github.com/]
+* {Dale Campbell}[http://nerdno.de/]
* {Kevin Williams}[http://kevwil.com/]
* {Krunoslav Husak}[http://h00s.net]
View
@@ -1,4 +1,5 @@
require 'bundler'
+require 'rdoc/task'
require 'rspec/core/rake_task'
Bundler::GemHelper.install_tasks
@@ -14,3 +15,13 @@ desc 'Run the specs'
RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = ['--color']
end
+
+namespace :docs do
+ RDoc::Task.new do |rd|
+ rd.title = "Pingfm API Docs"
+ rd.main = "README.rdoc"
+ rd.rdoc_dir = "#{File.dirname(__FILE__)}/doc/api"
+ rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
+ rd.options << "--all"
+ end
+end
View
@@ -4,6 +4,8 @@ require 'rubygems' if RUBY_VERSION =~ /1\.8/
require 'bundler/setup'
require 'slop'
+require 'pingfm'
+
opts = Slop.parse!(:help => true) do
banner "Usage: #{File.basename(__FILE__)} [options] <message>"
@@ -35,8 +37,8 @@ message = ARGV.join(' ')
begin
app_key = Pingfm::Config['app_key']
rescue Pingfm::ConfigNotFound => error
- Pingfm::Config.ask_for_app_key!
- app_key = Pingfm::Config['app_key']
+ app_key = Pingfm::Config.ask_for_app_key!
+ Pingfm::Config['app_key'] = app_key
end
client = Pingfm::Client.new(app_key)
View
@@ -4,5 +4,5 @@
require 'pingfm/config'
module Pingfm
- VERSION = '2.0.0'
+ VERSION = '2.1.0'
end
View
@@ -10,16 +10,20 @@ class << self
# Prompts the user for their API key and saves it.
def ask_for_app_key!
STDOUT.print 'Enter your Ping.fm User API key (http://ping.fm/key/): '
- @@config ||= {}
- @@config['app_key'] = STDIN.gets.chomp
- save!
+ STDIN.gets.chomp
end
def [](key)
setup! unless defined?(@@config)
@@config[key]
end
+ def []=(key, value)
+ @@config ||= {}
+ @@config[key] = value
+ save!
+ end
+
def save!
::File.open(CONFIG_FILE, 'w') do |config_file|
::YAML.dump(@@config, config_file)

0 comments on commit 0ac7618

Please sign in to comment.