trebbiatrice 0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8c3bd43f753fd67141b8beaffa25c4e8504e27a2
4
+ data.tar.gz: ac56e32bffc60f13f33bd2723bb305c757c5f0ff
5
+ SHA512:
6
+ metadata.gz: 02e83cd7680a1ebf28f7a63916b5acb9ca8809d707aec563d08b9313e2b122b17d7681f2e5327873e6780e75ca1bdd42a715ef788a1dc4073bcc02f6c5a4f75a
7
+ data.tar.gz: 66d84a568264b34fca34a597526a6acd672d4e2e853581694c500b4d8b60880187a35464a690e2b58e5df85ae3023ad80e0f59834982d5e9e067dd2f74232de2
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'harvested'
data/Gemfile.lock ADDED
@@ -0,0 +1,19 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ harvested (3.1.0)
5
+ hashie
6
+ httparty
7
+ json
8
+ hashie (3.4.0)
9
+ httparty (0.13.3)
10
+ json (~> 1.8)
11
+ multi_xml (>= 0.5.2)
12
+ json (1.8.2)
13
+ multi_xml (0.5.5)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ harvested
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ ![Trebbiatrice](http://i.imgur.com/ZSVlfcR.jpg)
2
+
3
+ Trebbiatrice
4
+ ============
5
+ Track the time on Harvest automatically watching what you're working on.
6
+
7
+ What do you need
8
+ ----------------
9
+ - Mac OS X (more platforms later)
10
+ - Sublime Text (more editors later)
11
+ - Projects/Workspace matching the ones you've available on Harvest
12
+
13
+ Installation
14
+ ------------
15
+ `$ gem install trebbiatrice`
16
+
17
+ ```sh
18
+ export TREBBIA_PASS='password'
19
+ export TREBBIA_DOMAIN='subdomain'
20
+ export TREBBIA_MAIL='email'
21
+ ```
22
+
23
+ `$ trebbiatrice`
24
+
25
+ TODO
26
+ ----
27
+ - Configuration file
28
+ - Run as daemon
29
+ - Logger
30
+ - More testate
31
+
32
+ Why
33
+ ---
34
+ > <RoxasShadow> https://www.getharvest.com/
35
+ > <RoxasShadow> è carino
36
+ > <RoxasShadow> e ha integrazioni ovunque
37
+ > <Cusy> trovo strano non te ne sia sviluppato uno tuo
38
+ > <Byakko> infatti
39
+ > [...]
40
+ > <Byakko> quindi, quando apri gli anime SubDesu-H ti segna mpv aperto
41
+ > <Cusy> ^
42
+ > <RoxasShadow> no
43
+ > <RoxasShadow> è manuale
44
+ > [...]
45
+ > <RoxasShadow> più che altro quasi quasi
46
+ > <RoxasShadow> potrei fare qualcosa di automatizzato
47
+ > <RoxasShadow> harvest ha le api
48
+ > <RoxasShadow> potrei detectare la roba aperta in sublime
49
+ > <RoxasShadow> Cusy sei utile
50
+ > <Byakko> vero
51
+ > <Cusy> ....
52
+ > <RoxasShadow> non credo esista
53
+ > <Cusy> NOI TI PERCULAVAMO
54
+ > <Byakko> così eviti il tempo di segnartele ogni volta
55
+ > <RoxasShadow> o almeno non conosco
56
+ > <Byakko> guadagni in tempo ed efficenza
57
+ > <RoxasShadow> ^
58
+ > <Cusy> ....
59
+
60
+ ... and also because half of Moze's development team forget to track the time. Anna will be happy now.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ #! /usr/bin/env ruby
2
+ require 'rake'
3
+
4
+ task default: [ :build, :install ]
5
+
6
+ task :build do
7
+ sh 'gem build *.gemspec'
8
+ end
9
+
10
+ task :install do
11
+ sh 'gem install *.gem'
12
+ end
@@ -0,0 +1,6 @@
1
+ tell application "System Events"
2
+ tell process "Sublime Text"
3
+ set AppleScript's text item delimiters to "\n"
4
+ return name of windows as text
5
+ end tell
6
+ end tell
data/bin/trebbiatrice ADDED
@@ -0,0 +1,29 @@
1
+ #! /usr/bin/env ruby
2
+ #--
3
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
4
+ # Version 2, December 2004
5
+ #
6
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
7
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
8
+ #
9
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
10
+ #++
11
+ require 'trebbiatrice'
12
+
13
+ Encoding.default_external = Encoding::UTF_8
14
+ Encoding.default_internal = Encoding::UTF_8
15
+
16
+ login_data = {
17
+ :subdomain => ENV['TREBBIA_DOMAIN'],
18
+ :username => ENV['TREBBIA_MAIL'],
19
+ :password => ENV['TREBBIA_PASS']
20
+ }
21
+
22
+ task = 'Development'
23
+ frequency = ENV.fetch('TREBBIA_FREQ') { 1 }.to_i
24
+ testata = {
25
+ :engine => 'osascript',
26
+ :name => File.join(File.dirname(__FILE__), 'testate/osx/sublime.scpt')
27
+ }
28
+
29
+ Trebbiatrice::Trebbia.new(login_data).run! testata, task, frequency
@@ -0,0 +1,16 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #++
10
+
11
+ require 'open3'
12
+ require 'harvested'
13
+
14
+ require 'trebbiatrice/harvest.rb'
15
+ require 'trebbiatrice/trebbia.rb'
16
+ require 'trebbiatrice/version.rb'
@@ -0,0 +1,29 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #++
10
+
11
+ module Trebbiatrice
12
+ class Harvest
13
+ def initialize(login_data)
14
+ @harvest = ::Harvest.hardy_client(login_data)
15
+ end
16
+
17
+ def projects
18
+ @harvest.time.trackable_projects
19
+ end
20
+
21
+ def new_entry!(entry)
22
+ @harvest.time.create(entry)
23
+ end
24
+
25
+ def toggle!(entry_id)
26
+ @harvest.time.toggle(entry_id)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,108 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #++
10
+
11
+ module Trebbiatrice
12
+ class Trebbia
13
+ attr_accessor :working_on
14
+
15
+ def initialize(login_data)
16
+ @harvest = Harvest.new(login_data)
17
+ @entry = nil
18
+ @tracking = false
19
+ end
20
+
21
+ def get_task(name)
22
+ @project = active_projects.last unless @project
23
+
24
+ @project.tasks.select { |t| t.name == name }.last
25
+ end
26
+
27
+ def track!(task = 'Development', notes = '')
28
+ return if tracking?
29
+
30
+ if @entry
31
+ @harvest.toggle!(@entry[:id])
32
+ else
33
+ task_id = get_task(task)[:id]
34
+ @entry = @harvest.new_entry! notes: notes, hours: 0, spent_at: today, project_id: @project[:id], task_id: task_id
35
+ end
36
+
37
+ @tracking = true
38
+ end
39
+
40
+ def stop_tracking!
41
+ if @entry && tracking?
42
+ @tracking = false
43
+ @harvest.toggle!(@entry[:id])
44
+ end
45
+ end
46
+
47
+ def tracking?
48
+ !!@tracking
49
+ end
50
+
51
+ def active_projects
52
+ @harvest.projects.select { |project| /#{project[:name]}/i.match(@working_on) }
53
+ end
54
+
55
+ def run!(task, testata, frequency)
56
+ last_project, project = nil
57
+
58
+ loop do
59
+ response = Trebbia.invoke!(testata[:engine], testata[:name])
60
+ @working_on = response[:contents].select do |content|
61
+ @working_on = content
62
+ active_projects.any?
63
+ end.last
64
+
65
+ if response[:status] == 'failure' || !@working_on
66
+ if tracking?
67
+ p "stopping #{project[:name]}" if project
68
+ stop_tracking!
69
+ end
70
+
71
+ last_project = nil
72
+ sleep frequency
73
+ else
74
+ if @working_on && (last_project != @working_on || !project)
75
+ last_project = @working_on
76
+ track!(task)
77
+
78
+ project = active_projects.last
79
+ p "tracking #{project[:name]}"
80
+ end
81
+
82
+ sleep frequency
83
+ end
84
+ end
85
+ end
86
+
87
+ class << self
88
+ def invoke!(*input)
89
+ stdin, stdout, stderr = Open3.popen3(*input)
90
+
91
+ response = unless stderr.read.chomp.strip.empty?
92
+ { status: 'failure', contents: stderr }
93
+ else
94
+ { status: 'success', contents: stdout }
95
+ end
96
+
97
+ response[:contents] = response[:contents].read.each_line.map(&:chomp)
98
+ response
99
+ end
100
+ end
101
+
102
+ private
103
+
104
+ def today
105
+ Time.now.strftime('%Y/%m/%d')
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,13 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #++
10
+
11
+ module Trebbiatrice
12
+ VERSION = '0.1'
13
+ end
@@ -0,0 +1,19 @@
1
+ Kernel.load 'lib/trebbiatrice/version.rb'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'trebbiatrice'
5
+ s.version = Trebbiatrice::VERSION
6
+ s.author = 'Giovanni Capuano'
7
+ s.email = 'webmaster@giovannicapuano.net'
8
+ s.homepage = 'http://www.giovannicapuano.net'
9
+ s.platform = Gem::Platform::RUBY
10
+ s.summary = 'RESTful gem for wrapping Pigro\'s APIs'
11
+ s.description = 'RESTful wrapper gem for Pigro\'s APIs'
12
+ s.license = 'WTFPL'
13
+
14
+ s.files = `git ls-files -z`.split("\0")
15
+ s.require_path = 'lib'
16
+ s.executables = 'trebbiatrice'
17
+
18
+ s.add_dependency 'harvested', '~> 3.1'
19
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trebbiatrice
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Giovanni Capuano
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: harvested
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ description: RESTful wrapper gem for Pigro's APIs
28
+ email: webmaster@giovannicapuano.net
29
+ executables:
30
+ - trebbiatrice
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - Gemfile
36
+ - Gemfile.lock
37
+ - README.md
38
+ - Rakefile
39
+ - bin/testate/osx/sublime.scpt
40
+ - bin/trebbiatrice
41
+ - lib/trebbiatrice.rb
42
+ - lib/trebbiatrice/harvest.rb
43
+ - lib/trebbiatrice/trebbia.rb
44
+ - lib/trebbiatrice/version.rb
45
+ - trebbiatrice.gemspec
46
+ homepage: http://www.giovannicapuano.net
47
+ licenses:
48
+ - WTFPL
49
+ metadata: {}
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 2.2.2
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: RESTful gem for wrapping Pigro's APIs
70
+ test_files: []