harvested 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY CHANGED
@@ -1,3 +1,6 @@
1
+ 0.6.1 - August 22, 2012
2
+ * Adds options to "all" finder (thanks Mikel Lindsaar)
3
+ * Adds Unauthorized error type (thanks @bcobb)
1
4
  0.6.0 - August 22, 2012
2
5
  * Replaces Dash with Mash
3
6
  0.5.3 - August 21, 2012
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Harvested: A Ruby Harvest API
2
2
 
3
- This is a Ruby wrapper for the [Harvest API](http://www.getharvest.com/).
3
+ This is a Ruby wrapper for the [Harvest API](http://www.getharvest.com/api).
4
4
 
5
5
  ## Installation
6
6
 
@@ -17,6 +17,20 @@ client = harvest.clients.create(client)
17
17
  harvest.clients.find(client.id) # returns a Harvest::Client
18
18
  ```
19
19
 
20
+ You can also pass query options in as the last parameter on any objects `all` finder
21
+ method, for example to find all the projects for client ID 12345:
22
+
23
+ ```ruby
24
+ harvest = Harvest.client('yoursubdomain', 'yourusername', 'yourpassword')
25
+ harvest.projects.harvest.projects.all(nil, :client => 12345)
26
+ ```
27
+
28
+ Note, the second parameter is a User ID field that is optional, but needs to be specified
29
+ as nil if not included.
30
+
31
+ You can pass in any hash of query attributes you wish as per the
32
+ [Harvest API](http://www.getharvest.com/api) page.
33
+
20
34
  You can find more examples in `/examples` and in the documentation for Harvest::Base
21
35
 
22
36
  ## Hardy Client
@@ -50,20 +64,20 @@ http://github.com/zmoazeni/harvested/issues/
50
64
  2. If you don’t see anything, create an issue with information on how to reproduce it.
51
65
 
52
66
  If you want to contribute an enhancement or a fix:
53
-
67
+
54
68
  1. Fork the project on github http://github.com/zmoazeni/harvested
55
69
  2. Make your changes with tests
56
70
  3. Commit the changes without messing with the Rakefile, VERSION, or history
57
71
  4. Send me a pull request
58
72
 
59
- Note on running tests: most specs run against a live Harvest account. To run the suite, sign up for a free trial account and fill out `/spec/support/harvest_credentials.yml` *(a sample harvest_credentials.example.yml has been included)*.
73
+ Note on running tests: most specs run against a live Harvest account. To run the suite, sign up for a free trial account and fill out `/spec/support/harvest_credentials.yml` *(a sample harvest_credentials.example.yml has been included)*.
60
74
 
61
75
  **DO NOT USE YOUR NORMAL CREDENTIALS IN `/spec/support/harvest_credentials.yml`!!!** The test suite blasts all the data before running (similiar to DatabaseCleaner).
62
76
 
63
77
  The tests use [VCR](https://github.com/myronmarston/vcr) to cache the test responses. This is a great boon for running the tests offline. While uncommon, sometimes the Harvest API will send an erroneous response and VCR will cache it, then subsequent runs will use the incorrect cached response. In order to ignore VCR you can run the specs by passing CACHE=false (e.g. `CACHE=false bundle rake spec`).
64
78
 
65
79
  Using [rvm](https://rvm.beginrescueend.com/) you can run the tests against the popular ruby runtimes by running:
66
-
80
+
67
81
  ./spec/test_rubies
68
82
 
69
83
  Each runtime needs to be installed in rvm along with the bundler gem.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.6.1
data/harvested.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "harvested"
8
- s.version = "0.6.0"
8
+ s.version = "0.6.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Zach Moazeni"]
@@ -43,6 +43,8 @@ module Harvest
43
43
  response
44
44
  when 400
45
45
  raise Harvest::BadRequest.new(response, params)
46
+ when 401
47
+ raise Harvest::AuthenticationFailed.new(response, params)
46
48
  when 404
47
49
  raise Harvest::NotFound.new(response, params)
48
50
  when 500
@@ -61,4 +63,4 @@ module Harvest
61
63
  end
62
64
  end
63
65
  end
64
- end
66
+ end
@@ -3,11 +3,12 @@ module Harvest
3
3
  module Crud
4
4
  # Retrieves all items
5
5
  # @return [Array<Harvest::BaseModel>] an array of models depending on where you're calling it from (e.g. [Harvest::Client] from Harvest::Base#clients)
6
- def all(user = nil)
7
- response = request(:get, credentials, api_model.api_path, :query => of_user_query(user))
6
+ def all(user = nil, query_options = {})
7
+ query = query_options.merge!(of_user_query(user))
8
+ response = request(:get, credentials, api_model.api_path, :query => query)
8
9
  api_model.parse(response.parsed_response)
9
10
  end
10
-
11
+
11
12
  # Retrieves an item by id
12
13
  # @overload find(id)
13
14
  # @param [Integer] the id of the item you want to retreive
@@ -15,13 +16,13 @@ module Harvest
15
16
  # @param [String] id the String version of the id
16
17
  # @overload find(model)
17
18
  # @param [Harvest::BaseModel] id you can pass a model and it will return a refreshed version
18
- #
19
+ #
19
20
  # @return [Harvest::BaseModel] the model depends on where you're calling it from (e.g. Harvest::Client from Harvest::Base#clients)
20
21
  def find(id, user = nil)
21
22
  response = request(:get, credentials, "#{api_model.api_path}/#{id}", :query => of_user_query(user))
22
23
  api_model.parse(response.parsed_response).first
23
24
  end
24
-
25
+
25
26
  # Creates an item
26
27
  # @param [Harvest::BaseModel] model the item you want to create
27
28
  # @return [Harvest::BaseModel] the created model depending on where you're calling it from (e.g. Harvest::Client from Harvest::Base#clients)
@@ -31,7 +32,7 @@ module Harvest
31
32
  id = response.headers["location"].match(/\/.*\/(\d+)/)[1]
32
33
  find(id, model.impersonated_user_id)
33
34
  end
34
-
35
+
35
36
  # Updates an item
36
37
  # @param [Harvest::BaseModel] model the model you want to update
37
38
  # @return [Harvest::BaseModel] the created model depending on where you're calling it from (e.g. Harvest::Client from Harvest::Base#clients)
@@ -40,7 +41,7 @@ module Harvest
40
41
  request(:put, credentials, "#{api_model.api_path}/#{model.to_i}", :body => model.to_json, :query => of_user_query(user))
41
42
  find(model.id)
42
43
  end
43
-
44
+
44
45
  # Deletes an item
45
46
  # @overload delete(model)
46
47
  # @param [Harvest::BaseModel] model the item you want to delete
@@ -48,7 +49,7 @@ module Harvest
48
49
  # @param [Integer] id the id of the item you want to delete
49
50
  # @overload delete(id)
50
51
  # @param [String] id the String version of the id of the item you want to delete
51
- #
52
+ #
52
53
  # @return [Integer] the id of the item deleted
53
54
  def delete(model, user = nil)
54
55
  request(:delete, credentials, "#{api_model.api_path}/#{model.to_i}", :query => of_user_query(user))
@@ -22,4 +22,5 @@ module Harvest
22
22
  class InformHarvest < HTTPError; end
23
23
  class BadRequest < HTTPError; end
24
24
  class ServerError < HTTPError; end
25
- end
25
+ class AuthenticationFailed < HTTPError ; end
26
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: harvested
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -261,7 +261,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
261
261
  version: '0'
262
262
  segments:
263
263
  - 0
264
- hash: -3859920276334034236
264
+ hash: -3050275460586809448
265
265
  required_rubygems_version: !ruby/object:Gem::Requirement
266
266
  none: false
267
267
  requirements: