harvestime 0.0.1
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 +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/Guardfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/harvestime.gemspec +29 -0
- data/lib/harvestime/client_filter.rb +22 -0
- data/lib/harvestime/interface.rb +12 -0
- data/lib/harvestime/invoice.rb +57 -0
- data/lib/harvestime/invoice_collection.rb +24 -0
- data/lib/harvestime/invoice_filter.rb +58 -0
- data/lib/harvestime/time_filter.rb +68 -0
- data/lib/harvestime/version.rb +3 -0
- data/lib/harvestime.rb +14 -0
- data/spec/harvestime/invoice_collection_spec.rb +26 -0
- data/spec/harvestime/invoice_filter_spec.rb +34 -0
- data/spec/harvestime/invoice_spec.rb +147 -0
- data/spec/harvestime/time_filter_spec.rb +46 -0
- data/spec/harvestime_spec.rb +5 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/support/invoice_api_call.xml +43 -0
- data/vcr_setup.rb +6 -0
- metadata +176 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 559a08c9ec0d0fd21a452ad78357f6350ef8767f
|
4
|
+
data.tar.gz: 48344c69f00ac8585acad0cb5cb46cfd20bfd2b1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 33e5f30d6f165b4604c50643c265f155305d07625708a4f0a45bedc5372851915ed8fc668012131b69bd70baa0d9792c82ba6871bba6386064d5df5434e49725
|
7
|
+
data.tar.gz: d3b19fba40be891a06ba1046e9687447a5ff017c444dae2c3912ea61513ffdfde78218b5f12a2941b38b158f592e84b812c06b3564178cba75d957e0a800ce81
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
harvestime
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0.0-p195
|
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Nick Fausnight
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Harvestime
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'harvestime'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install harvestime
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/harvestime.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'harvestime/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "harvestime"
|
8
|
+
spec.version = Harvestime::VERSION
|
9
|
+
spec.authors = ["Nick Fausnight"]
|
10
|
+
spec.email = ["nick.s.fausnight@gmail.com"]
|
11
|
+
spec.description = %q{For streamlining and automating time and invoice management in Harvest.}
|
12
|
+
spec.summary = %q{Streamline. Automate. Harvest.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "harvested"
|
22
|
+
spec.add_dependency "nokogiri"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "guard"
|
28
|
+
spec.add_development_dependency 'guard-rspec'
|
29
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'harvested'
|
2
|
+
|
3
|
+
module Harvestime
|
4
|
+
class ClientFilter
|
5
|
+
def initialize(interface)
|
6
|
+
@interface = interface
|
7
|
+
end
|
8
|
+
def create_client(client)
|
9
|
+
@interface.clients.create(client)
|
10
|
+
end
|
11
|
+
def build_client(name)
|
12
|
+
Harvest::Client.new(name)
|
13
|
+
end
|
14
|
+
def build_client_from_existing(client)
|
15
|
+
build_client(
|
16
|
+
)
|
17
|
+
end
|
18
|
+
def get_all_clients
|
19
|
+
@interface.clients.all
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'harvested'
|
2
|
+
module Harvestime
|
3
|
+
class Interface
|
4
|
+
attr_accessor :client_filter, :invoice_filter, :time_filter
|
5
|
+
def initialize(subdomain, username, password)
|
6
|
+
@interface = Harvest.hardy_client(subdomain, username, password)
|
7
|
+
# @client_filter = Harvestime::ClientFilter.new(@interface)
|
8
|
+
@invoice_filter = Harvestime::InvoiceFilter.new(@interface)
|
9
|
+
@time_filter = Harvestime::TimeFilter.new(@interface)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'harvested'
|
2
|
+
require 'Nokogiri'
|
3
|
+
module Harvestime
|
4
|
+
class Invoice
|
5
|
+
|
6
|
+
attr_accessor :amount, :due_amount, :due_date, :human_due_date, :client_id,
|
7
|
+
:currency_type, :purchase_order, :client_key, :state, :tax_1,
|
8
|
+
:tax_2, :tax_1_amount, :tax_2_amount, :discount_amount,
|
9
|
+
:recurring_invoice_id, :estimate_id, :retainer_invoice_id,
|
10
|
+
:updated_at, :id, :created_at, :created_by, :number, :period_end,
|
11
|
+
:period_start, :notes
|
12
|
+
|
13
|
+
|
14
|
+
def retrieve(path)
|
15
|
+
file = File.open(path.to_s)
|
16
|
+
@invoice = Nokogiri::XML(file)
|
17
|
+
instantiate_values
|
18
|
+
return :success
|
19
|
+
end
|
20
|
+
|
21
|
+
def instantiate_values
|
22
|
+
@id = @invoice.xpath('//id').text.to_i
|
23
|
+
@amount = @invoice.xpath('//amount').text.to_f
|
24
|
+
@due_amount = @invoice.xpath('//due-amount').text.to_f
|
25
|
+
@due_date = parse_date(@invoice.xpath('//due-at').text)
|
26
|
+
@human_due_date = @invoice.xpath('//due-at-human-format').text
|
27
|
+
@period_end = parse_date(@invoice.xpath('//period-end').text)
|
28
|
+
@period_start = parse_date(@invoice.xpath('//period-start').text)
|
29
|
+
@client_id = @invoice.xpath('//client-id').text.to_i
|
30
|
+
@currency_type = @invoice.xpath('//currency').text
|
31
|
+
@number = @invoice.xpath('//number').text.to_i
|
32
|
+
@purchase_order = @invoice.xpath('//purchase-order').text
|
33
|
+
@client_key = @invoice.xpath('//client-key').text
|
34
|
+
@state = @invoice.xpath('//state').text
|
35
|
+
@tax_1 = @invoice.xpath('//tax').text.to_f
|
36
|
+
@tax_2 = @invoice.xpath('//tax2').text.to_f
|
37
|
+
@tax_1_amount = @invoice.xpath('//tax-amount').text.to_f
|
38
|
+
@tax_2_amount = @invoice.xpath('//tax-amount2').text.to_f
|
39
|
+
@discount_amount = @invoice.xpath('//discount-amount').text.to_f
|
40
|
+
@discount = @invoice.xpath('//discount').text.to_f
|
41
|
+
@recurring_invoice_id = @invoice.xpath('//recurring-invoice-id').text.to_i
|
42
|
+
@retainer_invoice_id = @invoice.xpath('//retainer-id').text.to_i
|
43
|
+
@updated_at = parse_date(@invoice.xpath('//updated-at').text)
|
44
|
+
@created_at = parse_date(@invoice.xpath('//created-at').text)
|
45
|
+
@created_by = @invoice.xpath('//created-by-id').text.to_i
|
46
|
+
@notes = @invoice.xpath('//notes').text
|
47
|
+
@estimate_id = @invoice.xpath('//estimate-id').text.to_i
|
48
|
+
end
|
49
|
+
|
50
|
+
def parse_date(string)
|
51
|
+
Date.parse(string)
|
52
|
+
rescue
|
53
|
+
Time.new("").to_date
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Harvestime
|
2
|
+
class InvoiceCollection
|
3
|
+
|
4
|
+
def initialize(*args)
|
5
|
+
@container = []
|
6
|
+
self.add(args)
|
7
|
+
end
|
8
|
+
|
9
|
+
def add(*args)
|
10
|
+
@container.concat(args)
|
11
|
+
clean_up
|
12
|
+
args
|
13
|
+
end
|
14
|
+
|
15
|
+
def retrieve
|
16
|
+
@container
|
17
|
+
end
|
18
|
+
|
19
|
+
def clean_up
|
20
|
+
@container.flatten!
|
21
|
+
@container.uniq!
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require'harvested'
|
2
|
+
module Harvestime
|
3
|
+
class InvoiceFilter
|
4
|
+
|
5
|
+
def initialize(client)
|
6
|
+
@client = client
|
7
|
+
end
|
8
|
+
|
9
|
+
def all_with_status(state)
|
10
|
+
@client.invoices.all(status: state.to_s)
|
11
|
+
end
|
12
|
+
|
13
|
+
def all_invoices
|
14
|
+
@client.invoices.all
|
15
|
+
end
|
16
|
+
|
17
|
+
def all_by_client_id(client_id)
|
18
|
+
collection = []
|
19
|
+
all_invoices.each do |invoice|
|
20
|
+
collection << invoice if invoice.client_id == client_id
|
21
|
+
end
|
22
|
+
collection
|
23
|
+
end
|
24
|
+
|
25
|
+
def all_with_status_and_client(state, client_id)
|
26
|
+
collection = []
|
27
|
+
all_with_status(state).each do |invoice|
|
28
|
+
collection << invoice if invoice.client_id == client_id
|
29
|
+
end
|
30
|
+
collection
|
31
|
+
end
|
32
|
+
# # Unnecessary
|
33
|
+
# def outstanding_invoices
|
34
|
+
# all_with_status(:unpaid)
|
35
|
+
# end
|
36
|
+
|
37
|
+
# def draft_invoices
|
38
|
+
# all_with_status(:draft)
|
39
|
+
# end
|
40
|
+
|
41
|
+
# def partial_invoices
|
42
|
+
# all_with_status(:partial)
|
43
|
+
# end
|
44
|
+
|
45
|
+
# def unpaid_invoices
|
46
|
+
# all_with_status(:unpaid)
|
47
|
+
# end
|
48
|
+
|
49
|
+
# def paid_invoices
|
50
|
+
# all_with_status(:paid)
|
51
|
+
# end
|
52
|
+
|
53
|
+
# # coupled
|
54
|
+
# def outstanding_by_client_id(client_id)
|
55
|
+
# all_with_status_and_client(:unpaid, client_id)
|
56
|
+
# end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'harvested'
|
2
|
+
|
3
|
+
module Harvestime
|
4
|
+
class TimeFilter
|
5
|
+
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
|
10
|
+
def scale_entry(time_entry, modifier)
|
11
|
+
time_entry.hours = time_entry.hours * modifier
|
12
|
+
@client.time.update(time_entry)
|
13
|
+
time_entry.hours
|
14
|
+
end
|
15
|
+
# Current date only
|
16
|
+
def all_times
|
17
|
+
@client.time.all
|
18
|
+
end
|
19
|
+
|
20
|
+
def all_times_in_date(time)
|
21
|
+
@client.time.all(time)
|
22
|
+
end
|
23
|
+
|
24
|
+
def move_entry_from(other_account, entry)
|
25
|
+
create_entry(build_entry_from_existing(entry))
|
26
|
+
other_account.time.delete(entry)
|
27
|
+
:success
|
28
|
+
end
|
29
|
+
# build / create delivers ER404 (sometimes)
|
30
|
+
def build_entry(args = {})
|
31
|
+
Harvest::TimeEntry.new(
|
32
|
+
{ notes: '',
|
33
|
+
hours: '0',
|
34
|
+
project_id: 0,
|
35
|
+
task_id: 0,
|
36
|
+
spent_at: Time.now.strftime('%a, %e %b %Y')
|
37
|
+
}.merge(args)
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
def build_entry_from_existing(entry)
|
42
|
+
Harvest::TimeEntry.new(
|
43
|
+
notes: entry.notes,
|
44
|
+
hours: entry.hours,
|
45
|
+
project_id: entry.project_id,
|
46
|
+
task_id: entry.task_id,
|
47
|
+
spent_at: entry.spent_at
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
def clear_daily_entries
|
52
|
+
@client.time.all.each do |entry|
|
53
|
+
delete_entry(entry)
|
54
|
+
end
|
55
|
+
:success
|
56
|
+
end
|
57
|
+
|
58
|
+
def delete_entry(entry)
|
59
|
+
@client.time.delete(entry)
|
60
|
+
:success
|
61
|
+
end
|
62
|
+
|
63
|
+
def create_entry (entry)
|
64
|
+
@client.time.create(entry)
|
65
|
+
:success
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/harvestime.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'harvested'
|
2
|
+
|
3
|
+
require 'harvestime/version'
|
4
|
+
require 'harvestime/invoice_collection'
|
5
|
+
require 'harvestime/invoice_filter'
|
6
|
+
require 'harvestime/time_filter'
|
7
|
+
require 'harvestime/invoice'
|
8
|
+
require 'harvestime/interface'
|
9
|
+
|
10
|
+
module Harvestime
|
11
|
+
def self.interface(subdomain, username, password)
|
12
|
+
Harvestime::Interface.new(subdomain, username, password)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'harvested'
|
3
|
+
require File.expand_path('lib/harvestime/invoice_collection')
|
4
|
+
|
5
|
+
describe 'Harvestime::InvoiceCollection' do
|
6
|
+
let(:invoices) { Harvestime::InvoiceCollection.new}
|
7
|
+
let(:invoice ) { Harvest::Invoice.new(:line_items => "kind,description,quantity,unit_price,amount,taxed,taxed2,project_id\nService,Abc,200,12.00,2400.0,false,false,100\nService,def,1.00,20.00,20.0,false,false,101\n") }
|
8
|
+
|
9
|
+
it "should recieve an invoice and add it to its collection" do
|
10
|
+
expect(invoices.add(invoice)).to eq([invoice])
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should give its collection" do
|
14
|
+
expect(invoices.retrieve).to be_a_kind_of(Array)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should ignore duplicate entries" do
|
18
|
+
expected_collection = Harvestime::InvoiceCollection.new(invoice)
|
19
|
+
|
20
|
+
3.times { invoices.add(invoice) }
|
21
|
+
|
22
|
+
expect(invoices.retrieve).to eq(expected_collection.retrieve)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# InvoiceCollection.retrieve => [Invoice, Invoice, Invoice, Invoice, Invoice]
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'harvested'
|
3
|
+
require 'harvestime'
|
4
|
+
require File.expand_path('lib/harvestime/invoice_filter')
|
5
|
+
describe 'Harvestime::InvoiceFilter' do
|
6
|
+
let(:client) { Harvest.hardy_client('subdomain',
|
7
|
+
'username@email.com',
|
8
|
+
'password') }
|
9
|
+
let(:filter) { Harvestime::InvoiceFilter.new(client) }
|
10
|
+
it "should build an InvoiceCollection" do
|
11
|
+
expect(filter.all_invoices).to be_a_kind_of(Array)
|
12
|
+
# expect(filter.all_invoices.size).to eq(3)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns all outstanding invoices" do
|
16
|
+
expect(filter.all_with_status(:unpaid)).to be_a_kind_of(Array)
|
17
|
+
# expect(filter.outstanding_invoices.size).to eq(2)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns a collection of paid invoices" do
|
21
|
+
expect(filter.all_with_status(:paid)).to be_a_kind_of(Array)
|
22
|
+
# expect(filter.paid_invoices.size).to eq(1)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should get all invoices by a client" do
|
26
|
+
expect(filter.all_by_client_id(1761076)).to be_a_kind_of(Array)
|
27
|
+
# expect(filter.all_by_client_id(1761076).size).to eq(2)
|
28
|
+
end
|
29
|
+
it "should get outstanding invoices by a client" do
|
30
|
+
expect(filter.all_with_status_and_client(:unpaid, 1761076))
|
31
|
+
.to be_a_kind_of(Array)
|
32
|
+
# expect(filter.outstanding_by_client_id(1761076).size).to eq(1)
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require File.expand_path('lib/harvestime/invoice')
|
3
|
+
|
4
|
+
describe "Harvestime::" do
|
5
|
+
describe "Invoice" do
|
6
|
+
let(:invoice) { Harvestime::Invoice.new }
|
7
|
+
|
8
|
+
it "should instantiate from xml" do
|
9
|
+
xml_document = File.open("spec/support/invoice_api_call.xml")
|
10
|
+
expect(invoice.retrieve("spec/support/invoice_api_call.xml")).to be(:success)
|
11
|
+
end
|
12
|
+
|
13
|
+
context "date parsing" do
|
14
|
+
it "should handle date format" do
|
15
|
+
string = "2008-04-09T12:07:56Z"
|
16
|
+
expectation = Date.new(2_008, 4, 9)
|
17
|
+
expect(invoice.parse_date(string)).to eq(expectation)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should handle blank date" do
|
21
|
+
string = ""
|
22
|
+
expectation = Time.new("").to_date
|
23
|
+
expect(invoice.parse_date(string)).to eq(expectation)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "attribute fields" do
|
28
|
+
before(:each) do
|
29
|
+
xml_document = File.open("spec/support/invoice_api_call.xml")
|
30
|
+
invoice.retrieve("spec/support/invoice_api_call.xml")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should have an id" do
|
34
|
+
expect(invoice.id).to be_a_kind_of(Integer)
|
35
|
+
expect(invoice.id).to eq(1234567)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should have an amount" do
|
39
|
+
expect(invoice.amount).to be_a_kind_of(Float)
|
40
|
+
expect(invoice.amount).to eq(1155.0)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should have the due amount" do
|
44
|
+
expect(invoice.due_amount).to be_a_kind_of(Float)
|
45
|
+
expect(invoice.due_amount).to eq(0.0)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should have the due at date" do
|
49
|
+
expect(invoice.due_date).to be_a_kind_of(Date)
|
50
|
+
expect(invoice.due_date).to eq(Date.parse('2008-02-06'))
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should have the human form of the due date" do
|
54
|
+
expect(invoice.human_due_date).to be_a_kind_of(String)
|
55
|
+
expect(invoice.human_due_date).to eq('due upon receipt')
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should have the period end date" do
|
59
|
+
expect(invoice.period_end).to be_a_kind_of(Date)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should have the period start date" do
|
63
|
+
expect(invoice.period_start).to be_a_kind_of(Date)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should have the client's id" do
|
67
|
+
expect(invoice.client_id).to be_a_kind_of(Integer)
|
68
|
+
expect(invoice.client_id).to eq(46_066)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should have the currency type" do
|
72
|
+
expect(invoice.currency_type).to be_a_kind_of(String)
|
73
|
+
expect(invoice.currency_type).to eq('United States Dollars - USD')
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should have the created by id" do
|
77
|
+
expect(invoice.created_by).to be_a_kind_of(Integer)
|
78
|
+
expect(invoice.created_by).to eq(123_456)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should have a number" do
|
82
|
+
expect(invoice.number).to be_a_kind_of(Integer)
|
83
|
+
expect(invoice.number).to eq(8_008)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should have the invoice notes" do
|
87
|
+
expect(invoice.notes).to be_a_kind_of(String)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should have a purchase order" do
|
91
|
+
expect(invoice.purchase_order).to be_a_kind_of(String)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should have a client key" do
|
95
|
+
expect(invoice.client_key).to be_a_kind_of(String)
|
96
|
+
expect(invoice.client_key).to eq('f2a56b1232ad1asdf5926f040e8cff2befb5e8f1')
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should have a state" do
|
100
|
+
expect(invoice.state).to be_a_kind_of(String)
|
101
|
+
expect(invoice.state).to eq('paid')
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should have an applied Tax 1 value" do
|
105
|
+
expect(invoice.tax_1).to be_a_kind_of(Float)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should have an applied Tax 2 value" do
|
109
|
+
expect(invoice.tax_2).to be_a_kind_of(Float)
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should have a first tax amount" do
|
113
|
+
expect(invoice.tax_1_amount).to be_a_kind_of(Float)
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should have the second tax amount" do
|
117
|
+
expect(invoice.tax_2_amount).to be_a_kind_of(Float)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should have a discount amount" do
|
121
|
+
expect(invoice.discount_amount).to be_a_kind_of(Float)
|
122
|
+
expect(invoice.discount_amount).to eq(0.0)
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should have a recurring invoice id" do
|
126
|
+
expect(invoice.recurring_invoice_id).to be_a_kind_of(Integer)
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should have an estimate id" do
|
130
|
+
expect(invoice.estimate_id).to be_a_kind_of(Integer)
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should have a retainer invoice id" do
|
134
|
+
expect(invoice.retainer_invoice_id).to be_a_kind_of(Integer)
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should have a created at date" do
|
138
|
+
expect(invoice.created_at).to be_a_kind_of(Date)
|
139
|
+
expect(invoice.created_at).to eq(Date.parse('2008-04-09T12:07:56Z'))
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should have an updated at date" do
|
143
|
+
expect(invoice.updated_at).to be_a_kind_of(Date)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'harvested'
|
3
|
+
|
4
|
+
require File.expand_path('lib/harvestime/time_filter.rb')
|
5
|
+
describe 'Harvestime::TimeFilter' do
|
6
|
+
# Interface one
|
7
|
+
let(:client) {Harvest.hardy_client('subdomain',
|
8
|
+
'username@email.com',
|
9
|
+
'password')}
|
10
|
+
# Interface two
|
11
|
+
let(:client2) {Harvest.hardy_client('subdomain',
|
12
|
+
'username@email.com',
|
13
|
+
'password')}
|
14
|
+
# Get rid of this
|
15
|
+
let(:time_filter) { Harvestime::TimeFilter.new(client) }
|
16
|
+
|
17
|
+
it 'should scale hours down based on a given modifier' do
|
18
|
+
modifier = 0.8
|
19
|
+
time = client.time.all(Time.parse('6/21'))[0]
|
20
|
+
hours = time.hours
|
21
|
+
expect(time_filter.scale_entry(time, modifier))
|
22
|
+
.to eq(hours * modifier)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should transfer time entry from another account' do
|
26
|
+
|
27
|
+
entry = client2.time.all[0]
|
28
|
+
expect(time_filter.move_entry_from(client2, entry))
|
29
|
+
.to eq(:success)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should create a time entry' do
|
33
|
+
notes = 'Sample note'
|
34
|
+
hours = 12
|
35
|
+
project_id = client.projects.all[0].id
|
36
|
+
task_id = client.tasks.all[0].id
|
37
|
+
spent_at = Time.now
|
38
|
+
|
39
|
+
entry = time_filter.build_entry(notes: notes,
|
40
|
+
hours: hours,
|
41
|
+
project_id: project_id,
|
42
|
+
task_id: task_id,
|
43
|
+
spent_at: spent_at)
|
44
|
+
expect(time_filter.create_entry(entry)).to eq(:success)
|
45
|
+
end
|
46
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
<invoice>
|
2
|
+
<id type="integer">1234567</id>
|
3
|
+
<amount type="decimal">1155.0</amount>
|
4
|
+
<due-amount type="decimal">0.0</due-amount>
|
5
|
+
<due-at type="date">2008-02-06</due-at>
|
6
|
+
<!-- human representation for due at -->
|
7
|
+
<due-at-human-format>due upon receipt</due-at-human-format>
|
8
|
+
<!-- invoiced period, present for generated invoices -->
|
9
|
+
<period-end type="date" nil="true"></period-end>
|
10
|
+
<period-start type="date" nil="true"></period-start>
|
11
|
+
<client-id type="integer">46066</client-id>
|
12
|
+
<!-- see -->
|
13
|
+
<currency>United States Dollars - USD</currency>
|
14
|
+
<issued-at type="date">2008-02-06</issued-at>
|
15
|
+
<created-by-id type="integer">123456</created-by-id>
|
16
|
+
<notes></notes>
|
17
|
+
<number>8008</number>
|
18
|
+
<purchase-order></purchase-order>
|
19
|
+
<client-key>f2a56b1232ad1asdf5926f040e8cff2befb5e8f1</client-key>
|
20
|
+
<!-- See invoice messages and invoice payments for manipulating the
|
21
|
+
state attribute. Direct assignment will be ignored. Options are open,
|
22
|
+
draft, partial, paid and closed.-->
|
23
|
+
<state>paid</state>
|
24
|
+
<!-- applied tax percentage, blank if not taxed -->
|
25
|
+
<tax type="decimal" nil="true"></tax>
|
26
|
+
<!-- applied tax 2 percentage, blank if not taxed -->
|
27
|
+
<tax2 type="decimal" nil="true"></tax2>
|
28
|
+
<!-- the first tax amount -->
|
29
|
+
<tax-amount type="decimal" nil="true"></tax-amount>
|
30
|
+
<!-- the second tax amount -->
|
31
|
+
<tax-amount2 type="decimal" nil="true"></tax-amount2>
|
32
|
+
<!-- discount -->
|
33
|
+
<discount-amount type="decimal">0.0</discount-amount>
|
34
|
+
<discount type="decimal" nil="true"></discount>
|
35
|
+
<!-- is it recurring? -->
|
36
|
+
<recurring-invoice-id type="integer" nil="true"></recurring-invoice-id>
|
37
|
+
<!-- was this converted from an estimate? -->
|
38
|
+
<estimate-id type="integer" nil="true"></estimate-id>
|
39
|
+
<!-- retainer invoice? -->
|
40
|
+
<retainer-id type="integer">12345</retainer-id>
|
41
|
+
<updated-at type="datetime">2008-04-09T12:07:56Z</updated-at>
|
42
|
+
<created-at type="datetime">2008-04-09T12:07:56Z</created-at>
|
43
|
+
</invoice>
|
data/vcr_setup.rb
ADDED
metadata
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: harvestime
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Fausnight
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: harvested
|
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: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard-rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: For streamlining and automating time and invoice management in Harvest.
|
112
|
+
email:
|
113
|
+
- nick.s.fausnight@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .DS_Store
|
119
|
+
- .gitignore
|
120
|
+
- .rspec
|
121
|
+
- .ruby-gemset
|
122
|
+
- .ruby-version
|
123
|
+
- Gemfile
|
124
|
+
- Guardfile
|
125
|
+
- LICENSE.txt
|
126
|
+
- README.md
|
127
|
+
- Rakefile
|
128
|
+
- harvestime.gemspec
|
129
|
+
- lib/harvestime.rb
|
130
|
+
- lib/harvestime/client_filter.rb
|
131
|
+
- lib/harvestime/interface.rb
|
132
|
+
- lib/harvestime/invoice.rb
|
133
|
+
- lib/harvestime/invoice_collection.rb
|
134
|
+
- lib/harvestime/invoice_filter.rb
|
135
|
+
- lib/harvestime/time_filter.rb
|
136
|
+
- lib/harvestime/version.rb
|
137
|
+
- spec/harvestime/invoice_collection_spec.rb
|
138
|
+
- spec/harvestime/invoice_filter_spec.rb
|
139
|
+
- spec/harvestime/invoice_spec.rb
|
140
|
+
- spec/harvestime/time_filter_spec.rb
|
141
|
+
- spec/harvestime_spec.rb
|
142
|
+
- spec/spec_helper.rb
|
143
|
+
- spec/support/invoice_api_call.xml
|
144
|
+
- vcr_setup.rb
|
145
|
+
homepage: ''
|
146
|
+
licenses:
|
147
|
+
- MIT
|
148
|
+
metadata: {}
|
149
|
+
post_install_message:
|
150
|
+
rdoc_options: []
|
151
|
+
require_paths:
|
152
|
+
- lib
|
153
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - '>='
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
requirements: []
|
164
|
+
rubyforge_project:
|
165
|
+
rubygems_version: 2.0.3
|
166
|
+
signing_key:
|
167
|
+
specification_version: 4
|
168
|
+
summary: Streamline. Automate. Harvest.
|
169
|
+
test_files:
|
170
|
+
- spec/harvestime/invoice_collection_spec.rb
|
171
|
+
- spec/harvestime/invoice_filter_spec.rb
|
172
|
+
- spec/harvestime/invoice_spec.rb
|
173
|
+
- spec/harvestime/time_filter_spec.rb
|
174
|
+
- spec/harvestime_spec.rb
|
175
|
+
- spec/spec_helper.rb
|
176
|
+
- spec/support/invoice_api_call.xml
|