hackpad-cli 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb2500eed443d5bc32fb2c6a1c0fdbd85095037a
4
- data.tar.gz: af50106dab8686626a27c6bba5085a6211717773
3
+ metadata.gz: fb3d4f67776326cac794826db144053a0e8f7e77
4
+ data.tar.gz: ff10d38d124cf94e61e7dc24075ba6267f167a49
5
5
  SHA512:
6
- metadata.gz: 3531001771b33e3e8eeffee112b7e1f0075fabc32c6e10281c6b2df9eb81a7a30df2d0d51e7190f029f6aff51d8cc4b97fa47de8180cc35ae162a34b76b442dd
7
- data.tar.gz: 93f097d8ded9f2a4e45cf9e5f914d14a116f9950e32b90daa832553d38829b2fba1aa2bbe50a113d2135a03aa031723c0bc832ddff2126fcb6eb067784a7c91b
6
+ metadata.gz: 6b09a50391fa3911944a0a13c50e21f7fb766a16fbc6a00d54cfebf3f1a10616c2a0728a6c84ceb5cf56585b47df2200304da83b236c6b318c72b37bcbf1b43e
7
+ data.tar.gz: f06e4d88f32f0fab0dbea052cbef7b959c92ca9f93a426edb74f243590542a52d88beb39b4d95db5fc591a85f50166f21203638300324249ad0e75acb94f9948
data/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  Hackpad-cli changelog
2
2
  ==========================
3
3
 
4
+ v0.0.4 - 2014-04-01
5
+ --------------------
6
+
7
+ * add options in pad info for `hpcli info [pad_id]`
8
+ * implement a search command `hpcli search [term]`
9
+
4
10
  v0.0.3 - 2014-04-01
5
11
  --------------
6
12
 
data/README.md CHANGED
@@ -37,6 +37,8 @@ At first launch it will create your config dir (default ~/.hackpad-cli/), and wi
37
37
  Roadmap and todoz
38
38
  ---------------------
39
39
 
40
+ Check the [Changelog](CHANGELOG.md) for past evolutions.
41
+
40
42
  * cache the pads list in a local storage
41
43
  * refresh cache according to last cached date
42
44
  * add commands for creating a new pad, linked to $EDITOR
data/lib/hackpad/cli.rb CHANGED
@@ -19,13 +19,18 @@ module Hackpad
19
19
 
20
20
  default_task :help
21
21
 
22
+ desc "search [term]", "Lists available pads matching [term]."
23
+ def search(term)
24
+ Hackpad::Client.new(options).search term
25
+ end
26
+
22
27
  desc "list", "Lists available pads."
23
28
  def list
24
29
  Hackpad::Client.new(options).listall
25
30
  end
26
31
 
27
32
  desc "getinfo [pad_id]", "gets info for the pad <pad_id>."
28
- def getinfo(pad)
33
+ def info(pad)
29
34
  Hackpad::Client.new(options).getinfo pad
30
35
  end
31
36
 
@@ -2,6 +2,6 @@ require "thor"
2
2
 
3
3
  module Hackpad
4
4
  class Cli < Thor
5
- VERSION = "0.0.3"
5
+ VERSION = "0.0.4"
6
6
  end
7
7
  end
@@ -1,6 +1,7 @@
1
1
  require 'oauth'
2
2
  require 'net/http'
3
3
  require 'json'
4
+ require 'cgi'
4
5
  require 'reverse_markdown'
5
6
 
6
7
  require_relative 'config'
@@ -20,6 +21,21 @@ module Hackpad
20
21
  end
21
22
 
22
23
  # GET /api/1.0/pads/all
24
+ def search(term,start=0)
25
+ res = @token.get "/api/1.0/search?q=#{CGI.escape term}&start=#{start}&limit=100"
26
+ if res.is_a? Net::HTTPSuccess
27
+ all = JSON.parse res.body
28
+ all.each do |a|
29
+ puts "#{a['id'].bold} - #{unescape(a['title']).colorize(:yellow)}\n #{extract a['snippet']}"
30
+ end
31
+
32
+ else
33
+ puts "#{res.inspect}".colorize :red
34
+ puts "#{res.body}".colorize :red
35
+ return back
36
+ end
37
+ end
38
+
23
39
  def listall
24
40
  res = @token.get "/api/1.0/pads/all"
25
41
  if res.is_a? Net::HTTPSuccess
@@ -37,7 +53,18 @@ module Hackpad
37
53
  def getinfo(pad)
38
54
  res = @token.get "/api/1.0/pad/#{pad}/content.txt"
39
55
  if res.is_a? Net::HTTPSuccess
40
- puts "#{@config['site']}/#{pad} - #{pad} - #{res.body.lines.first.chomp}"
56
+ printf "%-20s %s\n", "Id", "#{pad}".bold
57
+ printf "%-20s %s\n", "Title", "#{res.body.lines.first.chomp}".colorize(:yellow)
58
+ printf "%-20s %s\n", "URI", "#{@config['site']}/#{pad}"
59
+ printf "%-20s %s\n", "Size", "#{res.body.length} chars"
60
+ else
61
+ puts "#{pad} failed".colorize :red
62
+ end
63
+ res = @token.get "/api/1.0/pad/#{pad}/options"
64
+ if res.is_a? Net::HTTPSuccess
65
+ a = JSON.parse res.body
66
+ printf "%-20s %s\n", "Guest Policy", "#{a['options']['guestPolicy']}"
67
+ printf "%-20s %s\n", "Moderated", "#{a['options']['isModerated'] || "No"}"
41
68
  else
42
69
  puts "#{pad} failed".colorize :red
43
70
  end
@@ -59,5 +86,15 @@ module Hackpad
59
86
  end
60
87
  end
61
88
 
89
+ private
90
+
91
+ def unescape(s)
92
+ CGI.unescapeHTML s
93
+ end
94
+
95
+ def extract(s)
96
+ unescape(s).gsub(/<b class="hit">([^<]*)<\/b>/) { |e| $1.colorize(:cyan).bold }
97
+ end
98
+
62
99
  end
63
100
  end
data/lib/hackpad/store.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  module Hackpad
2
2
  class Store
3
3
 
4
+ def initialize(config)
5
+ end
6
+
4
7
  end
5
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hackpad-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - mose
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-30 00:00:00.000000000 Z
11
+ date: 2014-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor