Sha256: 34d580b54129f974498516f260114b802452751c18e8c38dd790a8f02c343f0b

Contents?: true

Size: 1.51 KB

Versions: 5

Compression:

Stored size: 1.51 KB

Contents

require 'optparse'
require 'yaml'

module Instafavs
  CONFIG_FILENAME = File.expand_path("~/.instafavs")

  module Config
    
    class << self

      def save!(config=nil)
        config_to_save = config.nil? ? @config : config

        File.open(CONFIG_FILENAME, "w+") do |f|
          f.chmod(0600)
          f.write(YAML.dump(config_to_save))
        end
      end
    
      def load!
        raise "missing configuration file. run 'instafavs --configure'." unless File.exists?(CONFIG_FILENAME)
        @config = YAML.load_file(CONFIG_FILENAME)
      end
    
      def twitter_username
        @config["twitter_username"]
      end
    
      def instapaper_username
        @config["instapaper_username"]
      end
    
      def instapaper_password
        @config["instapaper_password"]
      end
      
      def last_seen_fav_ids
        @last_seen_fav_ids ||= @config["last_seen_fav_ids"] || Set.new
      end
      
      def update_last_seen_fav_ids!(seen_fav_ids)
        @config["last_seen_fav_ids"] = seen_fav_ids.to_a.join(",")
        save!
      end
    end
  
  end

  def self.parse_cmd_line_options!
    options = {}
    OptionParser.new do |opts|
      opts.banner = "Usage: instafavs [options]"

      opts.on("-c", "--configure", "Configure Twitter and Instapaper account details") do |c|
        options[:configure] = true
      end
      
      opts.on("-v", "--verbose", "Provide more detailed output of what instafavs is doing") do |c|
        options[:verbose] = true
      end
    end.parse!

    options
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
instafavs-0.0.5 lib/instafavs.rb
instafavs-0.0.4 lib/instafavs.rb
instafavs-0.0.3 lib/instafavs.rb
instafavs-0.0.2 lib/instafavs.rb
instafavs-0.0.1 lib/instafavs.rb