rescuetime 0.3.3 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce870b11b2ff5bc0257b76ef6e494a279dedd5b8
4
- data.tar.gz: 5d2a5e4e0884b38c321cdd6a64dcb4a00da2d57c
3
+ metadata.gz: 91580bf8d38de0e666474a0997d3e0ec3c556c83
4
+ data.tar.gz: b6e82c5ceaad582f0294ad7dde9e0e50aedfd38f
5
5
  SHA512:
6
- metadata.gz: ec48c9a8f5c98ffe39c1e43ff2342d617b20ffc95fb785ed25d171dd0d3f43184234064d1488aebd4f5a274a38bda29f1febb3e2e365c249d518a2baa96acf63
7
- data.tar.gz: 3f24d854c6e41263ac3ad2012e55743eefd7c72d1a7960e3749c8002d59c0213bbf33cecc2a20891ad569ad50aec8fe84dabad5cae115b4ea290743b6be27540
6
+ metadata.gz: 8dbb49c2e711c4f66c35a501253b3e491b933acee14f2232d147f33056cffd108856a98fa6c8b0751891649d0cb7b3332ee0577667b004d1c496783da706fed8
7
+ data.tar.gz: ecbedb46b28cf5861b16b61b9006a61d88952328f77654e1b0b1db28fc3e15b279eab88639bfff8f38036876fb81d033af86c895807675edf555e71b596ddc32
@@ -1 +1,4 @@
1
- inherit_from: .rubocop_todo.yml
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ Style/SignalException:
4
+ EnforcedStyle: only_raise
@@ -1,80 +1,58 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2016-05-22 00:42:00 -0400 using RuboCop version 0.40.0.
3
+ # on 2016-05-26 15:32:03 -0400 using RuboCop version 0.40.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 1
10
- Lint/AmbiguousOperator:
11
- Exclude:
12
- - 'lib/rescuetime/collection.rb'
9
+ # Offense count: 23
10
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
11
+ # URISchemes: http, https
12
+ Metrics/LineLength:
13
+ Max: 91
13
14
 
14
15
  # Offense count: 1
15
16
  # Configuration parameters: CountComments.
16
17
  Metrics/MethodLength:
17
18
  Max: 13
18
19
 
19
- # Offense count: 1
20
+ # Offense count: 8
20
21
  # Cop supports --auto-correct.
21
- Performance/StringReplacement:
22
+ # Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
23
+ # SupportedStyles: line_count_based, semantic, braces_for_chaining
24
+ # ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
25
+ # FunctionalMethods: let, let!, subject, watch
26
+ # IgnoredMethods: lambda, proc, it
27
+ Style/BlockDelimiters:
22
28
  Exclude:
23
- - 'lib/rescuetime/date_parser.rb'
29
+ - 'spec/rescuetime/core_extensions/object/blank_spec.rb'
30
+ - 'spec/rescuetime/date_parser_spec.rb'
31
+ - 'spec/rescuetime/formatters/array_formatter_spec.rb'
32
+ - 'spec/rescuetime/formatters/csv_formatter_spec.rb'
33
+ - 'spec/rescuetime/report_formatters_spec.rb'
34
+ - 'spec/rescuetime/requester_spec.rb'
24
35
 
25
- # Offense count: 1
26
- # Cop supports --auto-correct.
36
+ # Offense count: 7
27
37
  # Configuration parameters: EnforcedStyle, SupportedStyles.
28
- # SupportedStyles: always, conditionals
29
- Style/AndOr:
38
+ # SupportedStyles: nested, compact
39
+ Style/ClassAndModuleChildren:
30
40
  Exclude:
31
- - 'lib/rescuetime/query_buildable.rb'
41
+ - 'lib/rescuetime/core_extensions/object.rb'
42
+ - 'lib/rescuetime/core_extensions/object/blank.rb'
43
+ - 'lib/rescuetime/core_extensions/string.rb'
44
+ - 'lib/rescuetime/formatters/array_formatter.rb'
45
+ - 'lib/rescuetime/formatters/base_formatter.rb'
46
+ - 'lib/rescuetime/formatters/csv_formatter.rb'
47
+ - 'spec/fixtures/formatters/fake_formatter.rb'
32
48
 
