fakturoid 0.5.0 → 1.1.0

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.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -10
  3. data/.ruby-version +1 -1
  4. data/CHANGELOG.md +15 -0
  5. data/README.md +540 -145
  6. data/Rakefile +3 -1
  7. data/fakturoid.gemspec +36 -25
  8. data/lib/fakturoid/api/account.rb +13 -0
  9. data/lib/fakturoid/api/bank_account.rb +13 -0
  10. data/lib/fakturoid/api/base.rb +18 -0
  11. data/lib/fakturoid/api/event.rb +23 -0
  12. data/lib/fakturoid/api/expense.rb +55 -0
  13. data/lib/fakturoid/api/expense_payment.rb +20 -0
  14. data/lib/fakturoid/api/generator.rb +36 -0
  15. data/lib/fakturoid/api/inbox_file.rb +34 -0
  16. data/lib/fakturoid/api/inventory_item.rb +66 -0
  17. data/lib/fakturoid/api/inventory_move.rb +40 -0
  18. data/lib/fakturoid/api/invoice.rb +62 -0
  19. data/lib/fakturoid/api/invoice_message.rb +14 -0
  20. data/lib/fakturoid/api/invoice_payment.rb +26 -0
  21. data/lib/fakturoid/api/number_format.rb +13 -0
  22. data/lib/fakturoid/api/recurring_generator.rb +36 -0
  23. data/lib/fakturoid/api/subject.rb +42 -0
  24. data/lib/fakturoid/api/todo.rb +20 -0
  25. data/lib/fakturoid/api/user.rb +17 -0
  26. data/lib/fakturoid/api/webhook.rb +34 -0
  27. data/lib/fakturoid/api.rb +89 -9
  28. data/lib/fakturoid/client.rb +46 -12
  29. data/lib/fakturoid/config.rb +69 -12
  30. data/lib/fakturoid/oauth/access_token_service.rb +46 -0
  31. data/lib/fakturoid/oauth/credentials.rb +63 -0
  32. data/lib/fakturoid/oauth/flow/authorization_code.rb +53 -0
  33. data/lib/fakturoid/oauth/flow/base.rb +42 -0
  34. data/lib/fakturoid/oauth/flow/client_credentials.rb +27 -0
  35. data/lib/fakturoid/oauth/flow.rb +5 -0
  36. data/lib/fakturoid/oauth/request/api.rb +11 -0
  37. data/lib/fakturoid/oauth/request/base.rb +60 -0
  38. data/lib/fakturoid/oauth/request/oauth.rb +24 -0
  39. data/lib/fakturoid/oauth/request.rb +5 -0
  40. data/lib/fakturoid/oauth/token_response.rb +56 -0
  41. data/lib/fakturoid/oauth.rb +39 -0
  42. data/lib/fakturoid/response.rb +8 -20
  43. data/lib/fakturoid/utils.rb +27 -0
  44. data/lib/fakturoid/version.rb +1 -1
  45. data/lib/fakturoid.rb +22 -22
  46. metadata +48 -53
  47. data/.github/workflows/rubocop.yml +0 -20
  48. data/.github/workflows/tests.yml +0 -27
  49. data/.gitignore +0 -7
  50. data/Gemfile +0 -6
  51. data/lib/fakturoid/api/arguments.rb +0 -21
  52. data/lib/fakturoid/api/http_methods.rb +0 -23
  53. data/lib/fakturoid/client/account.rb +0 -11
  54. data/lib/fakturoid/client/bank_account.rb +0 -11
  55. data/lib/fakturoid/client/event.rb +0 -19
  56. data/lib/fakturoid/client/expense.rb +0 -49
  57. data/lib/fakturoid/client/generator.rb +0 -44
  58. data/lib/fakturoid/client/inventory_items.rb +0 -59
  59. data/lib/fakturoid/client/inventory_moves.rb +0 -36
  60. data/lib/fakturoid/client/invoice.rb +0 -73
  61. data/lib/fakturoid/client/number_format.rb +0 -11
  62. data/lib/fakturoid/client/subject.rb +0 -41
  63. data/lib/fakturoid/client/todo.rb +0 -18
  64. data/lib/fakturoid/client/user.rb +0 -20
  65. data/lib/fakturoid/connection.rb +0 -30
  66. data/lib/fakturoid/request.rb +0 -31
  67. data/test/api_test.rb +0 -24
  68. data/test/config_test.rb +0 -40
  69. data/test/fixtures/blocked_account.json +0 -8
  70. data/test/fixtures/invoice.json +0 -81
  71. data/test/fixtures/invoice.pdf +0 -0
  72. data/test/fixtures/invoice_error.json +0 -7
  73. data/test/fixtures/subjects.json +0 -52
  74. data/test/request_test.rb +0 -20
  75. data/test/response_test.rb +0 -189
  76. data/test/test_helper.rb +0 -19
