toggl 0.1.0 → 0.1.1

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/README.rdoc CHANGED
@@ -3,17 +3,14 @@
3
3
  Toggl API wrapper in a Ruby gem
4
4
 
5
5
  https://www.toggl.com
6
+
6
7
  https://www.toggl.com/public/api
7
8
 
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.
9
+ == toggl command
10
+
11
+ If you want to create new tasks from the command line, make sure you create ~/.toggl file containing nothing but your API key.
12
+
13
+ run 'toggl' to see all options.
17
14
 
18
15
  == Copyright
19
16
 
data/lib/toggl.rb CHANGED
@@ -6,18 +6,20 @@ class Toggl
6
6
  include HTTParty
7
7
  base_uri "https://toggl.com"
8
8
  format :json
9
- # debug_output
10
9
 
11
- attr_reader :name
10
+ attr_reader :name, :api_token
12
11
 
13
- def initialize(token, name="toggl-gem")
14
- self.class.default_params :output => 'json', :api_token => token
12
+ def initialize(token, name="toggl-gem", debug=false)
13
+ self.class.default_params :output => 'json'
14
+ @api_token = token
15
15
  @name = name
16
+ self.class.debug_output if debug
16
17
  end
17
18
 
18
19
  def create_task(params={})
19
20
  workspace = params[:workspace] || default_workspace_id
20
21
  project_id = find_project_id(params[:project]) || create_project(params, workspace)
22
+ params[:billable] = true
21
23
 
22
24
  params.merge!({ :created_with => name,
23
25
  :workspace => {:id => workspace},
@@ -26,15 +28,15 @@ class Toggl
26
28
  :start => start(params[:start]),
27
29
  :duration => duration(params[:duration])})
28
30
 
29
- self.class.post("/api/tasks.json", :body => {:task => params})
31
+ post 'tasks', {:task => params}
30
32
  end
31
33
 
32
34
  def create_project(params={}, workspace=nil)
33
35
  workspace ||= default_workspace_id
34
- if project = self.class.post("/api/projects.json", :body => {
36
+ if project = post("projects",
35
37
  :project => {:name => params[:project],
36
38
  :workspace => {:id => workspace},
37
- :billable => (params[:billable] || true)}})
39
+ :billable => (params[:billable] || true)})
38
40
  project["id"]
39
41
  end
40
42
  end
@@ -68,14 +70,29 @@ class Toggl
68
70
  end
69
71
 
70
72
  def workspaces
71
- self.class.get("/api/workspaces.json")
73
+ get 'workspaces'
72
74
  end
73
75
 
74
76
  def tasks
75
- self.class.get("/api/tasks.json")
77
+ get 'tasks'
76
78
  end
77
79
 
78
80
  def projects
79
- self.class.get("/api/projects.json")
81
+ get 'projects'
80
82
  end
81
- end
83
+
84
+ private
85
+
86
+ def get(resource_name)
87
+ self.class.get("/api/v1/#{resource_name}.json", :basic_auth => basic_auth)
88
+ end
89
+
90
+ def post(resource_name, data)
91
+ self.class.post("/api/v1/#{resource_name}.json", :body => data, :basic_auth => basic_auth)
92
+ end
93
+
94
+ def basic_auth
95
+ {:username => self.api_token, :password => "api_token"}
96
+ end
97
+
98
+ end
@@ -8,7 +8,7 @@ module TogglCmd
8
8
  options = RunnerOptions.new(args)
9
9
  if options.any?
10
10
  token = IO.readlines(File.expand_path("~/.toggl")).join
11
- Toggl.new(token).create_task(options)
11
+ Toggl.new(token, "toggl-gem", options.delete(:debug)).create_task(options)
12
12
  else
13
13
  puts options.opts
14
14
  end
@@ -25,6 +25,10 @@ module TogglCmd
25
25
  self[:start] = date
26
26
  end
27
27
 
28
+ o.on('-v', '--verbose', 'What\'s happening?') do |debug|
29
+ self[:debug] = debug
30
+ end
31
+
28
32
  o.on_tail('-h', '--help', 'Display this help and exit') do
29
33
  puts @opts
30
34
  exit
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toggl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koen Van der Auwera
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-23 00:00:00 +01:00
12
+ date: 2010-02-25 00:00:00 +01:00
13
13
  default_executable: toggl
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency