everhour2toggl 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 605410dd51b795421b13829ae6221e4ec3634d73707092d2c1ad446ae02bf4bf
4
+ data.tar.gz: 103efb6037475f8fb68176ebac43e330d65ef9bf3d3736d0a046cef417aa49a0
5
+ SHA512:
6
+ metadata.gz: ed080ec03a3f1ce6550389efd68db5f71c5249221694dc25c5495ef55f06e5b76c21ad869c6cbdd3bc79fac5fa408afc3433da48c5a2dd415f97961d2bee6773
7
+ data.tar.gz: 8c3055c1f161cd5a9b476467e1309e457b3cfbcca960897dcfcc683108939499ad0c095e434d6390834e749172e617f24a5a3591e2ed729617c16836e1022f16
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ # default output directory for export files from Everhour and Toggl
14
+ /everhour_entries/
15
+ /toggl_entries/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 1.17.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in everhour2toggl.gemspec
6
+ gemspec
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ everhour2toggl (0.1.0)
5
+ thor
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.3)
11
+ rake (10.5.0)
12
+ rspec (3.8.0)
13
+ rspec-core (~> 3.8.0)
14
+ rspec-expectations (~> 3.8.0)
15
+ rspec-mocks (~> 3.8.0)
16
+ rspec-core (3.8.0)
17
+ rspec-support (~> 3.8.0)
18
+ rspec-expectations (3.8.2)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.8.0)
21
+ rspec-mocks (3.8.0)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.8.0)
24
+ rspec-support (3.8.0)
25
+ thor (0.20.3)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler (~> 1.17)
32
+ everhour2toggl!
33
+ rake (~> 10.0)
34
+ rspec (~> 3.0)
35
+
36
+ BUNDLED WITH
37
+ 1.17.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 noriyotcp
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.
@@ -0,0 +1,62 @@
1
+ # Everhour2toggl
2
+
3
+ This gem exports [Everhour](https://everhour.com/)'s time entries, converts them to [Toggl](https://toggl.com/)'s time entries and posts them to Toggl.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'everhour2toggl'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install everhour2toggl
21
+
22
+ ## Usage
23
+
24
+ Export Everhour's time entries to JSON (default: `<pwd>/everhour_entries/<from>-<to>-<fields>.json`)
25
+
26
+ ```sh
27
+ $ everhour2toggl export --from 2019-01-01 --to 2019-01-31 --apikey xxxx-xxxx-xxxxxx-xxxxxx-xxxxxxxx --fields date,task,user
28
+ ```
29
+
30
+ Convert Everhour's time entries to Toggl's ones (JSON, default:`<pwd>/toggl_entries/<from>-<to>-<fields>.json`)
31
+
32
+ ```sh
33
+ $ everhour2toggl convert --input everhour_entries/2019-01-01-2019-01-31-date,task,user.json --starting_time 10:00 --interval 60 --pid xxxxxxx --tags foo,bar,baz
34
+ ```
35
+
36
+ Post Toggl's time entries to Toggl
37
+
38
+ ```sh
39
+ $ everhour2toggl post --input toggl_entries/2019-01-01-2019-01-31-date,task,user.json --api_token <YOUR_API_TOKEN>
40
+ ```
41
+
42
+ To see more usage
43
+
44
+ ```sh
45
+ $ everhour2toggl (or with option -h)
46
+ ```
47
+
48
+ This gem uses [Thor](https://github.com/erikhuda/thor) ([homepage](http://whatisthor.com/))
49
+
50
+ ## Development
51
+
52
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
53
+
54
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
55
+
56
+ ## Contributing
57
+
58
+ Bug reports and pull requests are welcome on GitHub at https://github.com/noriyotcp/everhour2toggl.
59
+
60
+ ## License
61
+
62
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "everhour2toggl"
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(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,41 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "everhour2toggl/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "everhour2toggl"
8
+ spec.version = Everhour2toggl::VERSION
9
+ spec.authors = ["noriyotcp"]
10
+ spec.email = ["noriyo.akita@gmail.com"]
11
+
12
+ spec.summary = %q{Everhour2toggl CLI tool for time entries from Everhour to Toggl.}
13
+ spec.description = %q{Everhour2toggl exports [Everhour](https://everhour.com/)'s time entries, converts them to [Toggl](https://toggl.com/)'s time entries and posts them to Toggl.}
14
+ spec.homepage = "https://github.com/noriyotcp/everhour2toggl"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = ""
21
+ #
22
+ # spec.metadata["homepage_uri"] = spec.homepage
23
+ # else
24
+ # raise "RubyGems 2.0 or newer is required to protect against " \
25
+ # "public gem pushes."
26
+ # end
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.add_dependency "thor"
38
+ spec.add_development_dependency "bundler", "~> 1.17"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "rspec", "~> 3.0"
41
+ end
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'everhour2toggl'
3
+
4
+ Everhour2toggl::CLI.start(ARGV)
@@ -0,0 +1,7 @@
1
+ require "everhour2toggl/version"
2
+ require "everhour2toggl/cli"
3
+
4
+ module Everhour2toggl
5
+ class Error < StandardError; end
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,39 @@
1
+ require 'thor'
2
+ require 'everhour2toggl/everhour'
3
+ require 'everhour2toggl/toggl'
4
+ require 'everhour2toggl/toggl/post'
5
+ require 'everhour2toggl/file_generator'
6
+
7
+ module Everhour2toggl
8
+ class CLI < Thor
9
+ option :from, type: :string, required: true, desc: 'Date from you what to fetch reported time (format YYYY-MM-DD) Example: 2018-01-01.'
10
+ option :to, type: :string, required: true, desc: 'Date to you what to fetch reported time (format YYYY-MM-DD) Example: 2018-01-31.'
11
+ option :fields, type: :string, desc: 'Comma separated objects to group by and fetch (allowed: user, project, task and date). Example: date,user,task.'
12
+ option :apikey, type: :string, required: true, desc: 'API key for authorization'
13
+ desc 'export', "Export Everhour's team time to json"
14
+ def export
15
+ everhour = Everhour.new(from: options[:from], to: options[:to], fields: options[:fields], apikey: options[:apikey])
16
+ everhour.export
17
+ end
18
+
19
+ option :input, type: :string, required: true, desc: 'JSON file to convert /path/to/example.json'
20
+ option :starting_time, type: :string, desc: 'Starting time on every entry Example: 10:00 NOTE: without this option, starting_time sets 00:00'
21
+ option :interval, type: :numeric, desc: 'Time interval between entries Example: 60, default is 3600(1 hour)'
22
+ option :wid, type: :numeric, desc: 'workspace ID (integer, required if pid or tid not supplied)'
23
+ option :pid, type: :numeric, desc: 'project ID (integer, not required)'
24
+ option :tags, type: :string, desc: 'Tags, separated by comma Example: foo,bar,baz'
25
+ desc 'convert', "Convert Everhour time entries to JSON which supports Toggl time entries"
26
+ def convert
27
+ toggl = Toggl.new(input: options[:input], starting_time: options[:starting_time], interval: options[:interval], wid: options[:wid], pid: options[:pid], tags: options[:tags])
28
+ toggl.convert
29
+ end
30
+
31
+ option :api_token, type: :string, required: true, desc: 'personal api token'
32
+ option :input, type: :string, required: true, desc: 'JSON file to post /path/to/example.json'
33
+ desc 'post', 'Post time entries to toggl'
34
+ def post
35
+ toggl_post = Toggl::Post.new(api_token: options[:api_token], input: options[:input])
36
+ toggl_post.post
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,43 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'fileutils'
5
+
6
+ module Everhour2toggl
7
+ class Everhour
8
+ def initialize(from:, to:, fields:, apikey:)
9
+ @from = from
10
+ @to = to
11
+ @fields = fields
12
+ @apikey = apikey
13
+ end
14
+
15
+ def export
16
+ output_path = "everhour_entries"
17
+ file_generator = Everhour2toggl::FileGenerator.new(output: output_path, filename: "#{@from}-#{@to}-#{@fields}.json")
18
+ file_generator.generate(exported_time_str)
19
+ end
20
+
21
+ private
22
+
23
+ def exported_time_str
24
+ uri = URI.parse("https://api.everhour.com/team/time/export")
25
+ params = {from: @from, to: @to, "fields": @fields}
26
+ uri.query = URI.encode_www_form(params)
27
+
28
+ request = Net::HTTP::Get.new(uri)
29
+ request.content_type = "application/json"
30
+ request["X-Api-Key"] = @apikey
31
+
32
+ req_options = {
33
+ use_ssl: uri.scheme == "https",
34
+ }
35
+
36
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
37
+ http.request(request)
38
+ end
39
+ # response.code
40
+ JSON.pretty_generate(JSON.parse(response.body))
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,17 @@
1
+ require 'fileutils'
2
+
3
+ module Everhour2toggl
4
+ class FileGenerator
5
+ def initialize(output:, filename:)
6
+ @output = output
7
+ @filename = filename
8
+ end
9
+
10
+ def generate(str)
11
+ FileUtils.mkdir_p("#{@output}")
12
+ File.open("#{Dir.pwd}/#{@output}/#{@filename}", "w") do |file|
13
+ file.puts(str)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,65 @@
1
+ require 'json'
2
+ require 'time'
3
+
4
+ module Everhour2toggl
5
+ class Toggl
6
+ def initialize(input:, starting_time:, interval: 3600, wid:, pid:, tags:)
7
+ begin
8
+ raise 'Error' unless pid || wid
9
+ rescue => e
10
+ puts "#{e}: wid must be required if pid is not supplied"
11
+ end
12
+ @input = input
13
+ @starting_time = starting_time
14
+ @interval = interval
15
+ @wid = wid
16
+ @pid = pid
17
+ @tags = tags
18
+ end
19
+
20
+ def convert
21
+ output_path = "toggl_entries"
22
+ # output file name is same with input file
23
+ file_generator = Everhour2toggl::FileGenerator.new(output: output_path, filename: "#{File.basename(@input)}")
24
+ file_generator.generate(converted_str)
25
+ end
26
+
27
+ def converted_str
28
+ file = File.read(@input)
29
+ data = JSON.parse(file)
30
+ groups = groups_by_date(data)
31
+ bodies = groups.map do |group|
32
+ request_bodies(group)
33
+ end.flatten
34
+ JSON.pretty_generate(bodies)
35
+ end
36
+
37
+ def groups_by_date(data)
38
+ data.group_by { |d| d['date'] }
39
+ end
40
+
41
+ def request_bodies(group)
42
+ # convert group[0](date) + starting_time to Time
43
+ # e.g. 2019-01-04 10:00:00 +0900
44
+ start = Time.parse([group[0], @starting_time].join(' '))
45
+ entry_array = group[1]
46
+ offset = 0
47
+ request_bodies = []
48
+ entry_array.each do |entry|
49
+ request_bodies << { "time_entry":
50
+ {
51
+ "description": entry['task']['name'],
52
+ "wid": @wid,
53
+ "pid": @pid,
54
+ "duration": entry['time'],
55
+ "start": (start + offset).iso8601,
56
+ "created_with": "everhour2toggl",
57
+ "tags": @tags&.split(',')
58
+ }.compact
59
+ }
60
+ offset += entry['time'] + @interval
61
+ end
62
+ request_bodies
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,32 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+
5
+ module Everhour2toggl
6
+ class Toggl::Post
7
+ def initialize(api_token:, input:)
8
+ @api_token = api_token
9
+ @input = input
10
+ end
11
+
12
+ def post
13
+ uri = URI.parse("https://www.toggl.com/api/v8/time_entries")
14
+ request = Net::HTTP::Post.new(uri)
15
+ request.basic_auth(@api_token, "api_token")
16
+ request.content_type = "application/json"
17
+
18
+ req_options = {
19
+ use_ssl: uri.scheme == "https",
20
+ }
21
+
22
+ entries = JSON.parse(File.read(@input))
23
+ responses = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
24
+ entries.each do |entry|
25
+ request.body = JSON.dump(entry)
26
+ http.request(request)
27
+ end
28
+ end
29
+ # puts responses
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module Everhour2toggl
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: everhour2toggl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - noriyotcp
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-01-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.17'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.17'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Everhour2toggl exports [Everhour](https://everhour.com/)'s time entries,
70
+ converts them to [Toggl](https://toggl.com/)'s time entries and posts them to Toggl.
71
+ email:
72
+ - noriyo.akita@gmail.com
73
+ executables:
74
+ - everhour2toggl
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - everhour2toggl.gemspec
89
+ - exe/everhour2toggl
90
+ - lib/everhour2toggl.rb
91
+ - lib/everhour2toggl/cli.rb
92
+ - lib/everhour2toggl/everhour.rb
93
+ - lib/everhour2toggl/file_generator.rb
94
+ - lib/everhour2toggl/toggl.rb
95
+ - lib/everhour2toggl/toggl/post.rb
96
+ - lib/everhour2toggl/version.rb
97
+ homepage: https://github.com/noriyotcp/everhour2toggl
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.7.6
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Everhour2toggl CLI tool for time entries from Everhour to Toggl.
121
+ test_files: []