hackpad-cli 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +1 -0
- data/bin/hpcli +5 -0
- data/hackpad-cli.gemspec +28 -0
- data/lib/hackpad/cli.rb +36 -0
- data/lib/hackpad/cli/version.rb +7 -0
- data/lib/hackpad/client.rb +64 -0
- data/lib/hackpad/config.rb +42 -0
- data/lib/hackpad/store.rb +5 -0
- metadata +143 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2fa9a4f22177ff0c7238a3335cb6d2159035e5e4
|
4
|
+
data.tar.gz: fb6c60ff2e364fdfc16114fb8744e924b4c6f298
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4711b53f44a1a856f00ac1bc9e08742272dd08421ac704009496c7624db56b910d5d5a8c0a3f0cc5834f7dfac99a0edbee15b04e0d9b137f1176177320becf4a
|
7
|
+
data.tar.gz: 587a1e4d9b8c657d7250a4f90253e07b57e27fab8bed71fe4bc98a64fbfe41abe9e7517181c3a75bac978b35057f1ee43014b02680157f9205b02e63f69e717f
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
hpcli
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.1
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 mose
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
Hackpad-Cli
|
2
|
+
===================
|
3
|
+
|
4
|
+
This is a command-line utility to check and manipulate hackpad documents.
|
5
|
+
It uses Hackpad REST API 1.0 https://hackpad.com/fQD2DRz22Wf
|
6
|
+
|
7
|
+
Initially this tool was created to overcome the frustration of the md export of pads, becasue we need to copy them to other places sometimes where proper markdown would be appreciated.
|
8
|
+
|
9
|
+
So for now, it does that, by transforming the html in markdown with the https://github.com/xijo/reverse_markdown gem.
|
10
|
+
|
11
|
+
Installation
|
12
|
+
------------------
|
13
|
+
|
14
|
+
gem install hackpad-cli
|
15
|
+
|
16
|
+
or
|
17
|
+
|
18
|
+
git clone https://github.com/mose/hackpad-cli.git
|
19
|
+
cd hackpad-cli
|
20
|
+
bundle install
|
21
|
+
|
22
|
+
Usage
|
23
|
+
---------------
|
24
|
+
|
25
|
+
(use `bundle exec` if you need, mostly in clone mode when not using rvm)
|
26
|
+
|
27
|
+
hpcli # will show help
|
28
|
+
hpcli get <pad_id> md # will spit out the content in nice markdown
|
29
|
+
|
30
|
+
|
31
|
+
Contributing
|
32
|
+
------------------
|
33
|
+
|
34
|
+
1. Fork it ( http://github.com/<my-github-username>/hackpad-cli/fork )
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
38
|
+
5. Create new Pull Request
|
39
|
+
|
40
|
+
Copyright
|
41
|
+
----------
|
42
|
+
|
43
|
+
(c) Copy is right, 2014 - mose - this code is distributed under MIT license
|
44
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/hpcli
ADDED
data/hackpad-cli.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hackpad/cli/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "hackpad-cli"
|
8
|
+
spec.version = Hackpad::Cli::VERSION
|
9
|
+
spec.authors = ["mose"]
|
10
|
+
spec.email = ["mose@mose.com"]
|
11
|
+
spec.summary = %q{CLI for hackpad browsing and editing.}
|
12
|
+
spec.description = %q{A Command Line Interface for consuming the Hackpad REST API.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "thor"
|
22
|
+
spec.add_dependency "colorize"
|
23
|
+
spec.add_dependency "oauth"
|
24
|
+
spec.add_dependency "reverse_markdown"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
end
|
data/lib/hackpad/cli.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require "thor"
|
2
|
+
require "colorize"
|
3
|
+
require "yaml"
|
4
|
+
require_relative "client"
|
5
|
+
|
6
|
+
module Hackpad
|
7
|
+
|
8
|
+
class Cli < Thor
|
9
|
+
include Thor::Actions
|
10
|
+
|
11
|
+
default_task :help
|
12
|
+
|
13
|
+
class_option :configdir,
|
14
|
+
aliases: "-c",
|
15
|
+
banner: "PATH",
|
16
|
+
default: File.join(ENV["HOME"], ".hackpad-cli/"),
|
17
|
+
desc: "Path to the hackpad-cli directory to use"
|
18
|
+
|
19
|
+
desc "list", "Lists available pads."
|
20
|
+
def list
|
21
|
+
Hackpad::Client.new(options[:configdir]).list
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "getinfo [pad_id]", "gets info for the pad <pad_id>"
|
25
|
+
def getinfo(pad)
|
26
|
+
Hackpad::Client.new(options[:configdir]).getinfo pad
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "show [pad_id] [format]", "shows pad <pad_id> in format [html,txt,md] (default txt)"
|
30
|
+
def show(pad,format='txt')
|
31
|
+
Hackpad::Client.new(options[:configdir]).show pad, format
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'oauth'
|
2
|
+
require 'net/http'
|
3
|
+
require 'json'
|
4
|
+
require 'reverse_markdown'
|
5
|
+
require 'awesome_print'
|
6
|
+
require_relative 'config'
|
7
|
+
|
8
|
+
module Hackpad
|
9
|
+
class Client
|
10
|
+
|
11
|
+
def initialize(configdir)
|
12
|
+
@configdir = configdir
|
13
|
+
@config = Config.load configdir
|
14
|
+
site = URI.parse @config['site']
|
15
|
+
consumer = OAuth::Consumer.new(
|
16
|
+
@config['client_id'],
|
17
|
+
@config['secret'],
|
18
|
+
site: @config['site']
|
19
|
+
)
|
20
|
+
@token = OAuth::AccessToken.new consumer
|
21
|
+
end
|
22
|
+
|
23
|
+
# GET /api/1.0/pads/all
|
24
|
+
def list
|
25
|
+
res = @token.get "/api/1.0/pads/all"
|
26
|
+
if res.is_a? Net::HTTPSuccess
|
27
|
+
all = JSON.parse res.body
|
28
|
+
all.each do |a|
|
29
|
+
puts getinfo(a)
|
30
|
+
end
|
31
|
+
else
|
32
|
+
puts "#{res.inspect}".colorize :red
|
33
|
+
puts "#{res.body}".colorize :red
|
34
|
+
return back
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def getinfo(pad)
|
39
|
+
res = @token.get "/api/1.0/pad/#{pad}/content.txt"
|
40
|
+
if res.is_a? Net::HTTPSuccess
|
41
|
+
puts "#{@config['site']}/#{pad} - #{res.body.lines.first.chomp}"
|
42
|
+
else
|
43
|
+
puts "#{pad} failed".colorize :red
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def show(pad,format)
|
48
|
+
ext = (format == 'md') ? 'html' : format
|
49
|
+
res = @token.get "/api/1.0/pad/#{pad}/content.#{ext}"
|
50
|
+
if res.is_a? Net::HTTPSuccess
|
51
|
+
puts "#{@config['site']}/#{pad}"
|
52
|
+
puts
|
53
|
+
if format == 'md'
|
54
|
+
puts ReverseMarkdown.convert(res.body, github_flavored: true)
|
55
|
+
else
|
56
|
+
puts res.body
|
57
|
+
end
|
58
|
+
else
|
59
|
+
puts "#{pad} failed".colorize :red
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Hackpad
|
2
|
+
module Config
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def load(dir = nil)
|
6
|
+
if !Dir.exists?(conf_dir dir) || !File.exists?(conf_file)
|
7
|
+
setup conf_dir dir
|
8
|
+
end
|
9
|
+
YAML::load_file conf_file
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def setup(dir)
|
15
|
+
config = {}
|
16
|
+
FileUtils.mkdir_p dir
|
17
|
+
puts "We need first to initialize your hackpad-cli configuration.".colorize(:blue)
|
18
|
+
puts "Please gather your information from https://<subdomain>.hackpad.com/ep/account/settings/"
|
19
|
+
print "What is your Client ID? "
|
20
|
+
STDOUT.flush
|
21
|
+
config['client_id'] = STDIN.gets.chomp
|
22
|
+
print "What is your Secret Key? "
|
23
|
+
STDOUT.flush
|
24
|
+
config['secret'] = STDIN.gets.chomp
|
25
|
+
print "What is the URI of your pad? "
|
26
|
+
STDOUT.flush
|
27
|
+
config['site'] = STDIN.gets.chomp
|
28
|
+
File.open(conf_file, "w") do |f|
|
29
|
+
f.write YAML::dump(config)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def conf_file
|
34
|
+
File.join(conf_dir, 'config.yml')
|
35
|
+
end
|
36
|
+
|
37
|
+
def conf_dir(dir = "#{ENV["HOME"]}/.hackpad-cli/")
|
38
|
+
dir
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hackpad-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mose
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: colorize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: oauth
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: reverse_markdown
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.5'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.5'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: A Command Line Interface for consuming the Hackpad REST API.
|
98
|
+
email:
|
99
|
+
- mose@mose.com
|
100
|
+
executables:
|
101
|
+
- hpcli
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".ruby-gemset"
|
107
|
+
- ".ruby-version"
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/hpcli
|
113
|
+
- hackpad-cli.gemspec
|
114
|
+
- lib/hackpad/cli.rb
|
115
|
+
- lib/hackpad/cli/version.rb
|
116
|
+
- lib/hackpad/client.rb
|
117
|
+
- lib/hackpad/config.rb
|
118
|
+
- lib/hackpad/store.rb
|
119
|
+
homepage: ''
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 2.2.2
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: CLI for hackpad browsing and editing.
|
143
|
+
test_files: []
|