togglv8-ng 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,87 @@
1
+ require "simplecov"
2
+ require "coveralls"
3
+
4
+ SimpleCov.formatters = [
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter
7
+ ]
8
+ SimpleCov.start
9
+
10
+ require_relative 'togglv8_spec_helper'
11
+ require_relative '../lib/togglv8'
12
+
13
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
14
+ RSpec.configure do |config|
15
+ config.filter_run :focus
16
+ config.filter_run_excluding :pro_account unless ENV['TOGGL_PRO_ACCOUNT']
17
+ config.run_all_when_everything_filtered = true
18
+
19
+ config.order = :random
20
+ Kernel.srand config.seed
21
+
22
+ config.expect_with :rspec do |expectations|
23
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
24
+ expectations.syntax = :expect
25
+ end
26
+
27
+ config.mock_with :rspec do |mocks|
28
+ mocks.verify_partial_doubles = true
29
+ end
30
+
31
+ config.before(:suite) do
32
+ toggl = TogglV8::API.new(Testing::API_TOKEN)
33
+ TogglV8SpecHelper.setUp(toggl) # start tests from known state
34
+ end
35
+ end
36
+
37
+ class MockResponse
38
+ # https://github.com/lostisland/faraday/blob/master/lib/faraday/response.rb
39
+
40
+ attr_accessor :status, :headers, :body, :env
41
+
42
+ def initialize(status, headers, body)
43
+ @status = status
44
+ @headers = headers
45
+ @body = body
46
+ end
47
+
48
+ def success?
49
+ @status == 200
50
+ end
51
+ end
52
+
53
+ def mktemp_dir
54
+ dir = File.join(Dir.pwd, "tmp-#{Time.now.to_f}")
55
+ Dir.mkdir(dir)
56
+ dir
57
+ end
58
+
59
+ def file_contains(filename, pattern, maxlen=1000)
60
+ expect(File.exist?(filename))
61
+ contents = File.new(filename).sysread(maxlen)
62
+ expect(contents).to match pattern
63
+ end
64
+
65
+ def file_is_pdf(filename)
66
+ expect(File.exist?(filename))
67
+ first_line = File.foreach(filename).first
68
+ expect(first_line).to eq "%PDF-1.3\n"
69
+ end
70
+
71
+ def file_is_xls(filename)
72
+ expect(File.exist?(filename))
73
+ header = File.new(filename).sysread(8)
74
+ expect(header).to eq ['D0CF11E0A1B11AE1'].pack("H*")
75
+ end
76
+
77
+ class Testing
78
+ API_TOKEN = ENV['API_TOKEN'] || '4880adbe1bee9a241fa08070d33bd49f'
79
+ EMAIL = ENV['EMAIL'] || 'togglv8@mailinator.com'
80
+ USERNAME = ENV['USERNAME'] || 'togglv8'
81
+ PASSWORD = ENV['PASSWORD'] || 'togglv8'
82
+ USER_ID = (ENV['USER_ID'] || 1820939).to_i
83
+
84
+ OTHER_EMAIL = ENV['OTHER_EMAIL'] || 'pr5zwux59w@snkmail.com'
85
+ OTHER_USERNAME = ENV['OTHER_USERNAME'] || 'Pr5zwux59w'
86
+ OTHER_USER_ID = (ENV['OTHER_USER_ID'] || 2450739).to_i
87
+ end
@@ -0,0 +1,75 @@
1
+ # :nocov:
2
+ require_relative '../lib/togglv8'
3
+
4
+ class TogglV8SpecHelper
5
+ include Logging
6
+
7
+ def self.setUp(toggl)
8
+ user = toggl.me(all=true)
9
+ @default_workspace_id = user['default_wid']
10
+
11
+ delete_all_projects(toggl)
12
+ delete_all_clients(toggl)
13
+ delete_all_tags(toggl)
14
+ delete_all_time_entries(toggl)
15
+ delete_all_workspaces(toggl)
16
+ end
17
+
18
+ def self.delete_all_clients(toggl)
19
+ clients = toggl.my_clients
20
+ unless clients.nil?
21
+ client_ids ||= clients.map { |c| c['id'] }
22
+ # logger.debug("Deleting #{client_ids.length} clients")
23
+ client_ids.each do |c_id|
24
+ toggl.delete_client(c_id)
25
+ end
26
+ end
27
+ end
28
+
29
+ def self.delete_all_projects(toggl)
30
+ projects = toggl.projects(@default_workspace_id)
31
+ unless projects.nil?
32
+ project_ids ||= projects.map { |p| p['id'] }
33
+ # logger.debug("Deleting #{project_ids.length} projects")
34
+ return unless project_ids.length > 0
35
+ toggl.delete_projects(project_ids)
36
+ end
37
+ end
38
+
39
+ def self.delete_all_tags(toggl)
40
+ tags = toggl.my_tags
41
+ unless tags.nil?
42
+ tag_ids ||= tags.map { |t| t['id'] }
43
+ # logger.debug("Deleting #{tag_ids.length} tags")
44
+ tag_ids.each do |t_id|
45
+ toggl.delete_tag(t_id)
46
+ end
47
+ end
48
+ end
49
+
50
+ def self.delete_all_time_entries(toggl)
51
+ time_entries = toggl.get_time_entries(
52
+ { :start_date => DateTime.now - 30, :end_date => DateTime.now + 30 } )
53
+ unless time_entries.nil?
54
+ time_entry_ids ||= time_entries.map { |t| t['id'] }
55
+ # logger.debug("Deleting #{time_entry_ids.length} time_entries")
56
+ time_entry_ids.each do |t_id|
57
+ toggl.delete_time_entry(t_id)
58
+ end
59
+ end
60
+ end
61
+
62
+ def self.delete_all_workspaces(toggl)
63
+ user = toggl.me(all=true)
64
+ workspaces = toggl.my_workspaces(user)
65
+ unless workspaces.nil?
66
+ workspace_ids ||= workspaces.map { |w| w['id'] }
67
+ workspace_ids.delete(user['default_wid'])
68
+ # logger.debug("Leaving #{workspace_ids.length} workspaces")
69
+ workspace_ids.each do |w_id|
70
+ toggl.leave_workspace(w_id)
71
+ end
72
+ end
73
+ end
74
+ end
75
+ # :nocov:
data/togglv8.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'togglv8/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "togglv8-ng"
8
+ spec.version = TogglV8::VERSION
9
+ spec.authors = ["Tom Kane", "Vincent Norguet"]
10
+ spec.email = ["vincent@neutronium.tech"]
11
+ spec.summary = %q{Toggl v8 API wrapper (See https://github.com/toggl/toggl_api_docs)}
12
+ spec.homepage = "https://github.com/vnorguet/togglv8"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.requirements << 'A Toggl account (https://toggl.com/)'
21
+
22
+ spec.add_development_dependency "bundler"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "rspec-mocks"
26
+ spec.add_development_dependency "fivemat"
27
+ spec.add_development_dependency "coveralls"
28
+ # spec.add_development_dependency "awesome_print"
29
+
30
+ spec.add_dependency "logger"
31
+ spec.add_dependency "faraday"
32
+ spec.add_dependency "oj"
33
+ end
metadata ADDED
@@ -0,0 +1,223 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: togglv8-ng
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Tom Kane
8
+ - Vincent Norguet
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2022-05-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec-mocks
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: fivemat
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: coveralls
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: logger
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: faraday
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: oj
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :runtime
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ description:
141
+ email:
142
+ - vincent@neutronium.tech
143
+ executables: []
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".codeclimate.yml"
148
+ - ".coveralls.yml"
149
+ - ".gitignore"
150
+ - ".rdoc_options"
151
+ - ".rspec"
152
+ - ".rubocop.yml"
153
+ - ".travis.yml"
154
+ - CHANGELOG.md
155
+ - Gemfile
156
+ - LICENSE.txt
157
+ - README.md
158
+ - Rakefile
159
+ - lib/logging.rb
160
+ - lib/reportsv2.rb
161
+ - lib/togglv8.rb
162
+ - lib/togglv8/clients.rb
163
+ - lib/togglv8/connection.rb
164
+ - lib/togglv8/dashboard.rb
165
+ - lib/togglv8/project_users.rb
166
+ - lib/togglv8/projects.rb
167
+ - lib/togglv8/tags.rb
168
+ - lib/togglv8/tasks.rb
169
+ - lib/togglv8/time_entries.rb
170
+ - lib/togglv8/togglv8.rb
171
+ - lib/togglv8/users.rb
172
+ - lib/togglv8/version.rb
173
+ - lib/togglv8/workspaces.rb
174
+ - spec/lib/reportsv2_spec.rb
175
+ - spec/lib/togglv8/clients_spec.rb
176
+ - spec/lib/togglv8/dashboard_spec.rb
177
+ - spec/lib/togglv8/projects_spec.rb
178
+ - spec/lib/togglv8/tags_spec.rb
179
+ - spec/lib/togglv8/tasks_spec.rb
180
+ - spec/lib/togglv8/time_entries_spec.rb
181
+ - spec/lib/togglv8/users_spec.rb
182
+ - spec/lib/togglv8/workspaces_spec.rb
183
+ - spec/lib/togglv8_spec.rb
184
+ - spec/spec_helper.rb
185
+ - spec/togglv8_spec_helper.rb
186
+ - togglv8.gemspec
187
+ homepage: https://github.com/vnorguet/togglv8
188
+ licenses:
189
+ - MIT
190
+ metadata: {}
191
+ post_install_message:
192
+ rdoc_options: []
193
+ require_paths:
194
+ - lib
195
+ required_ruby_version: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - ">="
198
+ - !ruby/object:Gem::Version
199
+ version: '0'
200
+ required_rubygems_version: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - ">="
203
+ - !ruby/object:Gem::Version
204
+ version: '0'
205
+ requirements:
206
+ - A Toggl account (https://toggl.com/)
207
+ rubygems_version: 3.2.32
208
+ signing_key:
209
+ specification_version: 4
210
+ summary: Toggl v8 API wrapper (See https://github.com/toggl/toggl_api_docs)
211
+ test_files:
212
+ - spec/lib/reportsv2_spec.rb
213
+ - spec/lib/togglv8/clients_spec.rb
214
+ - spec/lib/togglv8/dashboard_spec.rb
215
+ - spec/lib/togglv8/projects_spec.rb
216
+ - spec/lib/togglv8/tags_spec.rb
217
+ - spec/lib/togglv8/tasks_spec.rb
218
+ - spec/lib/togglv8/time_entries_spec.rb
219
+ - spec/lib/togglv8/users_spec.rb
220
+ - spec/lib/togglv8/workspaces_spec.rb
221
+ - spec/lib/togglv8_spec.rb
222
+ - spec/spec_helper.rb
223
+ - spec/togglv8_spec_helper.rb