hackpad-cli 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +2 -0
- data/lib/hackpad/cli.rb +6 -1
- data/lib/hackpad/cli/version.rb +1 -1
- data/lib/hackpad/client.rb +38 -1
- data/lib/hackpad/store.rb +3 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb3d4f67776326cac794826db144053a0e8f7e77
|
4
|
+
data.tar.gz: ff10d38d124cf94e61e7dc24075ba6267f167a49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b09a50391fa3911944a0a13c50e21f7fb766a16fbc6a00d54cfebf3f1a10616c2a0728a6c84ceb5cf56585b47df2200304da83b236c6b318c72b37bcbf1b43e
|
7
|
+
data.tar.gz: f06e4d88f32f0fab0dbea052cbef7b959c92ca9f93a426edb74f243590542a52d88beb39b4d95db5fc591a85f50166f21203638300324249ad0e75acb94f9948
|
data/CHANGELOG.md
CHANGED
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
|
33
|
+
def info(pad)
|
29
34
|
Hackpad::Client.new(options).getinfo pad
|
30
35
|
end
|
31
36
|
|
data/lib/hackpad/cli/version.rb
CHANGED
data/lib/hackpad/client.rb
CHANGED
@@ -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
|
-
|
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
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.
|
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-
|
11
|
+
date: 2014-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|