invoicexpress 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/CHANGELOG.md +0 -0
  2. data/README.md +322 -0
  3. data/Rakefile +19 -0
  4. data/invoicexpress.gemspec +26 -0
  5. data/lib/faraday/response/parse_xml.rb +23 -0
  6. data/lib/faraday/response/raise_invoicexpress_errors.rb +20 -0
  7. data/lib/invoicexpress.rb +26 -0
  8. data/lib/invoicexpress/authentication.rb +15 -0
  9. data/lib/invoicexpress/client.rb +56 -0
  10. data/lib/invoicexpress/client/cash_invoices.rb +110 -0
  11. data/lib/invoicexpress/client/charts.rb +57 -0
  12. data/lib/invoicexpress/client/clients.rb +215 -0
  13. data/lib/invoicexpress/client/credit_notes.rb +128 -0
  14. data/lib/invoicexpress/client/debit_notes.rb +129 -0
  15. data/lib/invoicexpress/client/invoices.rb +107 -0
  16. data/lib/invoicexpress/client/items.rb +82 -0
  17. data/lib/invoicexpress/client/purchase_orders.rb +126 -0
  18. data/lib/invoicexpress/client/schedules.rb +110 -0
  19. data/lib/invoicexpress/client/sequences.rb +71 -0
  20. data/lib/invoicexpress/client/simplified_invoices.rb +130 -0
  21. data/lib/invoicexpress/client/taxes.rb +82 -0
  22. data/lib/invoicexpress/client/users.rb +48 -0
  23. data/lib/invoicexpress/configuration.rb +51 -0
  24. data/lib/invoicexpress/connection.rb +40 -0
  25. data/lib/invoicexpress/error.rb +68 -0
  26. data/lib/invoicexpress/models.rb +29 -0
  27. data/lib/invoicexpress/models/chart.rb +41 -0
  28. data/lib/invoicexpress/models/client.rb +24 -0
  29. data/lib/invoicexpress/models/filter.rb +60 -0
  30. data/lib/invoicexpress/models/invoice.rb +235 -0
  31. data/lib/invoicexpress/models/purchase_order.rb +72 -0
  32. data/lib/invoicexpress/models/quarterly_result.rb +45 -0
  33. data/lib/invoicexpress/models/schedule.rb +87 -0
  34. data/lib/invoicexpress/models/sequence.rb +17 -0
  35. data/lib/invoicexpress/models/supplier.rb +17 -0
  36. data/lib/invoicexpress/models/top_client.rb +15 -0
  37. data/lib/invoicexpress/models/top_debtor.rb +14 -0
  38. data/lib/invoicexpress/models/user.rb +31 -0
  39. data/lib/invoicexpress/request.rb +63 -0
  40. data/lib/invoicexpress/version.rb +3 -0
  41. data/spec/fixtures/charts.invoicing.xml +21 -0
  42. data/spec/fixtures/charts.quarterly-results.xml +25 -0
  43. data/spec/fixtures/charts.top-clients.xml +10 -0
  44. data/spec/fixtures/charts.top-debtors.xml +10 -0
  45. data/spec/fixtures/charts.treasury.xml +49 -0
  46. data/spec/fixtures/clients.create.xml +6 -0
  47. data/spec/fixtures/clients.get.xml +21 -0
  48. data/spec/fixtures/clients.invoices.xml +11 -0
  49. data/spec/fixtures/clients.list.xml +18 -0
  50. data/spec/fixtures/clients.update.xml +1 -0
  51. data/spec/fixtures/credit_notes.create.xml +53 -0
  52. data/spec/fixtures/credit_notes.email_document.xml +9 -0
  53. data/spec/fixtures/credit_notes.list.xml +114 -0
  54. data/spec/fixtures/credit_notes.update_state.xml +7 -0
  55. data/spec/fixtures/invoices.create.xml +37 -0
  56. data/spec/fixtures/invoices.get.xml +50 -0
  57. data/spec/fixtures/invoices.list.xml +537 -0
  58. data/spec/fixtures/invoices.update_state.xml +7 -0
  59. data/spec/fixtures/ok.xml +0 -0
  60. data/spec/fixtures/po.create.xml +42 -0
  61. data/spec/fixtures/po.email_document.xml +0 -0
  62. data/spec/fixtures/po.get.xml +42 -0
  63. data/spec/fixtures/po.list.xml +44 -0
  64. data/spec/fixtures/po.update_state.xml +7 -0
  65. data/spec/fixtures/schedules.create.xml +48 -0
  66. data/spec/fixtures/schedules.get.xml +57 -0
  67. data/spec/fixtures/schedules.list.xml +40 -0
  68. data/spec/fixtures/sequences.create.xml +9 -0
  69. data/spec/fixtures/sequences.get.xml +10 -0
  70. data/spec/fixtures/sequences.list.xml +12 -0
  71. data/spec/fixtures/sequences.update.xml +10 -0
  72. data/spec/fixtures/simplified_invoices.create.xml +53 -0
  73. data/spec/fixtures/simplified_invoices.email_document.xml +9 -0
  74. data/spec/fixtures/simplified_invoices.get.xml +74 -0
  75. data/spec/fixtures/simplified_invoices.list.xml +114 -0
  76. data/spec/fixtures/simplified_invoices.update.xml +0 -0
  77. data/spec/fixtures/simplified_invoices.update_state.xml +7 -0
  78. data/spec/fixtures/taxes.create.xml +7 -0
  79. data/spec/fixtures/taxes.list.xml +18 -0
  80. data/spec/fixtures/taxes.update.xml +7 -0
  81. data/spec/fixtures/users.accounts.xml +12 -0
  82. data/spec/fixtures/users.change-account.xml +0 -0
  83. data/spec/fixtures/users.login.xml +11 -0
  84. data/spec/helper.rb +62 -0
  85. data/spec/invoicexpress/client/charts_spec.rb +69 -0
  86. data/spec/invoicexpress/client/clients_spec.rb +108 -0
  87. data/spec/invoicexpress/client/credit_notes_spec.rb +104 -0
  88. data/spec/invoicexpress/client/invoices_spec.rb +110 -0
  89. data/spec/invoicexpress/client/purchase_orders_spec.rb +116 -0
  90. data/spec/invoicexpress/client/schedules_spec.rb +111 -0
  91. data/spec/invoicexpress/client/sequences_spec.rb +68 -0
  92. data/spec/invoicexpress/client/simplified_invoices_spec.rb +116 -0
  93. data/spec/invoicexpress/client/taxes_spec.rb +70 -0
  94. data/spec/invoicexpress/client/users_spec.rb +40 -0
  95. data/spec/invoicexpress/client_spec.rb +24 -0
  96. data/spec/invoicexpress_spec.rb +19 -0
  97. metadata +279 -0
