costagent 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.rdoc +9 -1
  2. data/lib/costagent.rb +57 -5
  3. metadata +10 -4
data/README.rdoc CHANGED
@@ -40,6 +40,14 @@ To return all tasks for a specific project:
40
40
 
41
41
  tasks = costagent.tasks(project_id)
42
42
 
43
+ To return all invoices for the account:
44
+
45
+ invoices = costagent.invoices
46
+
47
+ To lookup a specific invoice:
48
+
49
+ invoice = costagent.invoice(id)
50
+
43
51
  To return your FA user ID:
44
52
 
45
53
  costagent.user_id
@@ -90,4 +98,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
90
98
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
91
99
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
92
100
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
93
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
101
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/lib/costagent.rb CHANGED
@@ -6,9 +6,11 @@ require "open-uri"
6
6
 
7
7
  # This exposes additional billable tracking functionality around the Freeagent API
8
8
  class CostAgent
9
- Project = Struct.new(:id, :name, :currency, :hourly_billing_rate)
10
- Timeslip = Struct.new(:id, :project, :hours, :date, :cost)
9
+ Project = Struct.new(:id, :name, :currency, :hourly_billing_rate, :daily_billing_rate, :hours_per_day)
10
+ Timeslip = Struct.new(:id, :project, :hours, :date, :cost, :comment, :status)
11
11
  Task = Struct.new(:id, :name, :project)
12
+ Invoice = Struct.new(:id, :project_id, :description, :reference, :amount, :status, :date, :due, :items)
13
+ InvoiceItem = Struct.new(:id, :invoice_id, :project_id, :item_type, :description, :price, :quantity, :cost)
12
14
 
13
15
  attr_accessor :subdomain, :username, :password
14
16
 
@@ -25,7 +27,19 @@ class CostAgent
25
27
  # Returns all projects
26
28
  def projects(filter = "active")
27
29
  @projects ||= {}
28
- @projects[filter] ||= (self.api("projects", {:view => filter})/"project").collect { |project| Project.new((project/"id").text.to_i, (project/"name").text, (project/"currency").text, (project/"normal-billing-rate").text.to_f) }
30
+ @projects[filter] ||= (self.api("projects", {:view => filter})/"project").collect do |project|
31
+ billing_rate = (project/"normal-billing-rate").text.to_f
32
+ hours_per_day = (project/"hours-per-day").text.to_f
33
+ billing_period = (project/"billing-period").text
34
+ hourly_rate = (billing_period == "hour" ? billing_rate : billing_rate / hours_per_day)
35
+ daily_rate = (billing_period == "hour" ? billing_rate * hours_per_day : billing_rate)
36
+ Project.new((project/"id").text.to_i,
37
+ (project/"name").text,
38
+ (project/"currency").text,
39
+ hourly_rate,
40
+ daily_rate,
41
+ hours_per_day)
42
+ end
29
43
  end
30
44
 
31
45
  # This returns the specified project
@@ -44,8 +58,10 @@ class CostAgent
44
58
  Timeslip.new((timeslip/"id").text.to_i,
45
59
  project,
46
60
  hours,
47
- DateTime.parse((timeslip/"updated-at").text),
48
- project.hourly_billing_rate * hours)
61
+ DateTime.parse((timeslip/"dated-on").text),
62
+ project.hourly_billing_rate * hours,
63
+ (timeslip/"comment").text,
64
+ (timeslip/"status").text)
49
65
  else
50
66
  nil
51
67
  end
@@ -64,6 +80,42 @@ class CostAgent
64
80
  end
65
81
  end
66
82
 
83
+ # This returns all invoices
84
+ def invoices
85
+ @invoices ||= (self.api("invoices")/"invoice").collect do |invoice|
86
+ items = (invoice/"invoice-item").collect do |item|
87
+ price = (item/"price").first.inner_text.to_f
88
+ quantity = (item/"quantity").first.inner_text.to_f
89
+ cost = price * quantity
90
+ InvoiceItem.new(
91
+ (item/"id").first.inner_text.to_i,
92
+ (item/"invoice-id").first.inner_text.to_i,
93
+ (item/"project-id").first.inner_text.to_i,
94
+ (item/"item-type").first.inner_text,
95
+ (item/"description").first.inner_text,
96
+ price,
97
+ quantity,
98
+ cost)
99
+ end
100
+ Invoice.new(
101
+ (invoice/"id").first.inner_text.to_i,
102
+ (invoice/"project-id").first.inner_text.to_i,
103
+ (invoice/"description").first.inner_text,
104
+ (invoice/"reference").text,
105
+ (invoice/"net-value").text.to_f,
106
+ (invoice/"status").text,
107
+ DateTime.parse((invoice/"dated-on").text),
108
+ DateTime.parse((invoice/"due-on").text),
109
+ items)
110
+ end
111
+ @invoices
112
+ end
113
+
114
+ # This returns the specific invoice by ID
115
+ def invoice(id)
116
+ self.invoices.detect { |i| i.id == id }
117
+ end
118
+
67
119
  # This looks up the user ID using the CostAgent credentials
68
120
  def user_id
69
121
  self.client("verify").get.headers[:user_id]
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 4
9
- version: 0.1.4
8
+ - 5
9
+ version: 0.1.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Elliott Draper
@@ -14,13 +14,14 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-05 00:00:00 +01:00
17
+ date: 2010-10-10 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rest-client
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
24
25
  requirements:
25
26
  - - "="
26
27
  - !ruby/object:Gem::Version
@@ -35,6 +36,7 @@ dependencies:
35
36
  name: hpricot
36
37
  prerelease: false
37
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
38
40
  requirements:
39
41
  - - "="
40
42
  - !ruby/object:Gem::Version
@@ -49,6 +51,7 @@ dependencies:
49
51
  name: shoulda
50
52
  prerelease: false
51
53
  requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
52
55
  requirements:
53
56
  - - ">="
54
57
  - !ruby/object:Gem::Version
@@ -61,6 +64,7 @@ dependencies:
61
64
  name: mocha
62
65
  prerelease: false
63
66
  requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
64
68
  requirements:
65
69
  - - ">="
66
70
  - !ruby/object:Gem::Version
@@ -91,6 +95,7 @@ rdoc_options:
91
95
  require_paths:
92
96
  - lib
93
97
  required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
94
99
  requirements:
95
100
  - - ">="
96
101
  - !ruby/object:Gem::Version
@@ -98,6 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
103
  - 0
99
104
  version: "0"
100
105
  required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
101
107
  requirements:
102
108
  - - ">="
103
109
  - !ruby/object:Gem::Version
@@ -107,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
113
  requirements: []
108
114
 
109
115
  rubyforge_project:
110
- rubygems_version: 1.3.6
116
+ rubygems_version: 1.3.7
111
117
  signing_key:
112
118
  specification_version: 3
113
119
  summary: costagent is a Ruby gem that provides lightweight access to the projects/timeslips part of the FreeAgent API, with a view to tracking billable hours and figures.