Class: TypePadTemplate::Command
- Inherits:
-
Thor
- Object
- Thor
- TypePadTemplate::Command
- Defined in:
- lib/type_pad_template/command.rb
Class Method Summary collapse
Instance Method Summary collapse
- #blogs ⇒ Object
- #download(filenames = nil) ⇒ Object
- #login ⇒ Object
- #logout ⇒ Object
- #templates ⇒ Object
- #upload ⇒ Object
Class Method Details
.blog_id_option ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/type_pad_template/command.rb', line 9 def self.blog_id_option method_option(:blog_id, { :type => :string, :aliases => "-b", :required => true, :desc => "Blog ID which blogs command shows" }) end |
.directory_option ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/type_pad_template/command.rb', line 18 def self.directory_option method_option(:directory, { :type => :string, :aliases => "-d", :desc => "Path to templates directory" }) end |
.pattern_option ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/type_pad_template/command.rb', line 26 def self.pattern_option method_option(:pattern, { :type => :string, :aliases => "-p", :desc => "Pattern to select templates" }) end |
Instance Method Details
#blogs ⇒ Object
54 55 56 |
# File 'lib/type_pad_template/command.rb', line 54 def blogs print_table account.blogs.map{|blog| [blog.blog_id, blog.name]} end |
#download(filenames = nil) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/type_pad_template/command.rb', line 68 def download(filenames = nil) pattern_select(blog.templates).each do |template| template.enqueue_get do |text| say "Downloaded #{template.filename}" File.open(File.join(directory, template.filename), "w"){|f| f.write(text)} end end Request.dispatch end |
#login ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/type_pad_template/command.rb', line 37 def login username = [:username] || highline.ask("Enter login email address: ") password = [:password] || highline.ask("Enter password: "){|q| q.echo = false } account = Account.login(username, password) File.open(SESSION_FILE, "w") do |file| YAML.dump(account., file) end end |
#logout ⇒ Object
49 50 51 |
# File 'lib/type_pad_template/command.rb', line 49 def logout File.unlink(SESSION_FILE) end |
#templates ⇒ Object
60 61 62 |
# File 'lib/type_pad_template/command.rb', line 60 def templates print_table blog.templates.map{|template| [template.filename, template.name]} end |
#upload ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/type_pad_template/command.rb', line 82 def upload pattern_select(blog.templates).each do |template| path = File.join(directory, template.filename) template.enqueue_post(File.read(path)) do |response| say "Uploaded #{template.filename}" end end Request.dispatch end |