@@ -0,0 +1,45 @@
1
+ module Invoicexpress
2
+ module Models
3
+
4
+ #TODO Improve this in the future, maybe inherit
5
+ class Quarter01 < BaseModel
6
+ include HappyMapper
7
+ tag 'quarter-01'
8
+ element :invoicing, Float
9
+ element :taxes, Float
10
+ element :ytd, Float
11
+ end
12
+ class Quarter02 < BaseModel
13
+ include HappyMapper
14
+ tag 'quarter-02'
15
+ element :invoicing, Float
16
+ element :taxes, Float
17
+ element :ytd, Float
18
+ end
19
+ class Quarter03 < BaseModel
20
+ include HappyMapper
21
+ tag 'quarter-03'
22
+ element :invoicing, Float
23
+ element :taxes, Float
24
+ element :ytd, Float
25
+ end
26
+ class Quarter04 < BaseModel
27
+ include HappyMapper
28
+ tag 'quarter-04'
29
+ element :invoicing, Float
30
+ element :taxes, Float
31
+ element :ytd, Float
32
+ end
33
+
34
+ class QuarterlyResult < BaseModel
35
+ include HappyMapper
36
+ tag 'quarterly-results'
37
+ element :year, Integer
38
+ element :currency, String
39
+ has_one :quarter01, Quarter01
40
+ has_one :quarter02, Quarter02
41
+ has_one :quarter03, Quarter03
42
+ has_one :quarter04, Quarter04
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,87 @@
1
+ require 'invoicexpress/models/client'
2
+ require 'invoicexpress/models/invoice'
3
+
4
+ module Invoicexpress
5
+ module Models
6
+
7
+ class InvoiceTemplate < BaseModel
8
+ include BaseInvoice
9
+ tag 'invoice_template'
10
+ element :due_days, Integer
11
+ end
12
+
13
+ class SentInvoices < BaseModel
14
+ include HappyMapper
15
+ tag 'sent_invoices'
16
+ has_many :invoices, Invoice
17
+ end
18
+
19
+ module BaseSchedule
20
+ def self.included(base)
21
+ base.class_eval do
22
+ include HappyMapper
23
+ tag 'schedule'
24
+
25
+ element :id, Integer
26
+ #these fields are only used on create and update...
27
+ element :start_date, Date, :on_save => DATE_FORMAT
28
+ element :end_date, Date, :on_save => DATE_FORMAT
29
+ element :create_back, String
30
+ element :schedule_type, String
31
+ element :interval, String
32
+ element :send_to_client, String
33
+ element :description, String
34
+
35
+ # has_many :sent_invoices, Invoice
36
+ has_one :invoice_template, InvoiceTemplate
37
+
38
+ end
39
+ end
40
+ end
41
+
42
+ class CoreSchedule < BaseModel
43
+ include BaseSchedule
44
+ end
45
+
46
+ class Schedule < CoreSchedule
47
+ include BaseSchedule
48
+
49
+ element :reference, String
50
+ element :retention, Float
51
+ element :currency, String
52
+ #observation instead of description?
53
+ element :observations, String
54
+ #items and client instead of invoice template?
55
+ has_many :items, Item
56
+ has_one :client, Client
57
+ element :sum, Float
58
+ element :discount, Float
59
+ element :before_taxes, Float
60
+ element :taxes, Float
61
+ element :total, Float
62
+ has_one :sent_invoices, SentInvoices
63
+
64
+ #creates a object that can be used in create/update by the invoicexpress API
65
+ def to_core_schedule()
66
+ Invoicexpress::Models::CoreSchedule.new(
67
+ :id=>self.id,
68
+ :start_date=>self.start_date,
69
+ :end_date=>self.end_date,
70
+ :create_back=>self.create_back,
71
+ :schedule_type=>self.schedule_type,
72
+ :interval=>self.interval,
73
+ :send_to_client=>self.send_to_client,
74
+ :description=>self.description,
75
+ :invoice_template=>self.invoice_template
76
+ )
77
+ end
78
+ end
79
+
80
+ class Schedules < BaseModel
81
+ include HappyMapper
82
+ tag 'schedules'
83
+ has_many :schedules, Schedule
84
+ end
85
+ end
86
+ end
87
+
@@ -0,0 +1,17 @@
1
+ module Invoicexpress
2
+ module Models
3
+
4
+ class Sequence < BaseModel
5
+ include HappyMapper
6
+
7
+ tag 'sequence'
8
+ element :id, String
9
+ element :serie, String
10
+ element :current_invoice_number, Integer
11
+ element :current_credit_note_number, Integer
12
+ element :current_debit_note_number, Integer
13
+ element :default_sequence, Boolean
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Invoicexpress
2
+ module Models
3
+
4
+ class Supplier < BaseModel
5
+ include HappyMapper
6
+ tag 'supplier'
7
+ element :id, String
8
+ element :name, String
9
+ element :code, String
10
+ element :email, String
11
+ element :address, String
12
+ element :postal_code, String
13
+ element :fiscal_id, String
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ require 'invoicexpress/models/client'
2
+
3
+ module Invoicexpress
4
+ module Models
5
+
6
+ class TopClient < BaseModel
7
+ include HappyMapper
8
+
9
+ tag 'top-clients'
10
+ element :currency, String
11
+
12
+ has_many :clients, Client
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ require 'invoicexpress/models/client'
2
+
3
+ module Invoicexpress
4
+ module Models
5
+
6
+ class TopDebtor < BaseModel
7
+ include HappyMapper
8
+
9
+ tag 'top-debtors'
10
+ element :currency, String
11
+ has_many :clients, Client
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,31 @@
1
+ module Invoicexpress
2
+ module Models
3
+
4
+ class Credentials < BaseModel
5
+ include HappyMapper
6
+
7
+ tag 'credentials'
8
+ element :login, String
9
+ element :password, String
10
+ end
11
+
12
+ class Account < BaseModel
13
+ include HappyMapper
14
+
15
+ tag 'account'
16
+ element :id, String
17
+ element :name, String
18
+ element :url, String
19
+ element :api_key, String
20
+ element :state, String
21
+ end
22
+
23
+ class ChangeAccountTo < BaseModel
24
+ include HappyMapper
25
+
26
+ tag 'change_account_to'
27
+ element :id, String
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,63 @@
1
+ module Invoicexpress
2
+ module Request
3
+
4
+ def delete(path, options={})
5
+ request(:delete, path, options).body
6
+ end
7
+
8
+ def get(path, options={})
9
+ repsonse = request(:get, path, options).body
10
+ end
11
+
12
+ def patch(path, options={})
13
+ request(:patch, path, options).body
14
+ end
15
+
16
+ def post(path, options={})
17
+ request(:post, path, options).body
18
+ end
19
+
20
+ def put(path, options={})
21
+ request(:put, path, options).body
22
+ end
23
+
24
+ private
25
+
26
+ # Executes the request, checking if ti was successful
27
+ #
28
+ # @return [Boolean] True on success, false otherwise
29
+ def boolean_from_response(method, path, options={})
30
+ request(method, path, options).status == 204
31
+ rescue Invoicexpress::NotFound
32
+ false
33
+ end
34
+
35
+ def request(method, path, options={})
36
+ token = options.delete(:api_key) || api_key
37
+ url = options.delete(:endpoint) || (api_endpoint % screen_name)
38
+ klass = options.delete(:klass) || raise(ArgumentError, "Need a HappyMapper class to parse")
39
+
40
+ conn_options = {
41
+ :url => url,
42
+ :klass => klass
43
+ }
44
+
45
+ response = connection(conn_options).send(method) do |request|
46
+ request.headers['Accept'] = options.delete(:accept) || 'application/xml'
47
+
48
+ case method
49
+ when :get, :delete, :head
50
+ request.url(path, options)
51
+ when :patch, :post, :put
52
+ request.headers['Content-Type'] = "application/xml; charset=utf-8"
53
+
54
+ request.path = path
55
+ request.body = options[:body].to_xml unless options.empty?
56
+ end
57
+ end
58
+
59
+ response
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,3 @@
1
+ module Invoicexpress
2
+ VERSION = "0.0.0" unless defined?(Invoicexpress::VERSION)
3
+ end
@@ -0,0 +1,21 @@
1
+ <?xml version='1.0' encoding='UTF-8'?>
2
+ <chart>
3
+ <series>
4
+ <value xid="0">Sep</value>
5
+ <value xid="1">Oct</value>
6
+ <value xid="2">Nov</value>
7
+ <value xid="3">Dec</value>
8
+ <value xid="4">Jan</value>
9
+ <value xid="5">Feb</value>
10
+ </series>
11
+ <graphs>
12
+ <graph gid="invoicing">
13
+ <value xid="0">0</value>
14
+ <value xid="1">0</value>
15
+ <value xid="2">0</value>
16
+ <value xid="3">0</value>
17
+ <value xid="4">0</value>
18
+ <value xid="5">60</value>
19
+ </graph>
20
+ </graphs>
21
+ </chart>
@@ -0,0 +1,25 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <quarterly-results>
3
+ <year>2010</year>
4
+ <currency>&#8364;</currency>
5
+ <quarter-01>
6
+ <invoicing>60.0</invoicing>
7
+ <taxes>0.0</taxes>
8
+ <ytd></ytd>
9
+ </quarter-01>
10
+ <quarter-02>
11
+ <invoicing>0</invoicing>
12
+ <taxes>0</taxes>
13
+ <ytd></ytd>
14
+ </quarter-02>
15
+ <quarter-03>
16
+ <invoicing>0</invoicing>
17
+ <taxes>0</taxes>
18
+ <ytd></ytd>
19
+ </quarter-03>
20
+ <quarter-04>
21
+ <invoicing>0</invoicing>
22
+ <taxes>0</taxes>
23
+ <ytd></ytd>
24
+ </quarter-04>
25
+ </quarterly-results>
@@ -0,0 +1,10 @@
1
+ <?xml version='1.0' encoding='UTF-8'?>
2
+ <top-clients>
3
+ <currency>€</currency>
4
+ <client>
5
+ <id>393116</id>
6
+ <name>Ruben Fonseca</name>
7
+ <balance>60.0</balance>
8
+ <fiscal_id/>
9
+ </client>
10
+ </top-clients>
@@ -0,0 +1,10 @@
1
+ <?xml version='1.0' encoding='UTF-8'?>
2
+ <top-debtors>
3
+ <currency>€</currency>
4
+ <client>
5
+ <id>393116</id>
6
+ <name>Ruben Fonseca</name>
7
+ <balance>60.0</balance>
8
+ <fiscal_id/>
9
+ </client>
10
+ </top-debtors>
@@ -0,0 +1,49 @@
1
+ <chart>
2
+ <series>
3
+ <value xid="0">Jan</value>
4
+ <value xid="1">Fev</value>
5
+ <value xid="2">Mar</value>
6
+ <value xid="3">Abr</value>
7
+ <value xid="4">Mai</value>
8
+ <value xid="5">Jun</value>
9
+ <value xid="6">Jul</value>
10
+ </series>
11
+ <graphs>
12
+ <graph title="Recebido" gid="settled_values">
13
+ <value xid="0">0</value>
14
+ <value xid="1">0</value>
15
+ <value xid="2">0</value>
16
+ <value xid="3">0</value>
17
+ <value xid="4">0</value>
18
+ <value xid="5">0</value>
19
+ <value xid="6">0</value>
20
+ </graph>
21
+ <graph title="Dentro Prazo" gid="due_values">
22
+ <value xid="0">0</value>
23
+ <value xid="1">0</value>
24
+ <value xid="2">0</value>
25
+ <value xid="3">0</value>
26
+ <value xid="4">0</value>
27
+ <value xid="5">0</value>
28
+ <value xid="6">0</value>
29
+ </graph>
30
+ <graph title="Vencido" gid="overdue_values">
31
+ <value xid="0">0</value>
32
+ <value xid="1">60</value>
33
+ <value xid="2">0</value>
34
+ <value xid="3">0</value>
35
+ <value xid="4">0</value>
36
+ <value xid="5">0</value>
37
+ <value xid="6">0</value>
38
+ </graph>
39
+ <graph title="Previs&#227;o" gid="forecast_values">
40
+ <value xid="0">0</value>
41
+ <value xid="1">60</value>
42
+ <value xid="2">0</value>
43
+ <value xid="3">0</value>
44
+ <value xid="4">0</value>
45
+ <value xid="5">0</value>
46
+ <value xid="6">0</value>
47
+ </graph>
48
+ </graphs>
49
+ </chart>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <client>
3
+ <id>1</id>
4
+ <name>Ruben Fonseca</name>
5
+ <email>fonseka@gmail.com</email>
6
+ </client>
@@ -0,0 +1,21 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <client>
3
+ <id>345</id>
4
+ <name>Bruce Norris</name>
5
+ <code>1337</code>
6
+ <email>foo@bar.com</email>
7
+ <address>Badgad</address>
8
+ <postal_code>123-456</postal_code>
9
+ <fiscal_id>1122331122</fiscal_id>
10
+ <website>www.brucenorris.com</website>
11
+ <phone>4433551242</phone>
12
+ <fax>4433551243</fax>
13
+ <preferred_contact>
14
+ <name>Rui Alves</name>
15
+ <email>xpto@xpto.pt</email>
16
+ <phone>4433551242</phone>
17
+ </preferred_contact>
18
+ <observations>Computer Processed</observations>
19
+ <send_options>1</send_options>
20
+ <!-- 1 - Original -->
21
+ </client>