wakatime 0.0.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.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +59 -0
- data/Rakefile +15 -0
- data/lib/wakatime.rb +9 -0
- data/lib/wakatime/client.rb +83 -0
- data/lib/wakatime/exceptions.rb +19 -0
- data/lib/wakatime/models/item.rb +10 -0
- data/lib/wakatime/session.rb +64 -0
- data/lib/wakatime/version.rb +3 -0
- data/spec/client_spec.rb +24 -0
- data/spec/fixtures/current_user.json +10 -0
- data/spec/fixtures/daily.json +166 -0
- data/spec/fixtures/plugins.json +18 -0
- data/spec/fixtures/summary.json +101 -0
- data/spec/integration/core_spec.rb +67 -0
- data/spec/session_spec.rb +48 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/support/account.example +2 -0
- data/spec/support/account.rb +7 -0
- data/wakatime.gemspec +30 -0
- metadata +204 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 89bbc6da32dfeaf171ba8b9c7e5cdad750623c50
|
4
|
+
data.tar.gz: facd85dbc3b653d15e5bf94af322d1eb5376c203
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 92c9785fc5d8bbc6a04383dafd8a6388018484af7e48dec378c741a74b05f2b98833710cc5cb4ee588a429dbde5619bb429f4564de3fa5da29b3fc157d142019
|
7
|
+
data.tar.gz: 525837f063c1aefb1b60ad87dcf6ae9f69f6fdb0f944d1ff3f9cbac8cd7836e3c03e4b205732dfc314a2531f42c7aed4828d48bc1e52b61af1f796e6d710dddb
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Russell Osborne
|
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,59 @@
|
|
1
|
+
# Wakatime Ruby
|
2
|
+
[](https://codeclimate.com/github/burningpony/wakatime)
|
3
|
+
[](https://travis-ci.org/burningpony/wakatime)
|
4
|
+
An Unofficial Wakatime Ruby API Client
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'wakatime'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install wakatime
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
@session = Wakatime::Session.new({
|
23
|
+
api_key: ENV['wakatime_api_key']
|
24
|
+
})
|
25
|
+
|
26
|
+
@client = Wakatime::Client.new(@session)
|
27
|
+
|
28
|
+
#### Summary
|
29
|
+
@client.summary
|
30
|
+
|
31
|
+
#### Daily Summary
|
32
|
+
@client.daily
|
33
|
+
|
34
|
+
#### Actions
|
35
|
+
@client.actions
|
36
|
+
|
37
|
+
#### Current User
|
38
|
+
@client.current_user
|
39
|
+
|
40
|
+
#### Plugin Data
|
41
|
+
@client.plugins
|
42
|
+
|
43
|
+
|
44
|
+
## Testing
|
45
|
+
|
46
|
+
1. Ensure your API Key is in a yaml file in spec/support/account.yml
|
47
|
+
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it ( https://github.com/burningpony/wakatime/fork )
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create a new Pull Request
|
56
|
+
|
57
|
+
## Credits
|
58
|
+
|
59
|
+
Massive Credit to [Ruby Box][https://github.com/attachmentsme/ruby-box] as being a template API client.
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require "bundler/gem_tasks"
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'rspec/core/rake_task'
|
15
|
+
RSpec::Core::RakeTask.new(:spec)
|
data/lib/wakatime.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/https'
|
3
|
+
require 'json'
|
4
|
+
require 'net/http/post/multipart'
|
5
|
+
require 'open-uri'
|
6
|
+
require 'cgi'
|
7
|
+
require 'active_support/inflector'
|
8
|
+
|
9
|
+
module Wakatime
|
10
|
+
class Client
|
11
|
+
def initialize(session)
|
12
|
+
@session = session
|
13
|
+
end
|
14
|
+
|
15
|
+
def summary(start_at = Time.now - 86400 , end_at = Time.now )
|
16
|
+
request_builder("summary", {:start => start_at, :end => end_at})
|
17
|
+
end
|
18
|
+
|
19
|
+
def daily(start_at = Time.now - 86400 , end_at = Time.now )
|
20
|
+
request_builder("summary/daily", {:start => start_at, :end => end_at})
|
21
|
+
end
|
22
|
+
|
23
|
+
def actions(params = {})
|
24
|
+
|
25
|
+
params[:start] ||= Time.now - 86400
|
26
|
+
params[:end] ||= Time.now
|
27
|
+
params[:show] ||= "file,branch,project,time"
|
28
|
+
|
29
|
+
request_builder("actions", params)
|
30
|
+
end
|
31
|
+
|
32
|
+
def plugins(params = {})
|
33
|
+
params[:show] ||= "name,version"
|
34
|
+
request_builder("plugins", params)
|
35
|
+
end
|
36
|
+
|
37
|
+
def current_user(params = {})
|
38
|
+
params[:show] ||= "email,timeout,last_plugin,timezone"
|
39
|
+
request_builder("users/current",params)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def cast_params(params)
|
45
|
+
casted_params = params.inject({}) { |h, (k, v)| h[k] = cast_param(v); h }
|
46
|
+
end
|
47
|
+
|
48
|
+
def cast_param(param)
|
49
|
+
case param.class.to_s
|
50
|
+
when "Time"
|
51
|
+
param.to_i
|
52
|
+
else
|
53
|
+
param
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def request_builder(action, params = {}, raw = false)
|
58
|
+
uri = Addressable::URI.new
|
59
|
+
uri.query_values = cast_params(params)
|
60
|
+
|
61
|
+
url = "#{Wakatime::API_URL}/#{action}?#{uri.query}"
|
62
|
+
response = @session.get( url )
|
63
|
+
|
64
|
+
if raw
|
65
|
+
response
|
66
|
+
else
|
67
|
+
response_factory(action, response)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def response_factory(action, response)
|
72
|
+
klass = Object.const_get("Wakatime::Models::#{action.split("/").first.singularize.classify}")
|
73
|
+
|
74
|
+
if response["data"].is_a? Hash
|
75
|
+
klass.new(response["data"])
|
76
|
+
else
|
77
|
+
response["data"].map do |attributes|
|
78
|
+
klass.new(attributes)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Wakatime
|
2
|
+
class WakatimeError < StandardError
|
3
|
+
attr_accessor :body, :status
|
4
|
+
|
5
|
+
def initialize(error_json, status, body)
|
6
|
+
@status = status
|
7
|
+
@body = body
|
8
|
+
@error_json = error_json
|
9
|
+
end
|
10
|
+
|
11
|
+
def [](key)
|
12
|
+
@error_json[key]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class AuthError < WakatimeError; end
|
17
|
+
class RequestError < WakatimeError; end
|
18
|
+
class ServerError < WakatimeError; end
|
19
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Wakatime
|
2
|
+
class Session
|
3
|
+
def initialize(opts={}, backoff=0.1)
|
4
|
+
@backoff = backoff # try not to excessively hammer API.
|
5
|
+
@api_key = opts[:api_key]
|
6
|
+
end
|
7
|
+
|
8
|
+
def get(url, raw=false)
|
9
|
+
uri = URI.parse(url)
|
10
|
+
request = Net::HTTP::Get.new( uri.request_uri )
|
11
|
+
resp = request( uri, request, raw )
|
12
|
+
end
|
13
|
+
|
14
|
+
def request(uri, request, raw=false, retries=0)
|
15
|
+
|
16
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
17
|
+
http.use_ssl = true
|
18
|
+
|
19
|
+
#http.set_debug_output($stdout)
|
20
|
+
request.add_field('Content-Type', 'application/json')
|
21
|
+
|
22
|
+
if @api_key
|
23
|
+
request.add_field('Authorization', "Basic #{Base64.strict_encode64( @api_key )}")#
|
24
|
+
end
|
25
|
+
|
26
|
+
response = http.request(request)
|
27
|
+
|
28
|
+
if response.is_a? Net::HTTPNotFound
|
29
|
+
raise Wakatime::ObjectNotFound
|
30
|
+
end
|
31
|
+
|
32
|
+
sleep(@backoff) # try not to excessively hammer API.
|
33
|
+
|
34
|
+
handle_errors( response, raw )
|
35
|
+
end
|
36
|
+
|
37
|
+
def handle_errors( response, raw )
|
38
|
+
status = response.code.to_i
|
39
|
+
body = response.body
|
40
|
+
begin
|
41
|
+
parsed_body = JSON.parse(body)
|
42
|
+
rescue
|
43
|
+
msg = body.nil? || body.empty? ? "no data returned" : body
|
44
|
+
parsed_body = { "errors" => msg }
|
45
|
+
end
|
46
|
+
# status is used to determine whether
|
47
|
+
# we need to refresh the access token.
|
48
|
+
parsed_body["status"] = status
|
49
|
+
|
50
|
+
case status / 100
|
51
|
+
when 3
|
52
|
+
# 302 Found. We should return the url
|
53
|
+
parsed_body["location"] = response["Location"] if status == 302
|
54
|
+
when 4
|
55
|
+
raise(Wakatime::AuthError.new(parsed_body, status, body), parsed_body["errors"]) if status == 401
|
56
|
+
raise(Wakatime::RequestError.new(parsed_body, status, body), parsed_body["errors"])
|
57
|
+
when 5
|
58
|
+
raise(Wakatime::ServerError.new(parsed_body, status, body), parsed_body["errors"])
|
59
|
+
end
|
60
|
+
raw ? body : parsed_body
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'support/account'
|
5
|
+
require 'wakatime'
|
6
|
+
require 'webmock/rspec'
|
7
|
+
|
8
|
+
describe Wakatime::Client do
|
9
|
+
before do
|
10
|
+
@session = Wakatime::Session.new
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#summary' do
|
14
|
+
it "should return json" do
|
15
|
+
stub_request(:get, "#{Wakatime::API_URL}/summary")
|
16
|
+
.with(:query => hash_including(:start, :end))
|
17
|
+
.to_return(:body => File.read('./spec/fixtures/summary.json'), :status => 200)
|
18
|
+
|
19
|
+
client = Wakatime::Client.new(@session)
|
20
|
+
client.summary.grand_total.total_seconds.should eq 49740
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
{
|
2
|
+
"data": {
|
3
|
+
"email": "russell@burningpony.com",
|
4
|
+
"id": "72136a2-266f-422c-9a39-3dc958b37c3d",
|
5
|
+
"last_plugin": "wakatime/1.0.1 (Darwin-13.1.0-x86_64-i386-64bit) Python2.7.5.final.0 sublime/3059 sublime-wakatime/1.6.5",
|
6
|
+
"timeout": 15,
|
7
|
+
"timezone": "America/New_York"
|
8
|
+
},
|
9
|
+
"status": 200
|
10
|
+
}
|
@@ -0,0 +1,166 @@
|
|
1
|
+
{
|
2
|
+
"data": [{
|
3
|
+
"grand_total": {
|
4
|
+
"digital": "2:55",
|
5
|
+
"hours": 2,
|
6
|
+
"minutes": 55,
|
7
|
+
"text": "2 hours 55 minutes",
|
8
|
+
"total_seconds": 10500
|
9
|
+
},
|
10
|
+
"languages": [{
|
11
|
+
"name": "Ruby",
|
12
|
+
"percent": 58.92
|
13
|
+
}, {
|
14
|
+
"name": "Haml",
|
15
|
+
"percent": 15.28
|
16
|
+
}, {
|
17
|
+
"name": "SCSS",
|
18
|
+
"percent": 8.46
|
19
|
+
}, {
|
20
|
+
"name": "CoffeeScript",
|
21
|
+
"percent": 6.75
|
22
|
+
}, {
|
23
|
+
"name": "Other",
|
24
|
+
"percent": 4.29
|
25
|
+
}, {
|
26
|
+
"name": "CSS",
|
27
|
+
"percent": 2.45
|
28
|
+
}, {
|
29
|
+
"name": "HTML",
|
30
|
+
"percent": 2.29
|
31
|
+
}, {
|
32
|
+
"name": "JavaScript",
|
33
|
+
"percent": 1.56
|
34
|
+
}],
|
35
|
+
"projects": [{
|
36
|
+
"digital": "2:48",
|
37
|
+
"hours": 2,
|
38
|
+
"minutes": 48,
|
39
|
+
"name": "timecard",
|
40
|
+
"text": "2 hours 48 minutes",
|
41
|
+
"total_seconds": 10138
|
42
|
+
}, {
|
43
|
+
"digital": "0:07",
|
44
|
+
"hours": 0,
|
45
|
+
"minutes": 7,
|
46
|
+
"name": "Unknown Project",
|
47
|
+
"text": "7 minutes",
|
48
|
+
"total_seconds": 472
|
49
|
+
}, {
|
50
|
+
"digital": "0:00",
|
51
|
+
"hours": 0,
|
52
|
+
"minutes": 0,
|
53
|
+
"name": "felfix",
|
54
|
+
"text": "0 minutes",
|
55
|
+
"total_seconds": 27
|
56
|
+
}],
|
57
|
+
"range": {
|
58
|
+
"end": 1397534399,
|
59
|
+
"end_date": "04/14/2014",
|
60
|
+
"end_human": "yesterday",
|
61
|
+
"start": 1397448000,
|
62
|
+
"start_date": "04/14/2014",
|
63
|
+
"start_human": "yesterday",
|
64
|
+
"text": "yesterday",
|
65
|
+
"timezone": "America/New_York"
|
66
|
+
}
|
67
|
+
}, {
|
68
|
+
"grand_total": {
|
69
|
+
"digital": "13:15",
|
70
|
+
"hours": 13,
|
71
|
+
"minutes": 15,
|
72
|
+
"text": "13 hours 15 minutes",
|
73
|
+
"total_seconds": 47700
|
74
|
+
},
|
75
|
+
"languages": [{
|
76
|
+
"name": "Ruby",
|
77
|
+
"percent": 64.82
|
78
|
+
}, {
|
79
|
+
"name": "Haml",
|
80
|
+
"percent": 23.09
|
81
|
+
}, {
|
82
|
+
"name": "Markdown",
|
83
|
+
"percent": 3.66
|
84
|
+
}, {
|
85
|
+
"name": "Other",
|
86
|
+
"percent": 2.55
|
87
|
+
}, {
|
88
|
+
"name": "CoffeeScript",
|
89
|
+
"percent": 2.36
|
90
|
+
}, {
|
91
|
+
"name": "SCSS",
|
92
|
+
"percent": 2.17
|
93
|
+
}, {
|
94
|
+
"name": "YAML",
|
95
|
+
"percent": 1.0
|
96
|
+
}, {
|
97
|
+
"name": "JSON",
|
98
|
+
"percent": 0.25
|
99
|
+
}, {
|
100
|
+
"name": "CSS",
|
101
|
+
"percent": 0.06
|
102
|
+
}, {
|
103
|
+
"name": "HTML",
|
104
|
+
"percent": 0.04
|
105
|
+
}, {
|
106
|
+
"name": "JavaScript",
|
107
|
+
"percent": 0.0
|
108
|
+
}],
|
109
|
+
"projects": [{
|
110
|
+
"digital": "9:14",
|
111
|
+
"hours": 9,
|
112
|
+
"minutes": 14,
|
113
|
+
"name": "timecard",
|
114
|
+
"text": "9 hours 14 minutes",
|
115
|
+
"total_seconds": 33278
|
116
|
+
}, {
|
117
|
+
"digital": "3:58",
|
118
|
+
"hours": 3,
|
119
|
+
"minutes": 58,
|
120
|
+
"name": "wakatime",
|
121
|
+
"text": "3 hours 58 minutes",
|
122
|
+
"total_seconds": 14280
|
123
|
+
}, {
|
124
|
+
"digital": "0:02",
|
125
|
+
"hours": 0,
|
126
|
+
"minutes": 2,
|
127
|
+
"name": "wakatime-ruby",
|
128
|
+
"text": "2 minutes",
|
129
|
+
"total_seconds": 177
|
130
|
+
}, {
|
131
|
+
"digital": "0:01",
|
132
|
+
"hours": 0,
|
133
|
+
"minutes": 1,
|
134
|
+
"name": "lumber",
|
135
|
+
"text": "1 minute",
|
136
|
+
"total_seconds": 60
|
137
|
+
}, {
|
138
|
+
"digital": "0:00",
|
139
|
+
"hours": 0,
|
140
|
+
"minutes": 0,
|
141
|
+
"name": "pdfthisdomain",
|
142
|
+
"text": "0 minutes",
|
143
|
+
"total_seconds": 48
|
144
|
+
}, {
|
145
|
+
"digital": "0:00",
|
146
|
+
"hours": 0,
|
147
|
+
"minutes": 0,
|
148
|
+
"name": "Unknown Project",
|
149
|
+
"text": "0 minutes",
|
150
|
+
"total_seconds": 11
|
151
|
+
}],
|
152
|
+
"range": {
|
153
|
+
"end": 1397620799,
|
154
|
+
"end_date": "04/15/2014",
|
155
|
+
"end_human": "today",
|
156
|
+
"start": 1397534400,
|
157
|
+
"start_date": "04/15/2014",
|
158
|
+
"start_human": "today",
|
159
|
+
"text": "today",
|
160
|
+
"timezone": "America/New_York"
|
161
|
+
}
|
162
|
+
}],
|
163
|
+
"end": 1397620799,
|
164
|
+
"start": 1397448000,
|
165
|
+
"status": 200
|
166
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
{
|
2
|
+
"data": [{
|
3
|
+
"id": "92f8f1ae-4b87-446a-b245-717815ff01d2",
|
4
|
+
"name": "vim",
|
5
|
+
"version": "1.5.4"
|
6
|
+
}, {
|
7
|
+
"id": "3cd30241-6aea-478d-8e36-5fc170e8be8b",
|
8
|
+
"name": "sublime",
|
9
|
+
"version": "1.6.5"
|
10
|
+
}, {
|
11
|
+
"id": "de429957-c8a4-4b11-b899-f2e797a820c6",
|
12
|
+
"name": "xcode",
|
13
|
+
"version": "1.0.0"
|
14
|
+
}],
|
15
|
+
"total": 3,
|
16
|
+
"total_pages": 1,
|
17
|
+
"status": 200
|
18
|
+
}
|
@@ -0,0 +1,101 @@
|
|
1
|
+
{
|
2
|
+
"data": {
|
3
|
+
"grand_total": {
|
4
|
+
"digital": "13:49",
|
5
|
+
"hours": 13,
|
6
|
+
"minutes": 49,
|
7
|
+
"text": "13 hours 49 minutes",
|
8
|
+
"total_seconds": 49740
|
9
|
+
},
|
10
|
+
"languages": [{
|
11
|
+
"name": "Ruby",
|
12
|
+
"percent": 63.0
|
13
|
+
}, {
|
14
|
+
"name": "Haml",
|
15
|
+
"percent": 23.05
|
16
|
+
}, {
|
17
|
+
"name": "CoffeeScript",
|
18
|
+
"percent": 4.1
|
19
|
+
}, {
|
20
|
+
"name": "Markdown",
|
21
|
+
"percent": 3.51
|
22
|
+
}, {
|
23
|
+
"name": "SCSS",
|
24
|
+
"percent": 2.55
|
25
|
+
}, {
|
26
|
+
"name": "Other",
|
27
|
+
"percent": 2.45
|
28
|
+
}, {
|
29
|
+
"name": "YAML",
|
30
|
+
"percent": 0.96
|
31
|
+
}, {
|
32
|
+
"name": "JSON",
|
33
|
+
"percent": 0.26
|
34
|
+
}, {
|
35
|
+
"name": "CSS",
|
36
|
+
"percent": 0.08
|
37
|
+
}, {
|
38
|
+
"name": "HTML",
|
39
|
+
"percent": 0.04
|
40
|
+
}, {
|
41
|
+
"name": "JavaScript",
|
42
|
+
"percent": 0.0
|
43
|
+
}],
|
44
|
+
"projects": [{
|
45
|
+
"digital": "9:48",
|
46
|
+
"hours": 9,
|
47
|
+
"minutes": 48,
|
48
|
+
"name": "timecard",
|
49
|
+
"text": "9 hours 48 minutes",
|
50
|
+
"total_seconds": 35325
|
51
|
+
}, {
|
52
|
+
"digital": "3:58",
|
53
|
+
"hours": 3,
|
54
|
+
"minutes": 58,
|
55
|
+
"name": "wakatime",
|
56
|
+
"text": "3 hours 58 minutes",
|
57
|
+
"total_seconds": 14329
|
58
|
+
}, {
|
59
|
+
"digital": "0:02",
|
60
|
+
"hours": 0,
|
61
|
+
"minutes": 2,
|
62
|
+
"name": "wakatime-ruby",
|
63
|
+
"text": "2 minutes",
|
64
|
+
"total_seconds": 177
|
65
|
+
}, {
|
66
|
+
"digital": "0:01",
|
67
|
+
"hours": 0,
|
68
|
+
"minutes": 1,
|
69
|
+
"name": "lumber",
|
70
|
+
"text": "1 minute",
|
71
|
+
"total_seconds": 60
|
72
|
+
}, {
|
73
|
+
"digital": "0:00",
|
74
|
+
"hours": 0,
|
75
|
+
"minutes": 0,
|
76
|
+
"name": "pdfthisdomain",
|
77
|
+
"text": "0 minutes",
|
78
|
+
"total_seconds": 48
|
79
|
+
}, {
|
80
|
+
"digital": "0:00",
|
81
|
+
"hours": 0,
|
82
|
+
"minutes": 0,
|
83
|
+
"name": "Unknown Project",
|
84
|
+
"text": "0 minutes",
|
85
|
+
"total_seconds": 11
|
86
|
+
}],
|
87
|
+
"range": {
|
88
|
+
"end": 1397618864.0,
|
89
|
+
"end_date": "04/15/2014",
|
90
|
+
"end_human": "today",
|
91
|
+
"start": 1397532464.0,
|
92
|
+
"start_date": "04/14/2014",
|
93
|
+
"start_human": "yesterday",
|
94
|
+
"text": "from yesterday until today",
|
95
|
+
"timezone": "America/New_York"
|
96
|
+
}
|
97
|
+
},
|
98
|
+
"end": 1397618864.0,
|
99
|
+
"start": 1397532464.0,
|
100
|
+
"status": 200
|
101
|
+
}
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'support/account'
|
5
|
+
require 'wakatime'
|
6
|
+
require 'webmock/rspec'
|
7
|
+
|
8
|
+
describe Wakatime, :skip => true do
|
9
|
+
before do
|
10
|
+
WebMock.allow_net_connect!
|
11
|
+
@session = Wakatime::Session.new({
|
12
|
+
api_key: ACCOUNT['api_key']
|
13
|
+
})
|
14
|
+
|
15
|
+
@client = Wakatime::Client.new(@session)
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
it "raises an AuthError if not client auth fails" do
|
20
|
+
session = Wakatime::Session.new({
|
21
|
+
api_key: 'bad-key'
|
22
|
+
})
|
23
|
+
|
24
|
+
@bad_client = Wakatime::Client.new(session)
|
25
|
+
|
26
|
+
lambda {@bad_client.summary}.should raise_error( Wakatime::AuthError )
|
27
|
+
end
|
28
|
+
describe Wakatime::Client do
|
29
|
+
|
30
|
+
it "will return json scoped to specified times" do
|
31
|
+
summary = @client.summary
|
32
|
+
summary.should be_a Wakatime::Models::Summary
|
33
|
+
summary.should respond_to :grand_total
|
34
|
+
summary.should respond_to :projects
|
35
|
+
end
|
36
|
+
|
37
|
+
it "will return json scoped to specified times" do
|
38
|
+
actions = @client.actions
|
39
|
+
actions.should be_a Array
|
40
|
+
actions.first.should be_a Wakatime::Models::Action
|
41
|
+
actions.first.should respond_to :file
|
42
|
+
actions.first.should respond_to :time
|
43
|
+
end
|
44
|
+
|
45
|
+
it "will return current user json" do
|
46
|
+
current_user = @client.current_user
|
47
|
+
current_user.should be_a Wakatime::Models::User
|
48
|
+
current_user.should respond_to :email
|
49
|
+
current_user.should respond_to :timezone
|
50
|
+
end
|
51
|
+
|
52
|
+
it "will return plugin usage json scoped to specified times" do
|
53
|
+
plugins = @client.plugins
|
54
|
+
plugins.should be_a Array
|
55
|
+
plugins.first.should be_a Wakatime::Models::Plugin
|
56
|
+
plugins.first.should respond_to :name
|
57
|
+
end
|
58
|
+
|
59
|
+
it "will return daily json scoped to specified times" do
|
60
|
+
daily = @client.daily
|
61
|
+
daily.should be_a Array
|
62
|
+
daily.first.should be_a Wakatime::Models::Summary
|
63
|
+
daily.first.should respond_to :grand_total
|
64
|
+
daily.first.should respond_to :projects
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'support/account'
|
5
|
+
require 'wakatime'
|
6
|
+
require 'webmock/rspec'
|
7
|
+
|
8
|
+
describe Wakatime::Session do
|
9
|
+
before do
|
10
|
+
|
11
|
+
@session = Wakatime::Session.new({
|
12
|
+
api_key: "Lame Key"
|
13
|
+
})
|
14
|
+
|
15
|
+
@client = Wakatime::Client.new(@session)
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
it "raises a RequestError if a badly formed request detected by the server" do
|
20
|
+
stub_request(:get, /.*\/summary.*/).to_return(:status => 401, :body => '{\n \"errors\": [\n \"UNAUTHORIZED\"\n ]\n}', :headers => {})
|
21
|
+
lambda {@client.summary}.should raise_error( Wakatime::AuthError )
|
22
|
+
|
23
|
+
# make sure status and body is
|
24
|
+
# set on error object.
|
25
|
+
begin
|
26
|
+
@client.summary
|
27
|
+
rescue Exception => e
|
28
|
+
e.body.should == '{\n \"errors\": [\n \"UNAUTHORIZED\"\n ]\n}'
|
29
|
+
e.status.should == 401
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "raises a ServerError if the server raises a 500 error" do
|
34
|
+
stub_request(:get, /.*\/summary.*/)
|
35
|
+
.to_return(:status => 503, :body => '{"type": "error", "status": 503, "message": "We messed up!"}', :headers => {})
|
36
|
+
lambda {@client.summary}.should raise_error( Wakatime::ServerError )
|
37
|
+
|
38
|
+
# make sure status and body is
|
39
|
+
# set on error object.
|
40
|
+
begin
|
41
|
+
@client.summary
|
42
|
+
rescue Exception => e
|
43
|
+
e.body.should == '{"type": "error", "status": 503, "message": "We messed up!"}' #TODO establish what happens when wakatime returns a 500 or something else.
|
44
|
+
e.status.should == 503
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/wakatime.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'wakatime/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "wakatime"
|
8
|
+
spec.version = Wakatime::VERSION
|
9
|
+
spec.authors = ["Russell Osborne"]
|
10
|
+
spec.email = ["russell@burningpony.com"]
|
11
|
+
spec.summary = %q{An unofficial ruby gem for accessing Wakatime records}
|
12
|
+
spec.description = %q{An unofficial ruby gem for accessing Wakatime records}
|
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_runtime_dependency(%q<hashie>, [">= 0"])
|
22
|
+
spec.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
23
|
+
spec.add_runtime_dependency(%q<multipart-post>, [">= 0"])
|
24
|
+
spec.add_runtime_dependency(%q<json>, [">= 0"])
|
25
|
+
spec.add_runtime_dependency(%q<addressable>, [">= 0"])
|
26
|
+
spec.add_development_dependency(%q<rspec>, [">= 0"])
|
27
|
+
spec.add_development_dependency(%q<bundler>, [">= 0"])
|
28
|
+
spec.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
29
|
+
spec.add_development_dependency(%q<webmock>, [">= 0"])
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wakatime
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Russell Osborne
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hashie
|
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: activesupport
|
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: multipart-post
|
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: json
|
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: addressable
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
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
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bundler
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: jeweler
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.6.4
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.6.4
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: webmock
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: An unofficial ruby gem for accessing Wakatime records
|
140
|
+
email:
|
141
|
+
- russell@burningpony.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".gitignore"
|
147
|
+
- ".rspec"
|
148
|
+
- ".travis.yml"
|
149
|
+
- Gemfile
|
150
|
+
- LICENSE.txt
|
151
|
+
- README.md
|
152
|
+
- Rakefile
|
153
|
+
- lib/wakatime.rb
|
154
|
+
- lib/wakatime/client.rb
|
155
|
+
- lib/wakatime/exceptions.rb
|
156
|
+
- lib/wakatime/models/item.rb
|
157
|
+
- lib/wakatime/session.rb
|
158
|
+
- lib/wakatime/version.rb
|
159
|
+
- spec/client_spec.rb
|
160
|
+
- spec/fixtures/current_user.json
|
161
|
+
- spec/fixtures/daily.json
|
162
|
+
- spec/fixtures/plugins.json
|
163
|
+
- spec/fixtures/summary.json
|
164
|
+
- spec/integration/core_spec.rb
|
165
|
+
- spec/session_spec.rb
|
166
|
+
- spec/spec_helper.rb
|
167
|
+
- spec/support/account.example
|
168
|
+
- spec/support/account.rb
|
169
|
+
- wakatime.gemspec
|
170
|
+
homepage: ''
|
171
|
+
licenses:
|
172
|
+
- MIT
|
173
|
+
metadata: {}
|
174
|
+
post_install_message:
|
175
|
+
rdoc_options: []
|
176
|
+
require_paths:
|
177
|
+
- lib
|
178
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - ">="
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0'
|
183
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
requirements: []
|
189
|
+
rubyforge_project:
|
190
|
+
rubygems_version: 2.2.2
|
191
|
+
signing_key:
|
192
|
+
specification_version: 4
|
193
|
+
summary: An unofficial ruby gem for accessing Wakatime records
|
194
|
+
test_files:
|
195
|
+
- spec/client_spec.rb
|
196
|
+
- spec/fixtures/current_user.json
|
197
|
+
- spec/fixtures/daily.json
|
198
|
+
- spec/fixtures/plugins.json
|
199
|
+
- spec/fixtures/summary.json
|
200
|
+
- spec/integration/core_spec.rb
|
201
|
+
- spec/session_spec.rb
|
202
|
+
- spec/spec_helper.rb
|
203
|
+
- spec/support/account.example
|
204
|
+
- spec/support/account.rb
|