Class: TypePadTemplate::Command

Inherits:
Thor
  • Object
show all
Defined in:
lib/type_pad_template/command.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.blog_id_optionObject



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_optionObject



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_optionObject



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

#blogsObject



54
55
56
# File 'lib/type_pad_template/command.rb', line 54

def blogs
  print_table .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

#loginObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/type_pad_template/command.rb', line 37

def 
  username = options[:username] || highline.ask("Enter login email address: ")
  password = options[:password] || highline.ask("Enter password: "){|q| q.echo = false }

   = Account.(username, password)

  File.open(SESSION_FILE, "w") do |file|
    YAML.dump(., file)
  end
end

#logoutObject



49
50
51
# File 'lib/type_pad_template/command.rb', line 49

def logout
  File.unlink(SESSION_FILE)
end

#templatesObject



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

#uploadObject



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