toggl 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.
- data/LICENSE +20 -0
- data/README.rdoc +20 -0
- data/bin/toggl +10 -0
- data/lib/toggl.rb +81 -0
- data/lib/toggl_cmd/runner.rb +19 -0
- data/lib/toggl_cmd/runner_options.rb +43 -0
- metadata +79 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Koen Van der Auwera
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
= toggl
|
2
|
+
|
3
|
+
Toggl API wrapper in a Ruby gem
|
4
|
+
|
5
|
+
https://www.toggl.com
|
6
|
+
https://www.toggl.com/public/api
|
7
|
+
|
8
|
+
== Note on Patches/Pull Requests
|
9
|
+
|
10
|
+
* Fork the project.
|
11
|
+
* Make your feature addition or bug fix.
|
12
|
+
* Add tests for it. This is important so I don't break it in a
|
13
|
+
future version unintentionally.
|
14
|
+
* Commit, do not mess with rakefile, version, or history.
|
15
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
16
|
+
* Send me a pull request. Bonus points for topic branches.
|
17
|
+
|
18
|
+
== Copyright
|
19
|
+
|
20
|
+
Copyright (c) 2010 Koen Van der Auwera. See LICENSE for details.
|
data/bin/toggl
ADDED
data/lib/toggl.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "httparty"
|
3
|
+
require "chronic_duration"
|
4
|
+
|
5
|
+
class Toggl
|
6
|
+
include HTTParty
|
7
|
+
base_uri "https://toggl.com"
|
8
|
+
format :json
|
9
|
+
# debug_output
|
10
|
+
|
11
|
+
attr_reader :name
|
12
|
+
|
13
|
+
def initialize(token, name="toggl-gem")
|
14
|
+
self.class.default_params :output => 'json', :api_token => token
|
15
|
+
@name = name
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_task(params={})
|
19
|
+
workspace = params[:workspace] || default_workspace_id
|
20
|
+
project_id = find_project_id(params[:project]) || create_project(params, workspace)
|
21
|
+
|
22
|
+
params.merge!({ :created_with => name,
|
23
|
+
:workspace => {:id => workspace},
|
24
|
+
:project => {:id => project_id},
|
25
|
+
:tag_names => [name],
|
26
|
+
:start => start(params[:start]),
|
27
|
+
:duration => duration(params[:duration])})
|
28
|
+
|
29
|
+
self.class.post("/api/tasks.json", :body => {:task => params})
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_project(params={}, workspace=nil)
|
33
|
+
workspace ||= default_workspace_id
|
34
|
+
if project = self.class.post("/api/projects.json", :body => {
|
35
|
+
:project => {:name => params[:project],
|
36
|
+
:workspace => {:id => workspace},
|
37
|
+
:billable => (params[:billable] || true)}})
|
38
|
+
project["id"]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def default_workspace_id
|
43
|
+
self.workspaces.first["id"]
|
44
|
+
end
|
45
|
+
|
46
|
+
def find_project_id(str)
|
47
|
+
if project = self.projects.find{|project| project["client_project_name"].downcase =~ /#{str}/}
|
48
|
+
project["id"]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def duration(str)
|
53
|
+
str ? ChronicDuration.parse(str) : 1800
|
54
|
+
end
|
55
|
+
|
56
|
+
def start(value)
|
57
|
+
if value
|
58
|
+
case value
|
59
|
+
when "today" : Date.today
|
60
|
+
when "yesterday": Date.today - 1
|
61
|
+
when "tomorrow" : Date.today + 1
|
62
|
+
else
|
63
|
+
DateTime.parse(value)
|
64
|
+
end
|
65
|
+
else
|
66
|
+
DateTime.now
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def workspaces
|
71
|
+
self.class.get("/api/workspaces.json")
|
72
|
+
end
|
73
|
+
|
74
|
+
def tasks
|
75
|
+
self.class.get("/api/tasks.json")
|
76
|
+
end
|
77
|
+
|
78
|
+
def projects
|
79
|
+
self.class.get("/api/projects.json")
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "optparse"
|
2
|
+
|
3
|
+
module TogglCmd
|
4
|
+
|
5
|
+
class Runner
|
6
|
+
|
7
|
+
def self.toggl(args)
|
8
|
+
options = RunnerOptions.new(args)
|
9
|
+
if options.any?
|
10
|
+
token = IO.readlines(File.expand_path("~/.toggl")).join
|
11
|
+
Toggl.new(token).create_task(options)
|
12
|
+
else
|
13
|
+
puts options.opts
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module TogglCmd
|
2
|
+
|
3
|
+
class RunnerOptions < Hash
|
4
|
+
attr_reader :opts
|
5
|
+
|
6
|
+
def initialize(args)
|
7
|
+
super()
|
8
|
+
|
9
|
+
@opts = OptionParser.new do |o|
|
10
|
+
o.banner = "Usage: #{File.basename($0)} [options]"
|
11
|
+
|
12
|
+
o.on('-t', '--title TITLE', 'What do you want to register?') do |title|
|
13
|
+
self[:description] = title
|
14
|
+
end
|
15
|
+
|
16
|
+
o.on('-p', '--project PROJECT', 'Who is going to pay?') do |project|
|
17
|
+
self[:project] = project
|
18
|
+
end
|
19
|
+
|
20
|
+
o.on('-s', '--duration DURATION', 'How long did it take?') do |duration|
|
21
|
+
self[:duration] = duration
|
22
|
+
end
|
23
|
+
|
24
|
+
o.on('-d', '--date DATE', 'When exactly did it happen?') do |date|
|
25
|
+
self[:start] = date
|
26
|
+
end
|
27
|
+
|
28
|
+
o.on_tail('-h', '--help', 'Display this help and exit') do
|
29
|
+
puts @opts
|
30
|
+
exit
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
begin
|
36
|
+
@opts.parse!(args)
|
37
|
+
rescue OptionParser::InvalidOption => e
|
38
|
+
self[:invalid_argument] = e.message
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: toggl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Koen Van der Auwera
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-02-23 00:00:00 +01:00
|
13
|
+
default_executable: toggl
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: httparty
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.5.2
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: chronic_duration
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.9.0
|
34
|
+
version:
|
35
|
+
description: Toggl provides a simple REST-style JSON API over standard HTTP - http://www.toggl.com
|
36
|
+
email: koen@atog.be
|
37
|
+
executables:
|
38
|
+
- toggl
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- lib/toggl.rb
|
46
|
+
- lib/toggl_cmd/runner.rb
|
47
|
+
- lib/toggl_cmd/runner_options.rb
|
48
|
+
- LICENSE
|
49
|
+
- README.rdoc
|
50
|
+
has_rdoc: true
|
51
|
+
homepage: http://github.com/atog/toggl
|
52
|
+
licenses: []
|
53
|
+
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options:
|
56
|
+
- --charset=UTF-8
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: "0"
|
70
|
+
version:
|
71
|
+
requirements: []
|
72
|
+
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.3.5
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: Toggl api ruby gem
|
78
|
+
test_files: []
|
79
|
+
|