Class: Hackpad::Cli::Client
- Inherits:
-
Object
- Object
- Hackpad::Cli::Client
- Defined in:
- lib/hackpad/cli/client.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #add ⇒ Object
- #default ⇒ Object
- #getnew ⇒ Object
- #info(id) ⇒ Object
-
#initialize(options, input = STDIN, output = STDOUT) ⇒ Client
constructor
A new instance of Client.
- #list ⇒ Object
- #search(term, start = 0) ⇒ Object
- #show(id, format) ⇒ Object
- #stats ⇒ Object
- #workspaces ⇒ Object
Constructor Details
#initialize(options, input = STDIN, output = STDOUT) ⇒ Client
Returns a new instance of Client.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/hackpad/cli/client.rb', line 16 def initialize(, input = STDIN, output = STDOUT) @output = output @input = input @config = Config.new , @input, @output if [:plain] == true || @config.use_colors == false Paint.mode = 0 end @workspace = Workspace.new({ basedir: File.join(@config.basedir, @config.workspace), name: @config.workspace }, @input, @output) Store.prepare @config, @workspace Api.prepare @workspace end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
14 15 16 |
# File 'lib/hackpad/cli/client.rb', line 14 def config @config end |
Instance Method Details
#add ⇒ Object
28 29 30 |
# File 'lib/hackpad/cli/client.rb', line 28 def add @workspace.clone.create end |
#default ⇒ Object
41 42 43 |
# File 'lib/hackpad/cli/client.rb', line 41 def default @config.change_default end |
#getnew ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/hackpad/cli/client.rb', line 65 def getnew @output.puts 'New pads:' padlist = Padlist.get_new if padlist.count == 0 @output.puts 'There is no new pad.' else @output.puts padlist.map { |pad| padline pad } end end |
#info(id) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/hackpad/cli/client.rb', line 77 def info(id) pad = Pad.new id pad.load 'txt' table 'Id', Paint[id, :bold] table 'Title', Paint[pad.title, :yellow] table 'URI', "#{@workspace.site}/#{id}" table 'Chars', "#{pad.chars}" table 'Lines', "#{pad.lines}" table 'Guest Policy', "#{pad.guest_policy}" table 'Moderated', "#{pad.moderated}" table 'Cached', "#{pad.cached_at || 'unknown'}" end |
#list ⇒ Object
59 60 61 62 63 |
# File 'lib/hackpad/cli/client.rb', line 59 def list @output.puts Padlist.get_list(@config.refresh).map { |pad| padline pad } end |
#search(term, start = 0) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/hackpad/cli/client.rb', line 51 def search(term, start = 0) payload = Api.search(term, start) payload.each do |a| @output.puts "#{id_or_url a['id']} - #{Paint[unescape(a['title']), :yellow]}" @output.puts " #{extract a['snippet']}" end end |
#show(id, format) ⇒ Object
90 91 92 93 94 |
# File 'lib/hackpad/cli/client.rb', line 90 def show(id, format) pad = Pad.new id pad.load format @output.puts pad.content end |
#stats ⇒ Object
45 46 47 48 49 |
# File 'lib/hackpad/cli/client.rb', line 45 def stats table 'Site', Paint[@workspace.site, :blue] table 'Cached Pads', Store.count_pads table 'Last Refresh', Store.last_refresh || 'not refreshed yet' end |
#workspaces ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/hackpad/cli/client.rb', line 32 def workspaces @config.workspaces.each do |s| if s.name == @config.workspace s.name = "> #{s.name}" end table s.name, s.site end end |