#!/usr/bin/env ruby require 'twoffein-client' require 'gli' include Twoffein include GLI::App DEBUG = $DEBUG program_desc "Client for API #{Server::VERSION} twoffein.de" desc "Show version" version Client::VERSION desc 'List the profile, which you have chosen by PROFILE' arg_name 'Name of profile which will be shown' command :profile do |c| #c.desc "Grep all profiles" #c.flag :grep c.action do |global_options,options,args| profile = args.first #if options[:grep] #puts Profiles.search(/#{options["grep"]}/i) #else puts Profile.get profile #end end end desc "List all drinks" arg_name "Describe arguments to drinks here" command :drinks do |c| c.desc "Grep all drinks" c.flag :grep c.action do |global_options,options,args| if options[:grep] puts Drinks.search(/#{options[:grep]}/i) else puts Drinks.new end end end desc 'Tweet your drinking DRINK' arg_name 'key_of_drink (see command "drinks")' command :tweet do |c| c.desc "Drink with somebody" c.flag :with c.action do |global_options,options,args| help_now!('DRINK is required') if args.empty? drink = args.first tweet = Tweet.new(drink, options[:with]) puts tweet.to_s begin info = tweet.publish unless DEBUG puts 'Info: ' + info[:info] unless info.nil? puts 'Drinks today: ' + info[:tweets].to_s if info && !info[:tweets].nil? rescue Twoffein::Error => e puts e.message end end end desc 'Give cookie to RECEIVER' arg_name 'Receiver receives your cookie' command :cookie do |c| c.action do |global_options,options,args| help_now!('RECEIVER is required') if args.empty? receiver = args.first cookie = Cookie.new(receiver) begin info = cookie.send unless DEBUG puts 'Info: ' + info[:info] unless info.nil? rescue Twoffein::Error => e puts e.message end end end exit run(ARGV)