summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZack Hobson2013-12-27 10:15:59 -0800
committerZack Hobson2013-12-27 10:15:59 -0800
commit40610cb63b577bed614bc6d5348dfde1ba66e26f (patch)
tree8a8cbbf23c56b4847587e5963886a7f39dbbe5a2
parent51236213fdf0a62d2795e2a3c341e87ab8d83117 (diff)
parentf0eee83fcdf3047674db3310f2847704021e54e1 (diff)
downloadhcl-40610cb63b577bed614bc6d5348dfde1ba66e26f.tar.bz2
Merge branch 'master' into resource_routes
-rw-r--r--CHANGELOG3
-rw-r--r--Gemfile.lock1
-rw-r--r--README.markdown19
-rw-r--r--hcl.gemspec1
-rw-r--r--lib/hcl.rb1
-rw-r--r--lib/hcl/commands.rb6
-rw-r--r--lib/hcl/console.rb19
7 files changed, 49 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 7a7d747..3e091c7 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,7 +2,8 @@
== next version
-* addded `config` command to display current credentials
+* added `config` command to display current credentials
+* added `console` command for exploring the Harvest API
== v0.4.9 2013-12-21
diff --git a/Gemfile.lock b/Gemfile.lock
index 362ea92..fe0c913 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -6,6 +6,7 @@ PATH
escape_utils
faraday
highline
+ pry
trollop
yajl-ruby
diff --git a/README.markdown b/README.markdown
index e898cb9..6c185aa 100644
--- a/README.markdown
+++ b/README.markdown
@@ -137,6 +137,25 @@ Adding something like the above to your bashrc will enable a new command,
`myhcl`. When using `myhcl` you can use different credentials and aliases,
while `hcl` will continue to function with your original configuration.
+### Interactive console
+
+An interactive Ruby console is provided to allow you to use the fairly
+powerful Harvest API client built into HCl, since not all of its
+features are exposed via the command line. The current {HCl::App}
+instance is available as `hcl`.
+
+It's also possible to issue HCl commands directly (as Ruby methods), or
+to query specific JSON end points and have the results pretty-printed:
+
+ hcl console
+ bin/hcl> show "yesterday"
+ # => prints yesterday's timesheet, note the quotes!
+ bin/hcl> Net.get('daily')
+ # => displays a pretty-printed version of the JSON output
+
+Note that unlike the commands themselves, the HCl internals may change without
+notice.
+
### Date Formats
Dates can be expressed in a variety of ways. See the [Chronic documentation][cd]
diff --git a/hcl.gemspec b/hcl.gemspec
index 7dd0fd8..cf1c615 100644
--- a/hcl.gemspec
+++ b/hcl.gemspec
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'faraday'
s.add_runtime_dependency 'yajl-ruby'
s.add_runtime_dependency 'escape_utils'
+ s.add_runtime_dependency 'pry'
s.add_development_dependency 'rake'
s.add_development_dependency 'rubygems-tasks'
s.add_development_dependency 'mocha'
diff --git a/lib/hcl.rb b/lib/hcl.rb
index 5d6f108..b041538 100644
--- a/lib/hcl.rb
+++ b/lib/hcl.rb
@@ -3,6 +3,7 @@ module HCl
autoload :App, 'hcl/app'
autoload :Net, 'hcl/net'
autoload :Commands, 'hcl/commands'
+ autoload :Console, 'hcl/console'
autoload :TimesheetResource, 'hcl/timesheet_resource'
autoload :Utility, 'hcl/utility'
autoload :Project, 'hcl/project'
diff --git a/lib/hcl/commands.rb b/lib/hcl/commands.rb
index 08d8a1e..834ba2c 100644
--- a/lib/hcl/commands.rb
+++ b/lib/hcl/commands.rb
@@ -1,5 +1,6 @@
require 'chronic'
require 'highline'
+require 'pry'
module HCl
module Commands
@@ -10,6 +11,11 @@ module HCl
Net.config_hash.merge(password:'***').map {|k,v| "#{k}: #{v}" }.join("\n")
end
+ def console
+ Console.new(self)
+ nil
+ end
+
def tasks project_code=nil
tasks = Task.all
if tasks.empty? # cache tasks
diff --git a/lib/hcl/console.rb b/lib/hcl/console.rb
new file mode 100644
index 0000000..da0f7c5
--- /dev/null
+++ b/lib/hcl/console.rb
@@ -0,0 +1,19 @@
+require 'pp'
+
+module HCl
+ class Console
+ attr_reader :hcl
+ def initialize app
+ @hcl = app
+ binding.pry quiet: true,
+ prompt:[->(a,b,c){"#{$PROGRAM_NAME}> "}],
+ print:->(io, *p){ pp p }
+ end
+
+ Commands.instance_methods.each do |command|
+ define_method command do |*args|
+ puts @hcl.send(command, *args)
+ end
+ end
+ end
+end