Permalink
Browse files

List blocks working

  • Loading branch information...
1 parent 84a6f4d commit 9224dff4c9b5e2762e843ef426ccd17bb8db439f @txus committed Dec 8, 2011
Showing with 112 additions and 4 deletions.
  1. +48 −0 bin/springpad
  2. +22 −0 lib/springpad.rb
  3. +9 −2 lib/springpad/blocks.rb
  4. +19 −2 lib/springpad/blocks/note.rb
  5. +13 −0 lib/springpad/blocks/task.rb
  6. +1 −0 springpad.gemspec
View
@@ -0,0 +1,48 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'commander/import'
+require_relative "../lib/springpad"
+
+program :version, Springpad::VERSION
+program :description, 'Command-line client to the Springpad API.'
+program :help, 'Author', 'Josep M. Bach (Txus) <josep.m.bach@gmail.com>'
+
+command :list do |c|
+ c.syntax = 'springpad list TYPE [options]'
+ c.summary = 'Lists all elements of a certain TYPE.'
+ c.description = 'Springpad blocks have an associated type, for example Note or Task. This command lists every block you own of a certain type. The result can be filtered using [options].'
+ c.example 'List all private notes', 'springpad list note --private'
+ c.option '--private', 'Show only private blocks'
+ c.action do |args, options|
+ type = args.first
+ unless type
+ warn "A TYPE must be specified. To know about available types, run:"
+ warn " $ springpad types"
+ abort
+ end
+ Springpad.list(type, options)
+ end
+end
+
+command :add do |c|
+ c.syntax = 'springpad add type [options]'
+ c.summary = 'Adds an element of a certain type.'
+ c.description = ''
+ c.example 'description', 'command example'
+ c.option '--some-switch', 'Some switch that does something'
+ c.action do |args, options|
+ # Do something or c.when_called Springpad::Commands::Add
+ end
+end
+
+command :types do |c|
+ c.syntax = 'springpad types'
+ c.summary = 'Lists the supported element types.'
+ c.description = ''
+ c.action do |args, options|
+ types = Springpad::Blocks.types
+ puts "Supported types are: #{types.join(', ')}"
+ end
+end
+
View
@@ -4,4 +4,26 @@
require_relative "springpad/cli"
module Springpad
+ def self.list(type, options)
+ api = Springpad::API.new
+ options = {}
+ options.merge({:public => false}) if options[:private]
+ case type
+ when "note"
+ render api.notes(options)
+ when "task"
+ render api.tasks(options)
+ end
+ end
+
+ def self.render(elements)
+ elements.each do |element|
+ element.render
+ puts
+ end
+ end
+
+ def self.add
+
+ end
end
@@ -1,7 +1,14 @@
module Springpad
module Blocks
+ def self.types
+ [
+ "note",
+ "task",
+ ]
+ end
end
end
-require_relative "blocks/note"
-require_relative "blocks/task"
+Springpad::Blocks.types.each do |type|
+ require_relative "blocks/#{type}"
+end
@@ -1,3 +1,6 @@
+require 'highline'
+require 'stringio'
+
module Springpad
module Blocks
# Public: Maps to a Springpad Note block.
@@ -18,7 +21,7 @@ class Note
def self.process(json)
json.map do |note|
Note.new(
- note['name'],
+ note['name'] || "(no title)",
note['properties']['text']
)
end
@@ -29,7 +32,21 @@ def self.process(json)
# name - the String name
# text - the String text content
def initialize(name, text)
- @name, @text = name, text
+ @name = name
+ @text = text
+ end
+
+ # Public: Renders a note to the standard output.
+ #
+ # Returns nothing.
+ def render
+ out = HighLine.new
+ out.wrap_at = 78
+ out.say <<-RENDER
+<%=color("#{@name}", :bold)%>
+<%='-'*#{@name.length}%>
+#{@text}
+RENDER
end
end
end
@@ -35,6 +35,19 @@ def initialize(name, description, category)
@description = description
@category = category
end
+
+ # Public: Renders a task to the standard output.
+ #
+ # Returns nothing.
+ def render
+ out = HighLine.new
+ out.wrap_at = 78
+ out.say <<-RENDER
+<%=color("#{@name}", :bold)%> [#{@category.upcase}]
+<%='-'*#{@name.length}%>
+#{@description}
+RENDER
+ end
end
end
end
View
@@ -24,4 +24,5 @@ Gem::Specification.new do |s|
s.add_development_dependency "vcr"
s.add_development_dependency "webmock"
s.add_runtime_dependency "rest-client"
+ s.add_runtime_dependency "commander"
end

0 comments on commit 9224dff

Please sign in to comment.