33
- # Offense count: 5
34
- # Cop supports --auto-correct.
35
- # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
36
- # SupportedStyles: aligned, indented
37
- Style/MultilineMethodCallIndentation:
38
- Enabled: false
39
-
40
- # Offense count: 9
41
- # Cop supports --auto-correct.
42
- Style/MutableConstant:
43
- Exclude:
44
- - 'lib/rescuetime/collection.rb'
45
- - 'lib/rescuetime/date_parser.rb'
46
- - 'lib/rescuetime/errors.rb'
47
- - 'lib/rescuetime/query_buildable.rb'
48
- - 'lib/rescuetime/requester.rb'
49
- - 'lib/rescuetime/version.rb'
50
- - 'spec/sample_secret.rb'
51
- - 'spec/secret.rb'
52
-
53
- # Offense count: 3
54
- # Cop supports --auto-correct.
55
- Style/NestedParenthesizedCalls:
49
+ # Offense count: 1
50
+ Style/DoubleNegation:
56
51
  Exclude:
57
- - 'spec/rescuetime/query_buildable_spec.rb'
52
+ - 'lib/rescuetime/core_extensions/object/blank.rb'
58
53
 
59
54
  # Offense count: 1
60
55
  # Cop supports --auto-correct.
61
56
  Style/ParallelAssignment:
62
57
  Exclude:
63
58
  - 'spec/rescuetime/query_buildable_spec.rb'
64
-
65
- # Offense count: 1
66
- # Cop supports --auto-correct.
67
- Style/RedundantSelf:
68
- Exclude:
69
- - 'lib/rescuetime/query_buildable.rb'
70
-
71
- # Offense count: 10
72
- # Cop supports --auto-correct.
73
- # Configuration parameters: EnforcedStyle, SupportedStyles.
74
- # SupportedStyles: only_raise, only_fail, semantic
75
- Style/SignalException:
76
- Exclude:
77
- - 'lib/rescuetime/collection.rb'
78
- - 'lib/rescuetime/date_parser.rb'
79
- - 'lib/rescuetime/query_buildable.rb'
80
- - 'lib/rescuetime/requester.rb'
data/Gemfile CHANGED
@@ -1,10 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'rubocop', require: false
4
-
5
3
  group :test do
6
4
  gem 'codeclimate-test-reporter', '~> 0.4.7'
7
- gem 'simplecov', '~> 0.9.2'
5
+ gem 'simplecov', '~> 0.11.2'
8
6
  end
9
7
 
10
8
  # Specify your gem's dependencies in rescuetime.gemspec
