Class: Ubiquitously::Command::Post
- Defined in:
- lib/ubiquitously/commands/post.rb
Defined Under Namespace
Modules: Opts
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#configure, #initialize, #main_folder, run, #show, #write
Constructor Details
This class inherits a constructor from Ubiquitously::Command::Base
Instance Method Details
#parse_options(args, attributes = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ubiquitously/commands/post.rb', line 25 def (args, attributes = {}) option_parser = OptionParser.new do |o| o.extend Ubiquitously::Command::Post::Opts o.(attributes) o. = "Usage: u.me [command] [service(s)] [options]\n" + "\n" + "Supported Commands:\n#{Ubiquitously.services.sort.join(', ')}" o.section "Post attributes:" do url title description username password end end option_parser.parse!(args) required attributes end |
#required(attributes) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/ubiquitously/commands/post.rb', line 17 def required(attributes) missing = %w(description).delete_if { |i| !attributes[i.to_sym].blank? } unless missing.blank? raise CommandInvalid.new("Missing arguments for post: #{missing.join(", ")}") end attributes end |
#run ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/ubiquitously/commands/post.rb', line 5 def run user = Ubiquitously::User.new(:storage => main_folder) user.accountables(services) do |account| account = account.new( :user => user, :username => attributes[:username] || Ubiquitously.key("#{account.service}.key"), :password => attributes[:password] || Ubiquitously.key("#{account.service}.secret") ) end Ubiquitously::Post.new(attributes.merge(:user => user)).save(services) end |