hackpad-cli 0.0.7 → 0.1.0

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: 7daab4b137edd9a8b347ea91aa5f3b2b274d62cf
4
- data.tar.gz: 0a6ea6f6ff546036118c9a92e5517e2f590e9c5f
3
+ metadata.gz: 75ec97eebdcae4ec244fa66f3275faa0b7f0db0c
4
+ data.tar.gz: 8190edde668cfaf92831a30ca7b5ce83d77228e3
5
5
  SHA512:
6
- metadata.gz: 0888040ce658299976f0d38216665e7839df805a7c24e581cfce30623d91758d3243a275c9e84cb1f252e7c66e8e501132b709dd670ba942e98f5a560a9b1763
7
- data.tar.gz: c5d33ee8c511411f82705a8e5a7c76f71956dffd7024f90388b3b99f7397b0c5ac1c90ecae7afd1fb56e90a647dde505d1bf38770f4b9db8518d2949bd53a252
6
+ metadata.gz: e44e5752085dc49e72dff125796dc0ece1b44538927020d092f032552c228d35d2dc3c301b79b6f2decc4eff6dc1d6cf50645745699770bde3be2c8810eb6198
7
+ data.tar.gz: 4b7d16c5a5bd6055cbbb291f6e8b7fc484cdafd2dfa996f52bae62443ec06b2ff5a140ca787daf7ba7539039f60a0b9b5b859c0647f95285b1d3a025f1258e33
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ LineLength:
2
+ Max: 122
3
+ MethodLength:
4
+ Max: 16
5
+ Documentation:
6
+ Enabled: false
7
+ AlignHash:
8
+ Enabled: false
9
+ IndentHash:
10
+ Enabled: false
11
+ AlignParameters:
12
+ Enabled: false
13
+ EmptyLinesAroundBody:
14
+ Enabled: false
data/.travis.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
+ bundler_args: --path vendor
2
3
  cache: bundler
3
4
  rvm:
4
5
  - 1.9.3
data/CHANGELOG.md CHANGED
@@ -1,21 +1,31 @@
1
1
  Hackpad-cli changelog
2
- ==========================
2
+ =====================
3
+
4
+ v0.1.0 - 2014-05-17
5
+ -------------------
6
+
7
+ - add a `stats` command to show how much pads are cached, and when it was last refreshed
8
+ - move `-r` (refresh) and `-u` (urls) options to specific method options
9
+ - add a User-Agent so that hackpad knows what is poking them
10
+ - completed test coverage
11
+ - prevent trailing slash on site config param to fuck up urls
12
+ - useless but satisfying rubocop green flag
3
13
 
4
14
  v0.0.7 - 2014-05-15
5
- -------------
15
+ -------------------
6
16
 
7
17
  - add a `cached_at` value in metadata, visible in the `show` command
8
18
  - fix `info` to display guest policy properly
9
- - add a `check` command to check if there are new pads and dcide to refresh or not
19
+ - add a `check` command to check if there are new pads and decide to refresh or not
10
20
  - whole lot of more tests
11
21
 
12
22
  v0.0.6 - 2014-05-04
13
- ------------
23
+ -------------------
14
24
 
15
25
  - fix compat with 1.9.3 (require ostruct)
16
26
 
17
27
  v0.0.5 - 2014-05-04
18
- --------------------
28
+ -------------------
19
29
 
20
30
  - add a dot-timer for when padlist refreshes so one knows that something is happening
21
31
  - add an option `-u` to display urls rather than pad id
@@ -25,13 +35,13 @@ v0.0.5 - 2014-05-04
25
35
  - add a flag for removing colors `-p`
26
36
 
27
37
  v0.0.4 - 2014-05-01
28
- --------------------
38
+ -------------------
29
39
 
30
40
  - add options in pad info for `hpcli info [pad_id]`
31
41
  - implement a search command `hpcli search [term]`
32
42
 
33
43
  v0.0.3 - 2014-05-01
34
- --------------
44
+ -------------------
35
45
 
36
46
  - add a better way to manage alternative configuration file
37
47
  - fix alternate config dir setup
@@ -39,11 +49,11 @@ v0.0.3 - 2014-05-01
39
49
  - better readme
40
50
 
41
51
  v0.0.2 - 2014-05-01
42
- ---------------
52
+ -------------------
43
53
 
44
54
  - damn, forgot to remove awesome_print. huhu
45
55
 
46
56
  v0.0.1 - 2014-05-01
47
- ------------------------
57
+ -------------------
48
58
 
49
59
  - initial release of a draft
data/README.md CHANGED
@@ -33,6 +33,8 @@ or
33
33
  cd hackpad-cli
34
34
  bundle install
35
35
 
36
+ Then you will have to launch it once and it will ask you some questions. you can find your client_id and secret at https://<subdomain>.hackpad.com/ep/account/settings/ (your subdomain is where you store the pads).
37
+
36
38
  Usage