data/README.md CHANGED
@@ -21,6 +21,7 @@ For more information about RescueTime, visit [the RescueTime homepage](https://w
21
21
  * [Usage](#usage)
22
22
  * [Prerequisites](#prerequisites)
23
23
  * [In a Nutshell](#in-a-nutshell) (skip to here if you want to see the syntax)
24
+ * [Custom Report Formatters](#custom-report-formatters)
24
25
  * [Finding Answers (Documentation)](#finding-answers-documentation)
25
26
  * [Defaults](#defaults)
26
27
  * [Rescuetime Exceptions](#rescuetime-exceptions)
@@ -51,7 +52,7 @@ Or install it yourself as:
51
52
 
52
53
  ### Prerequisites
53
54
 
54
- Ensure that you are using a [supported ruby version](https://github.com/leesharma/rescuetime/wiki/Supported-Rubies) for your project.
55
+ Ensure that you are using a [supported ruby version](https://github.com/leesharma/rescuetime/wiki/Supported-Rubies) for your project.
55
56
 
56
57
  In order to use access your RescueTime data, you will need an API key. If you do not already have a key, visit the [API key management page](https://www.rescuetime.com/anapi/manage).
57
58
 
@@ -66,7 +67,7 @@ require 'rescuetime'
66
67
 
67
68
  # Rescuetime uses lazy evaluation, so until you either manipulate the collection
68
69
  # or explicitly call for it (with #all), it will remain in the Rescuetime::Collection
69
- # format.
70
+ # format.
70
71
  @client.overview.class #=> Rescuetime::Collection
71
72
  @client.overview.all.class #=> Array
72
73
  @client.overview.map {...} #=> Array
@@ -89,9 +90,9 @@ require 'rescuetime'
89
90
  # - Object#strftime
90
91
  @client.overview # Fetches results from today
91
92
  @client.overview.date('2014-12-31') # Fetches results from Dec 31, 2014.
92
- @client.overview.from('2015-01-01').to('2015-02-01')
93
- @client.overview.from('2015-04-01')
94
-
93
+ @client.overview.from('2015-01-01').to('2015-02-01')
94
+ @client.overview.from('2015-04-01')
95
+
95
96
 
96
97
  ##
97
98
  # Report Order (:order_by)
@@ -99,7 +100,7 @@ require 'rescuetime'
99
100
  # Defaults:
100
101
  # Efficiency defaults to chronological order; everything else defaults to "rank" order
101
102
  #
102
- # You can order_by:
103
+ # You can order_by:
103
104
  # :rank, :time, or :member (note: efficiency can't be sorted by :rank)
104
105
  #
105
106
  # When ordering by time, default interval is 1 hour.
@@ -107,15 +108,15 @@ require 'rescuetime'
107
108
  # :minute (5-minute chunks), :hour, :day, :week, :month
108
109
  @client.efficiency # Defaults to :time
109
110
  @client.productivity # Defaults to :rank
110
-
111
- @client.productivity.order_by(:rank)
112
- @client.productivity.order_by(:time)
113
- @client.productivity.order_by(:member)
114
-
111
+
112
+ @client.productivity.order_by(:rank)
113
+ @client.productivity.order_by(:time)
114
+ @client.productivity.order_by(:member)
115
+
115
116
  @client.productivity.order_by(:time) # Defaults to :hour
116
- @client.productivity.order_by(:time, interval: :minute)
117
- @client.productivity.order_by(:time, interval: :hour)
118
- @client.productivity.order_by(:time, interval: :day)
117
+ @client.productivity.order_by(:time, interval: :minute)
118
+ @client.productivity.order_by(:time, interval: :hour)
119
+ @client.productivity.order_by(:time, interval: :day)
119
120
  @client.productivity.order_by(:time, interval: :week)
120
121
  @client.productivity.order_by(:time, interval: :month)
121
122
 
@@ -131,10 +132,10 @@ require 'rescuetime'
131
132
  # Try the query sans document for a list of valid options
132
133
  #
133
134
  # Names must be exact matches.
134
- @client.activities.where(name: 'github.com')
135
- @client.categories.where(name: 'Intelligence')
136
- @client.overview.where(name: 'Utilities')
137
- @client.activities.where(name: 'github.com', document: 'vcr/vcr')
135
+ @client.activities.where(name: 'github.com')
136
+ @client.categories.where(name: 'Intelligence')
137
+ @client.overview.where(name: 'Utilities')
138
+ @client.activities.where(name: 'github.com', document: 'vcr/vcr')
138
139
 
139
140
  ##
140
141
  # Formatting options (:csv, :array)
@@ -144,9 +145,98 @@ require 'rescuetime'
144
145
  @client.efficiency.format(:array) # Returns Array<Hash>
145
146
  ```
146
147
 
148
+ ### Custom Report Formatters
149
+
150
+ *Feature available in v0.4.0 and later*
151
+
152
+ Rescuetime ships with two report formats: CSV and Array. If you would like your
153
+ report in a different format, don't worry–it's easy to add a custom formatter.
154
+
155
+ Four things are required to add a custom formatter:
156
+
157
+ 1. [Write a class](#writing-a-formatter) within the module
158
+ `Rescuetime::Formatters` that inherits from `Rescuetime::Formatters::BaseFormatter`
159
+ or one of its descendants
160
+ 2. Define the class methods `.name` and `.format`
161
+ 4. [Register your formatters](#registering-your-formatters) using `Rescuetime.configure`
162
+
163
+ #### Writing a Formatter
164
+
165
+ First, the formatters themselves. Here is a basic formatter:
166
+
167
+ ```ruby
168
+ # config/formatters/nil_formatter.rb
169
+ module Rescuetime::Formatters
170
+ # Turns a productivity report into nothing useful.
171
+ class NilFormatter < BaseFormatter
172
+ # @return [String] name of this report format
173
+ def self.name
174
+ 'nil'
175
+ end
176
+
177
+ # @param [CSV] _report the raw CSV report from Rescuetime
178
+ # @return [nil] the formatted output (in this case, nil)
179
+ def self.format(_report)
180
+ nil
181
+ end
182
+ end
183
+ end
184
+ ```
185
+
186
+ You can even inherit from an existing formatter:
187
+
188
+ ```ruby
189
+ # config/formatters/shouty_array_formatter.rb
190
+ module Rescuetime::Formatters
191
+ # Formats a rescuetime report as an array of hashes, except shouting.
192
+ class ShoutyArrayFormatter < ArrayFormatter
193
+ # @return [String] name of this report format
194
+ def self.name
195
+ 'shouty_array'
196
+ end
197
+
198
+ # @param [CSV] report the raw CSV report from Rescuetime
199
+ # @return [Array<Hash>] the formatted output (in this case, a shouty
200
+ # array of hashes)
201
+ def self.format(report)
202
+ array = super(report)
203
+ array.map do |hash|
204
+ terms = hash.map { |key, value| [key.to_s.upcase, value.to_s.upcase] }
205
+ Hash[terms]
206
+ end
207
+ end
208
+ end
209
+ end
210
+ ```
211
+
212
+ #### Registering your Formatters
213
+
214
+ Before setting your report format, add the path to your formatter(s) to the
215
+ Rescuetime configuration using the `Rescuetime.configure` method. You will be
216
+ able to set, append to, or manipulate the `formatter_paths` setting.
217
+
218
+ ```ruby
219
+ Rescuetime.configure do |config|
220
+ path = File.expand_path('../my_custom_formatter.rb', __FILE__)
221
+ config.formatter_paths = [path]
222
+ end
223
+ ```
224
+
225
+ Now Rescuetime will look for the `my_custom_formatter.rb` file. Multiple paths
226
+ may be added as well.
227
+
228
+ ```ruby
229
+ Rescuetime.configure do |config|
230
+ config.formatter_paths = [
231
+ 'config/formatters/*_formatter.rb',
232
+ 'lib/formatters/**/*_formatter.rb',
233
+ ]
234
+ end
235
+ ```
236
+
147
237
  ### Finding Answers (Documentation)
148
238
 
149
- For more details, please see [official gem documentation](http://www.rubydoc.info/gems/rescuetime) or [read the wiki](https://github.com/leesharma/rescuetime/wiki).
239
+ For more details, please see [official gem documentation](http://www.rubydoc.info/gems/rescuetime) or [read the wiki](https://github.com/leesharma/rescuetime/wiki).
150
240
 
151
241
  ### Defaults
152
242
 
@@ -162,27 +252,32 @@ The `Rescuetime::Client#activities` action has the following defaults:
162
252
 
163
253
  ### Rescuetime Exceptions
164
254
 
165
- There are a number of exceptions that extend from the custom Rescuetime::Error class:
255
+ *Note: In v0.4.0, custom exceptions were moved from the base `Rescuetime`
256
+ namespace to the `Rescuetime::Errors` namespace. For example, in v0.3.3,
257
+ a bad request was represented by `Rescuetime::BadRequest`. In >= v0.4.0,
258
+ it is represented by `Rescuetime::Errors::BadRequest`.*
259
+
260
+ There are a number of exceptions that extend from the `Rescuetime::Errors::Error` class:
166
261
 
167
- * **Rescuetime::MissingCredentialsError** is raised when a request is attempted by a client with no credentials. Try setting credentials with `@client.api_key = <YOUR_API_KEY>`.
168
- * **Rescuetime::InvalidCredentialsError** is raised when a request is attempted by a client with invalid credentials. Double-check your API key and fix your client with `@client.api_key = <VALID_API_KEY>`.
169
- * **Rescuetime::InvalidQueryError** is raised if you enter an invalid value for any of the RescueTime query methods (or if the server returns a bad query error)
170
- * **Rescuetime::InvalidFormatError** is raised if you pass a disallowed format to the client
262
+ * **`Rescuetime::Errors::MissingCredentialsError`** is raised when a request is attempted by a client with no credentials. Try setting credentials with `@client.api_key = <YOUR_API_KEY>`.
263
+ * **`Rescuetime::Errors::InvalidCredentialsError`** is raised when a request is attempted by a client with invalid credentials. Double-check your API key and fix your client with `@client.api_key = <VALID_API_KEY>`.
264
+ * **`Rescuetime::Errors::InvalidQueryError`** is raised if you enter an invalid value for any of the RescueTime query methods (or if the server returns a bad query error)
265
+ * **`Rescuetime::Errors::InvalidFormatError`** is raised if you pass a disallowed format to the client
171
266
  * HTTP Response Errors:
172
- * **4xx => Rescuetime:: ClientError**
173
- * 400 => Rescuetime::BadRequest
174
- * 401 => Rescuetime::Unauthorized
175
- * 403 => Rescuetime::Forbidden
176
- * 404 => Rescuetime::NotFound
177
- * 406 => Rescuetime::NotAcceptable
178
- * 422 => Rescuetime::UnprocessableEntity
179
- * 429 => Rescuetime::TooManyRequests
180
- * **5xx => Rescuetime:: ServerError**
181
- * 500 => Rescuetime::InternalServerError
182
- * 501 => Rescuetime::NotImplemented
183
- * 502 => Rescuetime::BadGateway
184
- * 503 => Rescuetime::ServiceUnavailable
185
- * 504 => Rescuetime::GatewayTimeout
267
+ * **4xx => `Rescuetime::Errors::ClientError`**
268
+ * 400 => `Rescuetime::Errors::BadRequest`
269
+ * 401 => `Rescuetime::Errors::Unauthorized`
270
+ * 403 => `Rescuetime::Errors::Forbidden`
271
+ * 404 => `Rescuetime::Errors::NotFound`
272
+ * 406 => `Rescuetime::Errors::NotAcceptable`
273
+ * 422 => `Rescuetime::Errors::UnprocessableEntity`
274
+ * 429 => `Rescuetime::Errors::TooManyRequests`
275
+ * **5xx => `Rescuetime::Errors::ServerError`**
276
+ * 500 => `Rescuetime::Errors::InternalServerError`
277
+ * 501 => `Rescuetime::Errors::NotImplemented`
278
+ * 502 => `Rescuetime::Errors::BadGateway`
279
+ * 503 => `Rescuetime::Errors::ServiceUnavailable`
280
+ * 504 => `Rescuetime::Errors::GatewayTimeout`
186
281
 
187
282
  ## Development
188
283
 
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ defaults = [:spec]
11
11
  begin
12
12
  require 'rubocop/rake_task'
13
13
  RuboCop::RakeTask.new(:rubocop)
14
- # defaults << :rubocop
14
+ defaults << :rubocop
15
15
  rescue LoadError
16
16
  puts 'Rubocop is not installed; please install it for code quality checks.'
17
17
  end
@@ -1,10 +1,75 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rescuetime/version'
4
+ require 'rescuetime/configuration'
2
5
  require 'rescuetime/client'
3
6
  require 'rescuetime/errors'
4
7
 
5
- # lib/rescuetime.rb
8
+ # Wrapper module for rescuetime gem
9
+ #
10
+ # @since v0.1.0
6
11
  module Rescuetime
7
- # Wrapper module for rescuetime gem
12
+ # class << self
13
+ # attr_writer :configuration
14
+ # end
15
+
16
+ # Passes a block to the Rescuetime configuration, allowing configuration
17
+ # options to be set.
18
+ #
19
+ # @example
20
+ # # In an initializer or before any report formatters are called:
21
+ # Rescuetime.configure do |config|
22
+ # config.formatter_paths += ['path/to/local/formatters/*_formatter.rb']
23
+ # end
24
+ #
25
+ # # Let's say that directory contains the valid formatters pdf_formatter.rb
26
+ # # and json_formatter.rb
27
+ # report_formatters = Rescuetime::ReportFormatters.new
28
+ # puts report_formatters.all
29
+ # #=> ["array", "csv", "pdf", "json"]
30
+ #
31
+ # @see Rescuetime.configuration
32
+ # @see Rescuetime::Configuration
33
+ # @since v0.4.0
34
+ def self.configure
35
+ yield(configuration)
36
+ end
37
+
38
+ # Returns either the current configuration (if set) or initializes a new
39
+ # default configuration.
40
+ #
41
+ # @example
42
+ # Rescuetime.configuration.formatter_paths
43
+ # #=> []
44
+ #
45
+ # Rescuetime.configure do |config|
46
+ # config.formatter_paths += ['formatters/*.rb']
47
+ # end
48
+ # Rescuetime.configuration.formatter_paths
49
+ # #=> ["formatters/*.rb"]
50
+ #
51
+ # @see Rescuetime::Configuration
52
+ # @return [Rescuetime::Configuration] the current Rescuetime configuration
53
+ # @since v0.4.0
54
+ def self.configuration
55
+ @configuration ||= Configuration.new
56
+ end
57
+
58
+ # Resets the configuration back to the initial state. Mainly useful for
59
+ # resetting the class after testing, making specs order-independent.
60
+ #
61
+ # @example
62
+ # before :each do
63
+ # Rescuetime.configure { |c| c.formatter_paths += ['formatters/*.rb'] }
64
+ # end
65
+ #
66
+ # after :each do
67
+ # Rescuetime.reset
68
+ # end
8
69
  #
9
- # @since v0.1.0
70
+ # @see Rescuetime::Configuration#initialize
71
+ # @since v0.4.0
72
+ def self.reset
73
+ @configuration = Configuration.new
74
+ end
10
75
  end