rescuetime 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6464e2b8b391cfa2b334288ba6cdbd81fe7728f6
4
- data.tar.gz: e293998bd6552509d6225422b1a7f029a26dcde3
3
+ metadata.gz: ce870b11b2ff5bc0257b76ef6e494a279dedd5b8
4
+ data.tar.gz: 5d2a5e4e0884b38c321cdd6a64dcb4a00da2d57c
5
5
  SHA512:
6
- metadata.gz: 4e022e5eefb8a858051f8c5264d394562ba6939381beb5b9072807f2dad2a70f9d8047ada933a2be9172ba050ed5b71ed41e51934e1b2a8ade83bd67d7a645c2
7
- data.tar.gz: 8c09915abb016f0680d9b48c1f45362ccf6312fc970f1e58d38feeb25e15afda6cfeba1d5f18a877712ac7b29bce2e65f39cdf14ebea57caf79f26fbcdc5df33
6
+ metadata.gz: ec48c9a8f5c98ffe39c1e43ff2342d617b20ffc95fb785ed25d171dd0d3f43184234064d1488aebd4f5a274a38bda29f1febb3e2e365c249d518a2baa96acf63
7
+ data.tar.gz: 3f24d854c6e41263ac3ad2012e55743eefd7c72d1a7960e3749c8002d59c0213bbf33cecc2a20891ad569ad50aec8fe84dabad5cae115b4ea290743b6be27540
@@ -1,6 +1,3 @@
1
- require 'faraday'
2
- require 'csv'
3
-
4
1
  require 'rescuetime/query_buildable'
5
2
 
6
3
  require 'rescuetime/requester'
@@ -1,3 +1,5 @@
1
+ require 'csv'
2
+
1
3
  require 'rescuetime/query_buildable'
2
4
 
3
5
  module Rescuetime
@@ -34,7 +36,9 @@ module Rescuetime
34
36
  #
35
37
  # @see Rescuetime::Requester#get
36
38
  def all
37
- parse_response Requester.get(HOST, params).body
39
+ requester = Rescuetime::Requester
40
+ host = HOST
41
+ parse_response requester.get(host, params)
38
42
  end
39
43
 
40
44
  # Enumerates over the collection of Rescuetime report records. Performs
@@ -20,7 +20,7 @@ module Rescuetime
20
20
  # @param [String] host request host
21
21
  # @param [Hash] params request parameters
22
22
  # @param [#get] http HTTP requester
23
- # @return [Faraday::Response]
23
+ # @return [String]
24
24
  #
25
25
  # @raise [Rescuetime::MissingCredentialsError] if no api key is present
26
26
  # @raise [Rescuetime::InvalidCredentialsError] if api key is incorrect
@@ -29,31 +29,38 @@ module Rescuetime
29
29
  # not 200
30
30
  #
31
31
  # @see Rescuetime::Client#api_key=
32
- def get(host, params, http: Faraday)
32
+ def get(host, params, http: Net::HTTP)
33
33
  # Fail if no api key is provided
34
34
  unless params[:key] && !params[:key].to_s.empty?
35
35
  fail(Rescuetime::MissingCredentialsError)
36
36
  end
37
37
 
38
- req_params = params.delete_if { |_, v| !v || v.to_s.empty? }
39
- response = http.get host, req_params
38
+ uri = set_uri host, params
39
+ response = http.get_response uri
40
40
 
41
- fail_or_return response
41
+ fail_or_return_body response
42
42
  end
43
43
 
44
44
  private
45
45
 
46
+ def set_uri(host, params)
47
+ req_params = params.delete_if { |_, v| !v || v.to_s.empty? }
48
+ uri = URI(host)
49
+ uri.query = URI.encode_www_form(req_params)
50
+ uri
51
+ end
52
+
46
53
  # Checks for an error in the Rescuetime response. If an error was recieved
47
54
  # raise the appropriate Rescuetime::Error. Otherwise, return the response.
48
55
  #
49
- # @param [Faraday::Response] response HTTP response from rescuetime.com
50
- # @return [Faraday::Response] 200 HTTP response from rescuetime.com
56
+ # @param [Net::HTTPResponse] response HTTP response from rescuetime.com
57
+ # @return [String] valid response body
51
58
  #
52
59
  # @raise [Rescuetime::InvalidCredentialsError] if api key is incorrect
53
60
  # @raise [Rescuetime::InvalidQueryError] if query is badly formed
54
61
  # @raise [Rescuetime::Error] an error that varies based on the
55
62
  # response status
56
- def fail_or_return(response)
63
+ def fail_or_return_body(response)
57
64
  # match the response body to known error messages with 200 status
58
65
  case response.body
59
66
  when key_not_found? then fail Rescuetime::InvalidCredentialsError
@@ -61,10 +68,11 @@ module Rescuetime
61
68
  end
62
69
 
63
70
  # check the response status for errors
64
- error = Rescuetime::Error::CODES[response.status.to_i]
71
+ status = response.code.to_i
72
+ error = Rescuetime::Error::CODES[status]
65
73
  fail(error) if error
66
74
 
67
- response
75
+ response.body
68
76
  end
69
77
 
70
78
  # Returns lambda that returns true if the response body states that the
@@ -1,5 +1,5 @@
1
1
  # lib/rescuetime/version.rb
2
2
  module Rescuetime
3
3
  # rescuetime gem version number
4
- VERSION = '0.3.2'
4
+ VERSION = '0.3.3'
5
5
  end
data/rescuetime.gemspec CHANGED
@@ -15,15 +15,13 @@ Gem::Specification.new do |spec|
15
15
  spec.license = 'MIT'
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0")
18
- .reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ .reject { |f| f.match(%r{^(test|spec|features)/}) }
19
19
  spec.bindir = 'exe'
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ['lib']
22
22
 
23
23
  spec.required_ruby_version = '>= 2.0.0'
24
24
 
25
- spec.add_dependency 'faraday', '~> 0.9.1'
26
-
27
25
  spec.add_development_dependency 'bundler'
28
26
  spec.add_development_dependency 'rake', '~> 10.4', '>= 10.4.2'
29
27
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rescuetime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Sharma
@@ -10,20 +10,6 @@ bindir: exe
10
10
  cert_chain: []
11
11
  date: 2016-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: faraday
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 0.9.1
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 0.9.1
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: bundler
29
15
  requirement: !ruby/object:Gem::Requirement