37
39
  ---------------
38
40
 
@@ -40,22 +42,21 @@ Usage
40
42
 
41
43
  ```
42
44
  Commands:
43
- hpcli check # Checks differences between local cache and remote list.
45
+ hpcli check # Checks differences between local cache and remote list (options: -u to show urls).
44
46
  hpcli help [COMMAND] # Describe available commands or one specific command
45
47
  hpcli info [pad_id] # gets info for the pad <pad_id>.
46
- hpcli list # Lists available pads.
47
- hpcli search [term] # Lists available pads matching [term].
48
- hpcli show [pad_id] [format] # shows pad <pad_id> in format [html,txt,md] (default txt).
48
+ hpcli list # Lists available pads (options: -u to show urls, -r to refresh).
49
+ hpcli search [term] # Lists available pads matching [term] (options: -u to show urls)
50
+ hpcli show [pad_id] [format] # shows pad <pad_id> in format [html,txt,md] (default txt) (options: -r to refresh).
51
+ hpcli stats # Lists configuration values.
49
52
  hpcli version # Displays the hackpad-cli version.
50
53
 
51
54
  Options:
52
- -c, [--configdir=CONFIGDIR] # Path to the hackpad-cli directory to use.
53
- # Default: /home/mose/.hackpad-cli/
54
- -w, [--workspace=WORKSPACE] # Name of the workspace to use.
55
- # Default: default
56
- -r, [--refresh], [--no-refresh] # Add this if you want refresh the cache.
57
- -u, [--urls], [--no-urls] # Displays urls rather than pad ids.
58
- -p, [--plain], [--no-plain] # Add this if you don't want colors.
55
+ -c, [--configdir=CONFIGDIR] # Path to the hackpad-cli directory to use.
56
+ # Default: /home/mose/.hackpad-cli/
57
+ -w, [--workspace=WORKSPACE] # Name of the workspace to use.
58
+ # Default: default
59
+ -p, [--plain], [--no-plain] # Add this if you don't want colors.
59
60
  ```
60
61
 
61
62
  At first launch it will create your config dir (default ~/.hackpad-cli/), and will ask you questions to create the config file (default is .. default.yml). If you pass the `-w whatever` option at the end, it will ask questions again to write whatever.yml config file.
@@ -66,12 +67,12 @@ Roadmap and todoz
66
67
 
67
68
  Check the [Changelog](CHANGELOG.md) for past evolutions.
68
69
 
69
- - for v0.1.0
70
+ - <s>for v0.1.0</s>
70
71
  - <s>add freaking cool badges on the readme</s>
71
72
  - <s>cache the pads list in a local storage</s>
72
73
  - <s>have a choice to refresh cache</s>
73
74
  - <s>display cached date in output</s>
74
- - write proper tests
75
+ - <s>write proper tests</s>
75
76
  - for v0.2.0
76
77
  - add commands for creating a new pad, linked to $EDITOR
77
78
  - add a gateway to github so a pad could be copied over a wiki page directly or in a repo somehow
data/Rakefile CHANGED
@@ -5,16 +5,16 @@ rescue LoadError
5
5
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
6
  end
7
7
  require 'bundler/setup'
8
- require "bundler/gem_tasks"
9
- require "rake/testtask"
10
- require "rspec/core/rake_task" # RSpec 2.0
8
+ require 'bundler/gem_tasks'
9
+ require 'rake/testtask'
10
+ require 'rspec/core/rake_task' # RSpec 2.0
11
11
 
12
- desc "launch rspec tests"
12
+ desc 'launch rspec tests'
13
13
  task :spec do
14
14
  RSpec::Core::RakeTask.new(:spec) do |t|
15
- t.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
15
+ t.rspec_opts = ['-c', '-f progress', '-r ./spec/spec_helper.rb']
16
16
  t.pattern = 'spec/lib/**/*_spec.rb'
17
17
  end
18
18
  end
19
19
 
20
- task :default => :spec
20
+ task default: :spec
data/bin/hpcli CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require_relative "../lib/hackpad/cli/runner"
3
+ require_relative '../lib/hackpad/cli/runner'
4
4
 
5
5
  Hackpad::Cli::Runner.start
data/hackpad-cli.gemspec CHANGED
@@ -4,29 +4,29 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'hackpad/cli/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "hackpad-cli"
7
+ spec.name = 'hackpad-cli'
8
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 = "https://github.com/mose/hackpad-cli"
14
- spec.license = "MIT"
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 = 'https://github.com/mose/hackpad-cli'
14
+ spec.license = 'MIT'
15
15
 
