exist_client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +60 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/exist_client +52 -0
- data/exist_client.gemspec +30 -0
- data/launchd_example.plist +23 -0
- data/lib/exist_client.rb +78 -0
- data/lib/exist_client/config.rb +79 -0
- data/lib/exist_client/logical_date.rb +10 -0
- data/lib/exist_client/report_period.rb +23 -0
- data/lib/exist_client/reporter.rb +22 -0
- data/lib/exist_client/tasks.rb +36 -0
- data/lib/exist_client/tasks/task.rb +17 -0
- data/lib/exist_client/time_tracking.rb +52 -0
- data/lib/exist_client/time_tracking/entry.rb +20 -0
- data/lib/exist_client/version.rb +3 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 14ef8dd6d32db5a2abf4c770843fd660dcb332e6
|
4
|
+
data.tar.gz: 2c79edca6e33d9f5c39a23ff0d327b7bd6150daa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f7d513ff64f97c41df64dc77c42f59d2117db0884ba2ccdc5ade1a0fa081879f0c702fefb1c35983093e5e748603ad9d2d1616e880626801895bf1b826d0c0c1
|
7
|
+
data.tar.gz: 85481f59357b02da0c1235b8a8560e921938baeb1af1898de130169c6a0f775db072bd45b0a58758d0ca4e7334db9624b64224ead9133f8c809392cd70c08795
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at matthew.wean@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Matt Wean
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# ExistClient #
|
2
|
+
|
3
|
+
A tool for reporting metrics to [Exist.io](https://exist.io/?referred_by=matthewweanmwean). It currently supports time tracking and completed tasks and supports plugins to work with different apps.
|
4
|
+
|
5
|
+
## Installation ##
|
6
|
+
|
7
|
+
Install the gem:
|
8
|
+
|
9
|
+
$ gem install exist_client
|
10
|
+
|
11
|
+
Run the setup command:
|
12
|
+
|
13
|
+
$ exist_client setup
|
14
|
+
|
15
|
+
This will create a new directory called `.exist` in your home folder. Inside is a config file `config.yml` where you can configure ExistClient.
|
16
|
+
|
17
|
+
## Configuration ##
|
18
|
+
|
19
|
+
In the `config.yml` file, you can specify which plugins to use as well as the cutoff hour to switch to a new day (it defaults to 5am).
|
20
|
+
|
21
|
+
```yaml
|
22
|
+
plugins:
|
23
|
+
tasks: omni_focus
|
24
|
+
time_tracking: qbserve
|
25
|
+
cutoff_hour: 3
|
26
|
+
```
|
27
|
+
|
28
|
+
## Plugins ##
|
29
|
+
|
30
|
+
### Tasks ###
|
31
|
+
- [OmniFocus](https://github.com/mwean/exist_client-omni_focus)
|
32
|
+
|
33
|
+
### Time Tracking ###
|
34
|
+
- [Qbserve](https://github.com/mwean/exist_client-qbserve)
|
35
|
+
|
36
|
+
## Usage ##
|
37
|
+
|
38
|
+
In order to use the client, you will need an Exist API key. You can generate one [here](https://exist.io/account/apps/), then make it available as the environment variable `EXIST_API_KEY`.
|
39
|
+
|
40
|
+
Once you have your API key, you can send metrics manually with `exist_client report`.
|
41
|
+
|
42
|
+
If you're on a Mac and you want to run the report automatically, you can create a launchd agent. You can see an example that runs every day at 1pm [here](launchd_example.plist). The agent runs a helper command that looks like this:
|
43
|
+
|
44
|
+
```bash
|
45
|
+
#!/bin/bash
|
46
|
+
|
47
|
+
source ~/.secrets # Load your Exist API key
|
48
|
+
sleep 5 # Wait for network
|
49
|
+
|
50
|
+
# You may need to use something like ~/.rbenv/shims/exist_client if you use a ruby version manager
|
51
|
+
~/.rbenv/shims/exist_client report
|
52
|
+
```
|
53
|
+
|
54
|
+
## Contributing ##
|
55
|
+
|
56
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/exist_client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
57
|
+
|
58
|
+
## License ##
|
59
|
+
|
60
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "exist_client"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/exe/exist_client
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "cri"
|
4
|
+
|
5
|
+
require "exist_client"
|
6
|
+
|
7
|
+
default_command = Cri::Command.define do
|
8
|
+
name "exist_client"
|
9
|
+
usage "exist_client SUBCOMMAND [options]"
|
10
|
+
summary "Send metrics to Exist.io"
|
11
|
+
description "Make sure to get an API key and make it available as the EXIST_API_KEY environment variable"
|
12
|
+
|
13
|
+
flag :h, :help, "show help for this command" do |_value, cmd|
|
14
|
+
puts cmd.help
|
15
|
+
exit 0
|
16
|
+
end
|
17
|
+
|
18
|
+
flag :v, :version, "show version number" do |_value, cmd|
|
19
|
+
puts ExistClient::VERSION
|
20
|
+
exit 0
|
21
|
+
end
|
22
|
+
|
23
|
+
run do |_opts, _args, cmd|
|
24
|
+
puts cmd.help
|
25
|
+
exit 0
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
setup = Cri::Command.define do
|
30
|
+
name "setup"
|
31
|
+
usage "setup [options]"
|
32
|
+
summary "Installs required files and directories"
|
33
|
+
|
34
|
+
run do |_opts, _args, _cmd|
|
35
|
+
ExistClient.setup
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
report = Cri::Command.define do
|
40
|
+
name "report"
|
41
|
+
usage "report [options]"
|
42
|
+
summary "Sends configured metrics to Exist.io"
|
43
|
+
|
44
|
+
run do |_opts, _args, _cmd|
|
45
|
+
ExistClient.report
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
default_command.add_command(setup)
|
50
|
+
default_command.add_command(report)
|
51
|
+
|
52
|
+
default_command.run(ARGV)
|
@@ -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 'exist_client/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "exist_client"
|
8
|
+
spec.version = ExistClient::VERSION
|
9
|
+
spec.authors = ["Matt Wean"]
|
10
|
+
spec.email = ["matt@mattwean.com"]
|
11
|
+
|
12
|
+
spec.summary = "A client for posting data to Exist.io"
|
13
|
+
spec.description = "A client for posting data to Exist.io"
|
14
|
+
spec.homepage = "https://github.com/mwean/exist_client"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
|
28
|
+
spec.add_dependency "cri", "~> 2.10"
|
29
|
+
spec.add_dependency "httparty", "~> 0.15"
|
30
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
3
|
+
<plist version="1.0">
|
4
|
+
<dict>
|
5
|
+
<key>Label</key>
|
6
|
+
<string>Push to Exist</string>
|
7
|
+
<key>Program</key>
|
8
|
+
<string>/Users/USERNAME/.bin/report_to_exist</string>
|
9
|
+
<key>RunAtLoad</key>
|
10
|
+
<false/>
|
11
|
+
<key>StandardErrorPath</key>
|
12
|
+
<string>/Users/USERNAME/Library/Logs/report_to_exist.log</string>
|
13
|
+
<key>StandardOutPath</key>
|
14
|
+
<string>/Users/USERNAME/Library/Logs/report_to_exist.log</string>
|
15
|
+
<key>StartCalendarInterval</key>
|
16
|
+
<dict>
|
17
|
+
<key>Hour</key>
|
18
|
+
<integer>13</integer>
|
19
|
+
<key>Minute</key>
|
20
|
+
<integer>0</integer>
|
21
|
+
</dict>
|
22
|
+
</dict>
|
23
|
+
</plist>
|
data/lib/exist_client.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require "httparty"
|
2
|
+
require "logger"
|
3
|
+
|
4
|
+
require_relative "exist_client/version"
|
5
|
+
require_relative "exist_client/config"
|
6
|
+
require_relative "exist_client/logical_date"
|
7
|
+
require_relative "exist_client/report_period"
|
8
|
+
require_relative "exist_client/reporter"
|
9
|
+
require_relative "exist_client/time_tracking"
|
10
|
+
require_relative "exist_client/tasks"
|
11
|
+
|
12
|
+
module ExistClient
|
13
|
+
class << self
|
14
|
+
include LogicalDate
|
15
|
+
|
16
|
+
REPORTERS = [TimeTracking, Tasks]
|
17
|
+
|
18
|
+
def setup
|
19
|
+
puts "Installing ExistClient..."
|
20
|
+
Config.setup # TODO: Pass in optional data path
|
21
|
+
REPORTERS.each(&:setup)
|
22
|
+
end
|
23
|
+
|
24
|
+
def report
|
25
|
+
log "Starting report"
|
26
|
+
|
27
|
+
# TODO: Pass in optional data path
|
28
|
+
# Config.set_data_path()
|
29
|
+
last_report_date = Date.parse(Config.last_report_date_file.read.strip)
|
30
|
+
report_period = ReportPeriod.new(last_report_date)
|
31
|
+
|
32
|
+
unless report_period.valid?
|
33
|
+
log "Report period is not valid"
|
34
|
+
exit 1
|
35
|
+
end
|
36
|
+
|
37
|
+
Config.enabled_reporters.each do |reporter|
|
38
|
+
reporter.new(report_period).report
|
39
|
+
end
|
40
|
+
|
41
|
+
Config.last_report_date_file.write(logical_date(Time.now) - 1)
|
42
|
+
|
43
|
+
log "Done"
|
44
|
+
end
|
45
|
+
|
46
|
+
def post(values)
|
47
|
+
log values.to_json, indent: 1
|
48
|
+
|
49
|
+
headers = {
|
50
|
+
"Authorization" => "Bearer #{ENV.fetch("EXIST_API_KEY")}",
|
51
|
+
"Content-Type" => "application/json"
|
52
|
+
}
|
53
|
+
|
54
|
+
response = HTTParty.post("https://exist.io/api/1/attributes/update/", body: values.to_json, headers: headers)
|
55
|
+
|
56
|
+
if response.success?
|
57
|
+
log "Success!", indent: 1
|
58
|
+
else
|
59
|
+
log "Error!", indent: 1
|
60
|
+
log response.code, indent: 1
|
61
|
+
log response.body, indent: 1
|
62
|
+
exit 1
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def log(message, indent: 0)
|
67
|
+
logger.info("#{"\t" * indent}#{message}")
|
68
|
+
end
|
69
|
+
|
70
|
+
def logger
|
71
|
+
@logger ||= Logger.new(STDOUT).tap do |log|
|
72
|
+
log.formatter = lambda do |severity, datetime, _, msg|
|
73
|
+
format("[%s] %5s: %s\n", datetime.strftime("%F %T"), severity, msg)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
module ExistClient
|
4
|
+
class Config
|
5
|
+
DEFAULT_CUTOFF_HOUR = 5
|
6
|
+
DEFAULT_DATA_PATH = "~/.exist"
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def setup(relative_data_path = DEFAULT_DATA_PATH)
|
10
|
+
set_data_path(relative_data_path)
|
11
|
+
|
12
|
+
puts " Creating directory at #{data_path}"
|
13
|
+
data_path.mkpath
|
14
|
+
|
15
|
+
puts " Creating config file at #{config_file}"
|
16
|
+
config_file.write("")
|
17
|
+
|
18
|
+
last_report_date_file.write("2000-01-01")
|
19
|
+
end
|
20
|
+
|
21
|
+
def set_data_path(relative_data_path)
|
22
|
+
@data_path = Pathname.new(relative_data_path).expand_path
|
23
|
+
end
|
24
|
+
|
25
|
+
def data_path
|
26
|
+
@data_path ||= Pathname.new(DEFAULT_DATA_PATH).expand_path
|
27
|
+
end
|
28
|
+
|
29
|
+
def config_file
|
30
|
+
@config_file ||= data_path.join("config.yml")
|
31
|
+
end
|
32
|
+
|
33
|
+
def cutoff_hour
|
34
|
+
config_values.fetch("cutoff_hour", DEFAULT_CUTOFF_HOUR)
|
35
|
+
end
|
36
|
+
|
37
|
+
def data_path_for(reporter)
|
38
|
+
data_path.join(reporter.metric_name)
|
39
|
+
end
|
40
|
+
|
41
|
+
def plugin_for(reporter)
|
42
|
+
@plugins.fetch(reporter.metric_name)
|
43
|
+
end
|
44
|
+
|
45
|
+
def last_report_date_file
|
46
|
+
data_path.join("last_report_date")
|
47
|
+
end
|
48
|
+
|
49
|
+
def enabled_reporters
|
50
|
+
@enabled_reporters ||= plugins.keys.map { |reporter| constantize(reporter) }
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def config_values
|
56
|
+
@config_values ||= YAML.load_file(config_file)
|
57
|
+
end
|
58
|
+
|
59
|
+
def plugins
|
60
|
+
@plugins ||= load_plugins
|
61
|
+
end
|
62
|
+
|
63
|
+
def load_plugins
|
64
|
+
plugin_map = config_values.fetch("plugins").map do |reporter, plugin|
|
65
|
+
require "exist_client/#{plugin}"
|
66
|
+
|
67
|
+
[reporter, constantize(plugin)]
|
68
|
+
end
|
69
|
+
|
70
|
+
plugin_map.to_h
|
71
|
+
end
|
72
|
+
|
73
|
+
def constantize(str)
|
74
|
+
class_name = str.split("_").map(&:capitalize).join
|
75
|
+
ExistClient.const_get(class_name)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ExistClient
|
2
|
+
class ReportPeriod
|
3
|
+
include LogicalDate
|
4
|
+
|
5
|
+
attr_reader :start_time, :end_time
|
6
|
+
|
7
|
+
def initialize(last_report_date)
|
8
|
+
date = last_report_date + 1
|
9
|
+
end_date = logical_date(Time.now)
|
10
|
+
|
11
|
+
@start_time = Time.new(date.year, date.month, date.day, Config.cutoff_hour)
|
12
|
+
@end_time = Time.new(end_date.year, end_date.month, end_date.day, Config.cutoff_hour) - 1
|
13
|
+
end
|
14
|
+
|
15
|
+
def valid?
|
16
|
+
start_time < end_time
|
17
|
+
end
|
18
|
+
|
19
|
+
def include?(time)
|
20
|
+
time.between?(start_time, end_time)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ExistClient
|
2
|
+
class Reporter
|
3
|
+
attr_reader :report_period, :plugin, :data_path
|
4
|
+
|
5
|
+
def self.setup
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.metric_name
|
9
|
+
str = name.split("::").last
|
10
|
+
str.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
|
11
|
+
str.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
|
12
|
+
str.tr!("-", "_")
|
13
|
+
str.downcase!
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(report_period)
|
17
|
+
@report_period = report_period
|
18
|
+
@plugin = Config.plugin_for(self.class)
|
19
|
+
@data_path = Config.data_path_for(self.class)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative "tasks/task"
|
2
|
+
|
3
|
+
module ExistClient
|
4
|
+
class Tasks < Reporter
|
5
|
+
def report
|
6
|
+
ExistClient.log "Reporting completed tasks"
|
7
|
+
completed_tasks = plugin.completed_tasks(report_period, data_path).map { |task_data| Task.new(task_data) }
|
8
|
+
grouped_tasks = filter_tasks(completed_tasks).group_by(&:logical_date)
|
9
|
+
|
10
|
+
if grouped_tasks.any?
|
11
|
+
ExistClient.log "Found data for the following dates:", indent: 1
|
12
|
+
ExistClient.log grouped_tasks.keys.sort.map { |date| date.strftime("%-m/%-d") }.join(", "), indent: 1
|
13
|
+
else
|
14
|
+
ExistClient.log "No new data found", indent: 1
|
15
|
+
return
|
16
|
+
end
|
17
|
+
|
18
|
+
values = grouped_tasks.map do |date, tasks|
|
19
|
+
{
|
20
|
+
name: "tasks_completed",
|
21
|
+
date: date.to_s,
|
22
|
+
value: tasks.size
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
ExistClient.log "Reporting completed tasks data...", indent: 1
|
27
|
+
ExistClient.post(values)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def filter_tasks(tasks)
|
33
|
+
tasks.select { |task| report_period.include?(task.completed_at) }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ExistClient
|
2
|
+
class Tasks < Reporter
|
3
|
+
class Task
|
4
|
+
include LogicalDate
|
5
|
+
|
6
|
+
attr_reader :completed_at
|
7
|
+
|
8
|
+
def initialize(data)
|
9
|
+
@completed_at = data.fetch(:completed_at)
|
10
|
+
end
|
11
|
+
|
12
|
+
def logical_date
|
13
|
+
super(completed_at)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require_relative "time_tracking/entry"
|
2
|
+
|
3
|
+
module ExistClient
|
4
|
+
class TimeTracking < Reporter
|
5
|
+
PRODUCTIVITY_LABELS = {
|
6
|
+
productive: "productive_min",
|
7
|
+
neutral: "neutral_min",
|
8
|
+
distracting: "distracting_min"
|
9
|
+
}
|
10
|
+
|
11
|
+
def self.setup
|
12
|
+
Config.data_path_for(self).mkpath
|
13
|
+
end
|
14
|
+
|
15
|
+
def report
|
16
|
+
ExistClient.log "Reporting time tracking"
|
17
|
+
all_entries = plugin.entries(report_period, data_path).map { |entry_data| Entry.new(entry_data) }
|
18
|
+
grouped_entries = filter_entries(all_entries).group_by(&:logical_date)
|
19
|
+
|
20
|
+
if grouped_entries.any?
|
21
|
+
ExistClient.log "Found data for the following dates:", indent: 1
|
22
|
+
ExistClient.log grouped_entries.keys.sort.map { |date| date.strftime("%-m/%-d") }.join(", "), indent: 1
|
23
|
+
else
|
24
|
+
ExistClient.log "No new data found", indent: 1
|
25
|
+
return
|
26
|
+
end
|
27
|
+
|
28
|
+
values = grouped_entries.flat_map do |date, date_entries|
|
29
|
+
build_productivity_values(date, date_entries)
|
30
|
+
end
|
31
|
+
|
32
|
+
ExistClient.log "Reporting data...", indent: 1
|
33
|
+
ExistClient.post(values)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def filter_entries(entries)
|
39
|
+
entries.select { |entry| report_period.include?(entry.start_time) }
|
40
|
+
end
|
41
|
+
|
42
|
+
def build_productivity_values(date, date_entries)
|
43
|
+
date_entries.group_by(&:productivity).map do |productivity, productivity_entries|
|
44
|
+
{
|
45
|
+
name: PRODUCTIVITY_LABELS.fetch(productivity),
|
46
|
+
date: date.to_s,
|
47
|
+
value: productivity_entries.sum(&:seconds) / 60
|
48
|
+
}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ExistClient
|
2
|
+
class TimeTracking < Reporter
|
3
|
+
class Entry
|
4
|
+
include LogicalDate
|
5
|
+
|
6
|
+
attr_reader :start_time, :end_time, :seconds, :productivity
|
7
|
+
|
8
|
+
def initialize(data)
|
9
|
+
@start_time = data.fetch(:start_time)
|
10
|
+
@end_time = data.fetch(:end_time)
|
11
|
+
@productivity = data.fetch(:productivity)
|
12
|
+
@seconds = end_time - start_time
|
13
|
+
end
|
14
|
+
|
15
|
+
def logical_date
|
16
|
+
super(start_time)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: exist_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Wean
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: cri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.10'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.10'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: httparty
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.15'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.15'
|
83
|
+
description: A client for posting data to Exist.io
|
84
|
+
email:
|
85
|
+
- matt@mattwean.com
|
86
|
+
executables:
|
87
|
+
- exist_client
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- CODE_OF_CONDUCT.md
|
95
|
+
- Gemfile
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- bin/console
|
100
|
+
- bin/setup
|
101
|
+
- exe/exist_client
|
102
|
+
- exist_client.gemspec
|
103
|
+
- launchd_example.plist
|
104
|
+
- lib/exist_client.rb
|
105
|
+
- lib/exist_client/config.rb
|
106
|
+
- lib/exist_client/logical_date.rb
|
107
|
+
- lib/exist_client/report_period.rb
|
108
|
+
- lib/exist_client/reporter.rb
|
109
|
+
- lib/exist_client/tasks.rb
|
110
|
+
- lib/exist_client/tasks/task.rb
|
111
|
+
- lib/exist_client/time_tracking.rb
|
112
|
+
- lib/exist_client/time_tracking/entry.rb
|
113
|
+
- lib/exist_client/version.rb
|
114
|
+
homepage: https://github.com/mwean/exist_client
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.6.11
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: A client for posting data to Exist.io
|
138
|
+
test_files: []
|