@@ -1,189 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- class Fakturoid::ResponseTest < Fakturoid::TestCase
6
- should "should return json invoice" do
7
- json = load_fixture("invoice.json")
8
- test_connection = Faraday.new do |builder|
9
- builder.adapter :test do |stub|
10
- stub.get("invoices/5.json") { |_env| [200, { content_type: "application/json" }, json] }
11
- end
12
- builder.headers = { content_type: "application/json", user_agent: "Fakturoid gem (email@testmail.cz)" }
13
- end
14
-
15
- response = Fakturoid::Response.new(test_connection.get("invoices/5.json"), Fakturoid::Client::Invoice, :get)
16
- assert response.json?
17
- assert_equal 200, response.status_code
18
- assert_equal 5, response.id
19
- assert_equal 5, response.body["id"]
20
- assert response.respond_to?(:body)
21
- assert response.respond_to?(:id)
22
- assert_raises(NoMethodError) { response.name }
23
- end
24
-
25
- context "Exceptions" do
26
- should "raise user agent error" do
27
- test_connection = Faraday.new do |builder|
28
- builder.adapter :test do |stub|
29
- stub.get("invoices/5.json") { |_env| [400, { content_type: "application/json" }, " "] }
30
- end
31
- builder.headers = { content_type: "application/json", user_agent: "" }
32
- end
33
-
34
- assert_raises(Fakturoid::UserAgentError) { Fakturoid::Response.new(test_connection.get("invoices/5.json"), Fakturoid::Client::Invoice, :get) }
35
- end
36
-
37
- should "raise pagination error" do
38
- test_connection = Faraday.new do |builder|
39
- builder.adapter :test do |stub|
40
- stub.get("invoices.json?page=4") { |_env| [400, { content_type: "application/json" }, " "] }
41
- end
42
- builder.headers = { content_type: "application/json", user_agent: "Fakturoid gem (email@testmail.cz)" }
43
- end
44
-
45
- assert_raises(Fakturoid::PaginationError) { Fakturoid::Response.new(test_connection.get("invoices.json?page=4"), Fakturoid::Client::Invoice, :get) }
46
- end
47
-
48
- should "raise authentication error" do
49
- test_connection = Faraday.new do |builder|
50
- builder.adapter :test do |stub|
51
- stub.get("invoices.json?page=4") { |_env| [401, { content_type: "application/json" }, " "] }
52
- end
53
- builder.headers = { content_type: "application/json", user_agent: "Fakturoid gem (email@testmail.cz)" }
54
- end
55
-
56
- assert_raises(Fakturoid::AuthenticationError) { Fakturoid::Response.new(test_connection.get("invoices.json?page=4"), Fakturoid::Client::Invoice, :get) }
57
- end
58
-
59
- should "raise blocked account error" do
60
- json = load_fixture("blocked_account.json")
61
- test_connection = Faraday.new do |builder|
62
- builder.adapter :test do |stub|
63
- stub.get("account.json") { |_env| [402, { content_type: "application/json" }, json] }
64
- end
65
- builder.headers = { content_type: "application/json", user_agent: "Fakturoid gem (email@testmail.cz)" }
66
- end
67
-
68
- begin
69
- Fakturoid::Response.new(test_connection.get("account.json"), Fakturoid::Client::Account, :get)
70
- rescue Fakturoid::BlockedAccountError => e
71
- assert_equal 402, e.response_code
72
- assert e.response_body.key?("status")
73
- rescue => e
74
- assert false, "Raised exception was not expected: #{e.class}"
75
- else
76
- assert false, "Exception was expected"
77
- end
78
- end
79
-
80
- should "raise destroy subject error" do
81
- test_connection = Faraday.new do |builder|
82
- builder.adapter :test do |stub|
83
- stub.delete("subjects/5.json") { |_env| [403, { content_type: "application/json" }, " "] }
84
- end
85
- builder.headers = { content_type: "application/json", user_agent: "Fakturoid gem (email@testmail.cz)" }
86
- end
87
-
88
- assert_raises(Fakturoid::DestroySubjectError) { Fakturoid::Response.new(test_connection.delete("subjects/5.json"), Fakturoid::Client::Subject, :delete) }
89
- end
90
-
91
- should "raise subject limit error" do
92
- test_connection = Faraday.new do |builder|
93
- builder.adapter :test do |stub|
94
- stub.post("subjects.json") { |_env| [403, { content_type: "application/json" }, " "] }
95
- end
96
- builder.headers = { content_type: "application/json", user_agent: "Fakturoid gem (email@testmail.cz)" }
97
- end
98
-
99
- assert_raises(Fakturoid::SubjectLimitError) { Fakturoid::Response.new(test_connection.post("subjects.json", name: "Customer s.r.o."), Fakturoid::Client::Subject, :post) }
100
- end
101
-
102
- should "raise generator limit error" do
103
- test_connection = Faraday.new do |builder|
104
- builder.adapter :test do |stub|
105
- stub.post("generators.json") { |_env| [403, { content_type: "application/json" }, " "] }
106
- end
107
- builder.headers = { content_type: "application/json", user_agent: "Fakturoid gem (email@testmail.cz)" }
108
- end
109
-
110
- assert_raises(Fakturoid::GeneratorLimitError) { Fakturoid::Response.new(test_connection.post("generators.json", name: "Customer s.r.o.", recurring: true), Fakturoid::Client::Generator, :post) }
111
- end
112
-
113
- should "raise unsupported feature error" do
114
- test_connection = Faraday.new do |builder|
115
- builder.adapter :test do |stub|
116
- stub.post("invoices/5/message.json") { |_env| [403, { content_type: "application/json" }, " "] }
117
- end
118
- builder.headers = { content_type: "application/json", user_agent: "Fakturoid gem (email@testmail.cz)" }
119
- end
120
-
121
- assert_raises(Fakturoid::UnsupportedFeatureError) { Fakturoid::Response.new(test_connection.post("invoices/5/message.json", email: "customer@email.cz"), Fakturoid::Client::Invoice, :post) }
122
- end
123
-
124
- should "raise record not found error" do
125
- test_connection = Faraday.new do |builder|
126
- builder.adapter :test do |stub|
127
- stub.get("invoices/10.json") { |_env| [404, { content_type: "application/json" }, " "] }
128
- end
129
- builder.headers = { content_type: "application/json", user_agent: "Fakturoid gem (email@testmail.cz)" }
130
- end
131
-
132
- assert_raises(Fakturoid::RecordNotFoundError) { Fakturoid::Response.new(test_connection.get("invoices/10.json"), Fakturoid::Client::Invoice, :get) }
133
- end
134
-
135
- should "raise content type error" do
136
- test_connection = Faraday.new do |builder|
137
- builder.adapter :test do |stub|
138
- stub.get("invoices/5.xml") { |_env| [415, { content_type: "application/xml" }, " "] }
139
- end
140
- builder.headers = { content_type: "application/xml", user_agent: "Fakturoid gem (email@testmail.cz)" }
141
- end
142
-
143
- assert_raises(Fakturoid::ContentTypeError) { Fakturoid::Response.new(test_connection.get("invoices/5.xml"), Fakturoid::Client::Invoice, :get) }
144
- end
145
-
146
- should "raise invalid record error" do
147
- json = load_fixture("invoice_error.json")
148
- test_connection = Faraday.new do |builder|
149
- builder.adapter :test do |stub|
150
- stub.patch("invoice/5.json") { |_env| [422, { content_type: "application/json" }, json] }
151
- end
152
- builder.headers = { content_type: "application/json", user_agent: "Fakturoid gem (email@testmail.cz)" }
153
- end
154
-
155
- begin
156
- Fakturoid::Response.new(test_connection.patch("invoice/5.json"), Fakturoid::Client::Invoice, :patch)
157
- rescue Fakturoid::InvalidRecordError => e
158
- assert_equal 422, e.response_code
159
- assert e.response_body.key?("errors")
160
- rescue => e
161
- assert false, "Raised exception was not expected: #{e.class}"
162
- else
163
- assert false, "Exception was expected"
164
- end
165
- end
166
-
167
- should "raise rate limit error" do
168
- test_connection = Faraday.new do |builder|
169
- builder.adapter :test do |stub|
170
- stub.get("invoices/5.json") { |_env| [429, { content_type: "application/json" }, " "] }
171
- end
172
- builder.headers = { content_type: "application/json", user_agent: "Fakturoid gem (email@testmail.cz)" }
173
- end
174
-
175
- assert_raises(Fakturoid::RateLimitError) { Fakturoid::Response.new(test_connection.get("invoices/5.json"), Fakturoid::Client::Invoice, :get) }
176
- end
177
-
178
- should "raise read only site error" do
179
- test_connection = Faraday.new do |builder|
180
- builder.adapter :test do |stub|
181
- stub.delete("invoices/5.json") { |_env| [503, { content_type: "application/json" }, " "] }
182
- end
183
- builder.headers = { content_type: "application/json", user_agent: "Fakturoid gem (email@testmail.cz)" }
184
- end
185
-
186
- assert_raises(Fakturoid::ReadOnlySiteError) { Fakturoid::Response.new(test_connection.delete("invoices/5.json"), Fakturoid::Client::Invoice, :delete) }
187
- end
188
- end
189
- end
data/test/test_helper.rb DELETED
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "minitest/autorun"
4
- require "mocha/minitest"
5
- require "shoulda-context"
6
- require "pathname"
7
- require "fakturoid"
8
-
9
- module Fakturoid
10
- class TestCase < Minitest::Test
11
- def test_path
12
- Pathname.new(File.dirname(__FILE__))
13
- end
14
-
15
- def load_fixture(file_name)
16
- File.read(test_path.join("fixtures", file_name))
17
- end
18
- end
19
- end