16
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"]
17
+ spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(/^spec\//)
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency "thor"
22
- spec.add_dependency "colorize"
23
- spec.add_dependency "oauth"
24
- spec.add_dependency "reverse_markdown"
21
+ spec.add_dependency 'thor'
22
+ spec.add_dependency 'colorize'
23
+ spec.add_dependency 'oauth'
24
+ spec.add_dependency 'reverse_markdown'
25
25
 
26
- spec.add_development_dependency "bundler", "~> 1.5"
27
- spec.add_development_dependency "rake"
28
- spec.add_development_dependency "rspec"
29
- spec.add_development_dependency "webmock"
30
- spec.add_development_dependency "coveralls"
31
- spec.add_development_dependency "codeclimate-test-reporter"
26
+ spec.add_development_dependency 'bundler', '~> 1.5'
27
+ spec.add_development_dependency 'rake'
28
+ spec.add_development_dependency 'rspec'
29
+ spec.add_development_dependency 'webmock'
30
+ spec.add_development_dependency 'coveralls'
31
+ spec.add_development_dependency 'codeclimate-test-reporter'
32
32
  end
@@ -9,10 +9,9 @@ module Hackpad
9
9
  end
10
10
 
11
11
  module Api
12
- extend self
12
+ module_function
13
13
 
14
14
  def prepare(config)
15
- site = URI.parse config['site']
16
15
  consumer = OAuth::Consumer.new(
17
16
  config['client_id'],
18
17
  config['secret'],
@@ -21,16 +20,12 @@ module Hackpad
21
20
  @token = OAuth::AccessToken.new consumer
22
21
  end
23
22
 
24
- def search(term, start=0)
23
+ def search(term, start = 0)
25
24
  get "/api/1.0/search?q=#{CGI.escape term}&start=#{start}&limit=100"
26
25
  end
27
26
 
28
27
  def list
29
- get "/api/1.0/pads/all"
30
- end
31
-
32
- def title(id)
33
- show(id, 'txt').lines.first
28
+ get '/api/1.0/pads/all'
34
29
  end
35
30
 
36
31
  def read_options(id)
@@ -41,17 +36,12 @@ module Hackpad
41
36
  get "/api/1.0/pad/#{id}/content.#{ext}", false
42
37
  end
43
38
 
44
- def get(url, json=true)
45
- res = @token.get url
39
+ def get(url, json = true)
40
+ res = @token.get url, 'User-Agent' => "hackpad-cli v#{Hackpad::Cli::VERSION}"
46
41
  if res.is_a? Net::HTTPSuccess
47
- puts res.body.inspect if ENV['DEBUG']
48
- if json
49
- JSON.parse res.body
50
- else
51
- res.body
52
- end
42
+ json ? JSON.parse(res.body) : res.body
53
43
  else
54
- raise ApiException, "HTTP error, code #{res.code}"
44
+ fail ApiException, "HTTP error, code #{res.code}"
55
45
  end
56
46
  end
57
47
 
@@ -11,7 +11,7 @@ module Hackpad
11
11
  module Cli
12
12
  class Client
13
13
 
14
- def initialize(options, output=STDOUT)
14
+ def initialize(options, output = STDOUT)
15
15
  @output = output
16
16
  @options = options
17
17
  Store.prepare @options
@@ -22,11 +22,16 @@ module Hackpad
22
22
  end
23
23
  end
24
24
 
25
- # GET /api/1.0/pads/all
26
- def search(term,start=0)
27
- payload = Api.search(term,start)
25
+ def stats
26
+ table 'Site', @config['site'].blue
27
+ table 'Cached Pads', Store.count_pads
28
+ table 'Last Refresh', Store.last_refresh || 'not refreshed yet'
29
+ end
30
+
31
+ def search(term, start = 0)
32
+ payload = Api.search(term, start)
28
33
  payload.each do |a|
29
- @output.puts "#{(@config['site'] + '/') if @options[:urls]}#{a['id'].bold} - #{unescape(a['title']).yellow}"
34
+ @output.puts "#{id_or_url a['id']} - #{unescape(a['title']).yellow}"
30
35
  @output.puts " #{extract a['snippet']}"
31
36
  end
32
37
  end
@@ -38,10 +43,10 @@ module Hackpad
38
43
  end
39
44
 
40
45
  def check
41
- @output.puts "New pads:"
42
- padlist = Padlist.check_list.map
46
+ @output.puts 'New pads:'
47
+ padlist = Padlist.check_list(@options['refresh']).map
43
48
  if padlist.count == 0
44
- @output.puts "There is no new pad."
49
+ @output.puts 'There is no new pad.'
45
50
  else
46
51
  @output.puts padlist.map { |pad|
47
52
  padline pad
@@ -52,17 +57,17 @@ module Hackpad
52
57
  def info(id)
53
58
  pad = Pad.new id
54
59
  pad.load 'txt'
55
- table "Id", "#{id}".bold
56
- table "Title", "#{pad.title}".yellow
57
- table "URI", "#{@config['site']}/#{id}"
58
- table "Chars", "#{pad.chars}"
59
- table "Lines", "#{pad.lines}"
60
- table "Guest Policy", "#{pad.guest_policy}"
61
- table "Moderated", "#{pad.moderated}"
62
- table "Cached", "#{pad.cached_at || 'unknown'}"
60
+ table 'Id', "#{id}".bold
61
+ table 'Title', "#{pad.title}".yellow
62
+ table 'URI', "#{@config['site']}/#{id}"
63
+ table 'Chars', "#{pad.chars}"
64
+ table 'Lines', "#{pad.lines}"
65
+ table 'Guest Policy', "#{pad.guest_policy}"
66
+ table 'Moderated', "#{pad.moderated}"
67
+ table 'Cached', "#{pad.cached_at || 'unknown'}"
63
68
  end
64
69
 
65
- def show(id,format)
70
+ def show(id, format)
66
71
  ext = (format == 'md') ? 'html' : format
67
72
  pad = Pad.new id
68
73
  pad.load ext
@@ -73,7 +78,7 @@ module Hackpad
73
78
  end
74
79
  end
75
80
 
76
- private
81
+ private
77
82
 
78
83
  def padline(pad)
79
84
  "#{(@config['site'] + '/') if @options[:urls]}#{pad.id} - #{pad.title}"
@@ -84,13 +89,17 @@ module Hackpad
84
89
  end
85
90
 
86
91
  def extract(s)
87
- unescape(s).gsub(/<b class="hit">([^<]*)<\/b>/) { |e| $1.cyan.bold }
92
+ unescape(s).gsub(/<b class="hit">([^<]*)<\/b>/) { Regexp.last_match[1].cyan.bold }
88
93
  end
89
94
 
90
- def table(key,value)
95
+ def table(key, value)
91
96
  @output.printf "%-20s %s\n", key, value
92
97
  end
93
98
 
99
+ def id_or_url(id)
100
+ "#{(@config['site'] + '/') if @options[:urls]}#{id.bold}"
101
+ end
102
+
94
103
  end
95
104
  end
96
105
  end
@@ -3,44 +3,39 @@ require 'colorize'
3
3
  module Hackpad
4
4
  module Cli
5
5
  module Config
6
- extend self
6
+ module_function
7
7
 
8
- def load(options, input=STDIN, output=STDOUT)
8
+ def load(options, input = STDIN, output = STDOUT)
9
9
  @input = input
10
10
  @output = output
11
11
  configdir = options[:configdir]
12
12
  configfile = File.join(configdir, "#{options[:workspace]}.yml")
13
- # temporary migration path
14
- if !File.exists?(configfile) && File.exists?(File.join(configdir, "config.yml"))
15
- FileUtils.mv File.join(configdir, "config.yml"), configfile
16
- end
17
- if !Dir.exists?(configdir) || !File.exists?(configfile)
13
+ if !Dir.exist?(configdir) || !File.exist?(configfile)
18
14
  setup configfile, input, output
19
15
  end
20
- YAML::load_file configfile
16
+ YAML.load_file configfile
21
17
  end
22
18
 
23
- private
24
-
25
- def setup(configfile, input=STDIN, output=STDOUT)
19
+ def setup(configfile, input = STDIN, output = STDOUT)
26
20
  config = {}
27
21
  FileUtils.mkdir_p File.dirname(configfile)
28
- output.puts "We need first to initialize your hackpad-cli configuration.".blue
29
- output.puts "Please gather your information from https://<subdomain>.hackpad.com/ep/account/settings/".light_blue
30
- output.print "What is your Client ID? "
31
- config['client_id'] = input.gets.chomp
32
- output.flush
33
- output.print "What is your Secret Key? "
34
- output.flush
35
- config['secret'] = input.gets.chomp
36
- output.print "What is the URI of your pad? "
37
- output.flush
38
- config['site'] = input.gets.chomp
39
- File.open(configfile, "w") do |f|
40
- f.write YAML::dump(config)
22
+ output.puts 'We need first to initialize your hackpad-cli configuration.'.blue
23
+ output.puts 'Please gather your information from https://<subdomain>.hackpad.com/ep/account/settings/'.light_blue
24
+ config['client_id'] = ask 'What is your Client ID?', input, output
25
+ config['secret'] = ask 'What is your Secret Key?', input, output
26
+ config['site'] = ask('What is the URI of your pad?', input, output).gsub(/\/$/, '')
27
+ File.open(configfile, 'w') do |f|
28
+ f.write YAML.dump(config)
41
29
  end
42
30
  end
43
31
 
32
+ def ask(question, input, output)
33
+ output.print "#{question} "
34
+ back = input.gets.chomp
35
+ output.flush
36
+ back
37
+ end
38
+
44
39
  end
45
40
  end
46
41
  end