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
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fakturoid
4
+ class Oauth
5
+ class TokenResponse
6
+ attr_reader :client, :response, :body
7
+
8
+ def initialize(response)
9
+ @response = response
10
+ @body = MultiJson.load(response.env.body) unless Utils.empty?(response.env.body)
11
+
12
+ handle_response
13
+ end
14
+
15
+ def status_code
16
+ response.env["status"]
17
+ end
18
+
19
+ def refresh_token
20
+ body["refresh_token"]
21
+ end
22
+
23
+ def access_token
24
+ body["access_token"]
25
+ end
26
+
27
+ def expires_in
28
+ body["expires_in"]
29
+ end
30
+
31
+ def token_type
32
+ body["token_type"]
33
+ end
34
+
35
+ def inspect
36
+ "#<#{self.class.name}:#{object_id} @body=\"#{body}\" @status_code=\"#{status_code}\">"
37
+ end
38
+
39
+ private
40
+
41
+ def handle_response
42
+ case status_code
43
+ when 400 then raise error(OauthError, "OAuth request failed")
44
+ when 401 then raise error(AuthenticationError, "OAuth authentication failed")
45
+ else
46
+ raise error(ServerError, "Server error") if status_code >= 500
47
+ raise error(ClientError, "Client error") if status_code >= 400
48
+ end
49
+ end
50
+
51
+ def error(klass, message = nil)
52
+ klass.new message, status_code, body
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "oauth/credentials"
4
+ require_relative "oauth/flow"
5
+ require_relative "oauth/request"
6
+ require_relative "oauth/token_response"
7
+ require_relative "oauth/access_token_service"
8
+
9
+ module Fakturoid
10
+ class Oauth
11
+ extend Forwardable
12
+
13
+ attr_reader :client, :flow, :access_token_service
14
+
15
+ def_delegators :@flow, :authorization_uri, :authorize, :fetch_access_token, :revoke_access, :authorized?
16
+
17
+ def initialize(client)
18
+ @client = client
19
+ @flow = find_flow
20
+ @access_token_service = AccessTokenService.new(self)
21
+ end
22
+
23
+ def perform_request(method, path, params)
24
+ access_token_service.perform_request(method, path, params)
25
+ end
26
+
27
+ private
28
+
29
+ def find_flow
30
+ if client.config.client_credentials_flow?
31
+ Flow::ClientCredentials.new(client)
32
+ elsif client.config.authorization_code_flow?
33
+ Flow::AuthorizationCode.new(client)
34
+ else
35
+ raise ConfigurationError, "Unsupported OAuth flow."
36
+ end
37
+ end
38
+ end
39
+ end
@@ -2,30 +2,32 @@
2
2
 
3
3
  module Fakturoid
4
4
  class Response
5
- attr_reader :response, :caller, :env, :body, :request_method
5
+ attr_reader :response, :caller, :body, :request_method
6
6
 
7
7
  def initialize(faraday_response, caller, request_method)
8
8
  @response = faraday_response
9
9
  @caller = caller
10
- @env = faraday_response.env
11
10
  @request_method = request_method.to_sym
12
11
 
12
+ env = response.env
13
+
13
14
  if !(env.body.nil? || env.body.empty? || (json? && env.body =~ /\A\s+\z/))
14
15
  @body = json? ? MultiJson.load(env.body) : env.body
15
16
  end
17
+
16
18
  handle_response
17
19
  end
18
20
 
19
21
  def status_code
20
- env["status"]
22
+ response.env["status"]
21
23
  end
22
24
 
23
25
  def json?
24
- env.request_headers["Content-Type"] == "application/json"
26
+ headers["content-type"] =~ %r{\Aapplication/json}
25
27
  end
26
28
 
27
29
  def headers
28
- env.response_headers
30
+ response.env.response_headers.transform_keys(&:downcase)
29
31
  end
30
32
 
31
33
  def inspect
@@ -36,21 +38,7 @@ module Fakturoid
36
38
 
37
39
  def handle_response
38
40
  case status_code
39
- when 400
40
- raise error(UserAgentError, "User-Agent header missing") if env.request_headers["User-Agent"].nil? || env.request_headers["User-Agent"].empty?
41
- raise error(PaginationError, "Page does not exist")
42
- when 401 then raise error(AuthenticationError, "Authentification failed")
43
- when 402 then raise error(BlockedAccountError, "Account is blocked")
44
- when 403
45
- raise error(DestroySubjectError, "Cannot destroy subject with invoices") if caller == Client::Subject && request_method == :delete
46
- raise error(SubjectLimitError, "Subject limit for account reached") if caller == Client::Subject && request_method == :post
47
- raise error(GeneratorLimitError, "Recurring generator limit for account reached") if caller == Client::Generator
48
- raise error(UnsupportedFeatureError, "Feature unavailable for account plan")
49
- when 404 then raise error(RecordNotFoundError, "Record not found")
50
- when 415 then raise error(ContentTypeError, "Unsupported Content-Type")
51
- when 422 then raise error(InvalidRecordError, "Invalid record")
52
- when 429 then raise error(RateLimitError, "Rate limit reached")
53
- when 503 then raise error(ReadOnlySiteError, "Fakturoid is in read only state")
41
+ when 401 then raise error(AuthenticationError, "Authentication failed")
54
42
  else
55
43
  raise error(ServerError, "Server error") if status_code >= 500
56
44
  raise error(ClientError, "Client error") if status_code >= 400
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fakturoid
4
+ module Utils
5
+ def self.permit_params(params_hash, *permitted_params)
6
+ params_hash.select { |param, _value| permitted_params.include?(param.to_sym) }
7
+ end
8
+
9
+ def self.validate_numerical_id(id)
10
+ raise ArgumentError, "Wrong ID given: #{id}" if !id.is_a?(Integer) && !(id.is_a?(String) && id =~ /\A\d+\z/)
11
+ true
12
+ end
13
+
14
+ def self.validate_search_query(query: nil, tags: nil, allow_tags: false)
15
+ if allow_tags && empty?(tags) && empty?(query)
16
+ raise ArgumentError, "Query or tags parameter is required"
17
+ elsif !allow_tags && empty?(query)
18
+ raise ArgumentError, "Query parameter is required"
19
+ end
20
+ true
21
+ end
22
+
23
+ def self.empty?(string)
24
+ string.nil? || string.empty?
25
+ end
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Fakturoid
4
- VERSION = "0.5.0"
4
+ VERSION = "1.1.0"
5
5
  end
data/lib/fakturoid.rb CHANGED
@@ -1,17 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "uri"
4
+ require "forwardable"
5
+ require "time"
4
6
  require "multi_json"
5
7
  require "faraday"
6
8
 
7
- require "fakturoid/config"
8
- require "fakturoid/connection"
9
- require "fakturoid/request"
10
- require "fakturoid/response"
11
- require "fakturoid/api"
12
- require "fakturoid/client"
13
- require "fakturoid/version"
14
- require "fakturoid/railtie" if defined?(::Rails)
9
+ require_relative "fakturoid/utils"
10
+ require_relative "fakturoid/config"
11
+ require_relative "fakturoid/response"
12
+ require_relative "fakturoid/api"
13
+ require_relative "fakturoid/oauth"
14
+ require_relative "fakturoid/client"
15
+ require_relative "fakturoid/version"
16
+ require_relative "fakturoid/railtie" if defined?(::Rails)
15
17
 
16
18
  module Fakturoid
17
19
  class ApiError < StandardError
@@ -24,25 +26,23 @@ module Fakturoid
24
26
  end
25
27
  end
26
28
 
27
- class ContentTypeError < ApiError; end
28
- class UserAgentError < ApiError; end
29
+ class ConfigurationError < ApiError; end
30
+ class OauthError < ApiError; end
29
31
  class AuthenticationError < ApiError; end
30
- class BlockedAccountError < ApiError; end
31
- class RateLimitError < ApiError; end
32
- class ReadOnlySiteError < ApiError; end
33
- class PaginationError < ApiError; end
34
-
35
- class RecordNotFoundError < ApiError; end
36
- class InvalidRecordError < ApiError; end
37
- class DestroySubjectError < ApiError; end
38
- class SubjectLimitError < ApiError; end
39
- class GeneratorLimitError < ApiError; end
40
- class UnsupportedFeatureError < ApiError; end
41
32
 
42
33
  class ClientError < ApiError; end
43
34
  class ServerError < ApiError; end
44
35
 
36
+ HTTP_GET = :get
37
+ HTTP_POST = :post
38
+ HTTP_PATCH = :patch
39
+ HTTP_DELETE = :delete
40
+
45
41
  def self.configure(&block)
46
- Fakturoid::Api.configure(&block)
42
+ Client.configure(&block)
43
+ end
44
+
45
+ def self.client
46
+ @client ||= Client.new
47
47
  end
48
48
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fakturoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eda Riedl
@@ -11,10 +11,10 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2023-01-13 00:00:00.000000000 Z
14
+ date: 2024-07-15 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
- name: multi_json
17
+ name: faraday
18
18
  requirement: !ruby/object:Gem::Requirement
19
19
  requirements:
20
20
  - - ">="
@@ -28,7 +28,7 @@ dependencies:
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
30
  - !ruby/object:Gem::Dependency
31
- name: faraday
31
+ name: multi_json
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  requirements:
34
34
  - - ">="
@@ -56,7 +56,7 @@ dependencies:
56
56
  - !ruby/object:Gem::Version
57
57
  version: '1'
58
58
  - !ruby/object:Gem::Dependency
59
- name: rake
59
+ name: minitest
60
60
  requirement: !ruby/object:Gem::Requirement
61
61
  requirements:
62
62
  - - ">="
@@ -70,7 +70,7 @@ dependencies:
70
70
  - !ruby/object:Gem::Version
71
71
  version: '0'
72
72
  - !ruby/object:Gem::Dependency
73
- name: minitest
73
+ name: mocha
74
74
  requirement: !ruby/object:Gem::Requirement
75
75
  requirements:
76
76
  - - ">="
@@ -84,7 +84,7 @@ dependencies:
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0'
86
86
  - !ruby/object:Gem::Dependency
87
- name: shoulda-context
87
+ name: rake
88
88
  requirement: !ruby/object:Gem::Requirement
89
89
  requirements:
90
90
  - - ">="
@@ -98,7 +98,7 @@ dependencies:
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
100
  - !ruby/object:Gem::Dependency
101
- name: mocha
101
+ name: rubocop
102
102
  requirement: !ruby/object:Gem::Requirement
103
103
  requirements:
104
104
  - - ">="
@@ -112,7 +112,7 @@ dependencies:
112
112
  - !ruby/object:Gem::Version
113
113
  version: '0'
114
114
  - !ruby/object:Gem::Dependency
115
- name: rubocop
115
+ name: shoulda-context
116
116
  requirement: !ruby/object:Gem::Requirement
117
117
  requirements:
118
118
  - - ">="
@@ -132,54 +132,59 @@ executables: []
132
132
  extensions: []
133
133
  extra_rdoc_files: []
134
134
  files:
135
- - ".github/workflows/rubocop.yml"
136
- - ".github/workflows/tests.yml"
137
- - ".gitignore"
138
135
  - ".rubocop.yml"
139
136
  - ".ruby-version"
140
137
  - CHANGELOG.md
141
- - Gemfile
142
138
  - LICENSE.txt
143
139
  - README.md
144
140
  - Rakefile
145
141
  - fakturoid.gemspec
146
142
  - lib/fakturoid.rb
147
143
  - lib/fakturoid/api.rb
148
- - lib/fakturoid/api/arguments.rb
149
- - lib/fakturoid/api/http_methods.rb
144
+ - lib/fakturoid/api/account.rb
145
+ - lib/fakturoid/api/bank_account.rb
146
+ - lib/fakturoid/api/base.rb
147
+ - lib/fakturoid/api/event.rb
148
+ - lib/fakturoid/api/expense.rb
149
+ - lib/fakturoid/api/expense_payment.rb
150
+ - lib/fakturoid/api/generator.rb
151
+ - lib/fakturoid/api/inbox_file.rb
152
+ - lib/fakturoid/api/inventory_item.rb
153
+ - lib/fakturoid/api/inventory_move.rb
154
+ - lib/fakturoid/api/invoice.rb
155
+ - lib/fakturoid/api/invoice_message.rb
156
+ - lib/fakturoid/api/invoice_payment.rb
157
+ - lib/fakturoid/api/number_format.rb
158
+ - lib/fakturoid/api/recurring_generator.rb
159
+ - lib/fakturoid/api/subject.rb
160
+ - lib/fakturoid/api/todo.rb
161
+ - lib/fakturoid/api/user.rb
162
+ - lib/fakturoid/api/webhook.rb
150
163
  - lib/fakturoid/client.rb
151
- - lib/fakturoid/client/account.rb
152
- - lib/fakturoid/client/bank_account.rb
153
- - lib/fakturoid/client/event.rb
154
- - lib/fakturoid/client/expense.rb
155
- - lib/fakturoid/client/generator.rb
156
- - lib/fakturoid/client/inventory_items.rb
157
- - lib/fakturoid/client/inventory_moves.rb
158
- - lib/fakturoid/client/invoice.rb
159
- - lib/fakturoid/client/number_format.rb
160
- - lib/fakturoid/client/subject.rb
161
- - lib/fakturoid/client/todo.rb
162
- - lib/fakturoid/client/user.rb
163
164
  - lib/fakturoid/config.rb
164
- - lib/fakturoid/connection.rb
165
+ - lib/fakturoid/oauth.rb
166
+ - lib/fakturoid/oauth/access_token_service.rb
167
+ - lib/fakturoid/oauth/credentials.rb
168
+ - lib/fakturoid/oauth/flow.rb
169
+ - lib/fakturoid/oauth/flow/authorization_code.rb
170
+ - lib/fakturoid/oauth/flow/base.rb
171
+ - lib/fakturoid/oauth/flow/client_credentials.rb
172
+ - lib/fakturoid/oauth/request.rb
173
+ - lib/fakturoid/oauth/request/api.rb
174
+ - lib/fakturoid/oauth/request/base.rb
175
+ - lib/fakturoid/oauth/request/oauth.rb
176
+ - lib/fakturoid/oauth/token_response.rb
165
177
  - lib/fakturoid/railtie.rb
166
- - lib/fakturoid/request.rb
167
178
  - lib/fakturoid/response.rb
179
+ - lib/fakturoid/utils.rb
168
180
  - lib/fakturoid/version.rb
169
- - test/api_test.rb
170
- - test/config_test.rb
171
- - test/fixtures/blocked_account.json
172
- - test/fixtures/invoice.json
173
- - test/fixtures/invoice.pdf
174
- - test/fixtures/invoice_error.json
175
- - test/fixtures/subjects.json
176
- - test/request_test.rb
177
- - test/response_test.rb
178
- - test/test_helper.rb
179
181
  homepage: https://github.com/fakturoid/fakturoid-ruby
180
182
  licenses:
181
183
  - MIT
182
- metadata: {}
184
+ metadata:
185
+ homepage_uri: https://github.com/fakturoid/fakturoid-ruby
186
+ source_code_uri: https://github.com/fakturoid/fakturoid-ruby
187
+ changelog_uri: https://github.com/fakturoid/fakturoid-ruby/blob/main/CHANGELOG.md
183
188
  post_install_message:
184
189
  rdoc_options: []
185
190
  require_paths:
@@ -188,25 +193,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
188
193
  requirements:
189
194
  - - ">="
190
195
  - !ruby/object:Gem::Version
191
- version: '0'
196
+ version: 2.7.0
192
197
  required_rubygems_version: !ruby/object:Gem::Requirement
193
198
  requirements:
194
199
  - - ">="
195
200
  - !ruby/object:Gem::Version
196
201
  version: '0'
197
202
  requirements: []
198
- rubygems_version: 3.4.2
203
+ rubygems_version: 3.5.13
199
204
  signing_key:
200
205
  specification_version: 4
201
206
  summary: Ruby client for web based invoicing service www.fakturoid.cz
202
- test_files:
203
- - test/api_test.rb
204
- - test/config_test.rb
205
- - test/fixtures/blocked_account.json
206
- - test/fixtures/invoice.json
207
- - test/fixtures/invoice.pdf
208
- - test/fixtures/invoice_error.json
209
- - test/fixtures/subjects.json
210
- - test/request_test.rb
211
- - test/response_test.rb
212
- - test/test_helper.rb
207
+ test_files: []
@@ -1,20 +0,0 @@
1
- # https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-ruby
2
- # https://github.com/actions/starter-workflows/blob/main/ci/ruby.yml
3
-
4
- name: Rubocop
5
- on: [push, pull_request]
6
-
7
- jobs:
8
- test:
9
- runs-on: ubuntu-latest
10
- steps:
11
- - uses: actions/checkout@v3
12
-
13
- - name: Set up Ruby
14
- uses: ruby/setup-ruby@v1
15
- with:
16
- ruby-version: 3.0
17
- bundler-cache: true
18
-
19
- - name: Rubocop
20
- run: bundle exec rubocop
@@ -1,27 +0,0 @@
1
- # https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-ruby
2
- # https://github.com/actions/starter-workflows/blob/main/ci/ruby.yml
3
-
4
- name: Tests
5
- on: [push, pull_request]
6
-
7
- jobs:
8
- test:
9
-
10
- runs-on: ubuntu-latest
11
- strategy:
12
- matrix:
13
- ruby-version: ['2.6', '2.7', '3.0']
14
-
15
- steps:
16
- - uses: actions/checkout@v3
17
-
18
- - name: Set up Ruby
19
- # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
20
- # change this to (see https://github.com/ruby/setup-ruby#versioning):
21
- uses: ruby/setup-ruby@v1
22
- with:
23
- ruby-version: ${{ matrix.ruby-version }}
24
- bundler-cache: true # runs 'bundle install' and caches installed gems automatically
25
-
26
- - name: Run tests
27
- run: bundle exec rake
data/.gitignore DELETED
@@ -1,7 +0,0 @@
1
- .bundle/
2
- Gemfile.lock
3
- coverage/
4
- doc/
5
- pkg/
6
- .DS_Store
7
- rubocop.html
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- # Specify your gem's dependencies in fakturoid.gemspec
6
- gemspec
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Fakturoid
4
- class Api
5
- module Arguments
6
- def permit_params(params_hash, *permitted_params)
7
- params_hash.select { |param, _value| permitted_params.include?(param.to_sym) }
8
- end
9
-
10
- def validate_numerical_id(id)
11
- raise ArgumentError, "Wrong ID given: #{id}" if !id.is_a?(Integer) && !(id.is_a?(String) && id =~ /\A\d+\z/)
12
- true
13
- end
14
-
15
- def validate_search_query(query)
16
- raise ArgumentError, "Query parameter is required" if query.nil? || query.empty?
17
- true
18
- end
19
- end
20
- end
21
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Fakturoid
4
- class Api
5
- module HttpMethods
6
- def get_request(path, params = {})
7
- Request.new(:get, path, self).call(params)
8
- end
9
-
10
- def post_request(path, params = {})
11
- Request.new(:post, path, self).call(params)
12
- end
13
-
14
- def patch_request(path, params = {})
15
- Request.new(:patch, path, self).call(params)
16
- end
17
-
18
- def delete_request(path, params = {})
19
- Request.new(:delete, path, self).call(params)
20
- end
21
- end
22
- end
23
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Fakturoid
4
- module Client
5
- class Account < Fakturoid::Api
6
- def self.current
7
- get_request("account.json")
8
- end
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Fakturoid
4
- module Client
5
- class BankAccount < Fakturoid::Api
6
- def self.all
7
- get_request("bank_accounts.json")
8
- end
9
- end
10
- end
11
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Fakturoid
4
- module Client
5
- class Event < Fakturoid::Api
6
- def self.all(params = {})
7
- request_params = permit_params(params, :page, :since, :subject_id) || {}
8
-
9
- get_request("events.json", request_params: request_params)
10
- end
11
-
12
- def self.paid(params = {})
13
- request_params = permit_params(params, :page, :since, :subject_id) || {}
14
-
15
- get_request("events/paid.json", request_params: request_params)
16
- end
17
- end
18
- end
19
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Fakturoid
4
- module Client
5
- class Expense < Fakturoid::Api
6
- def self.all(params = {})
7
- request_params = permit_params(params, :page, :since, :updated_since, :number, :variable_symbol, :status, :subject_id, :custom_id) || {}
8
-
9
- get_request("expenses.json", request_params: request_params)
10
- end
11
-
12
- def self.find(id)
13
- validate_numerical_id(id)
14
- get_request("expenses/#{id}.json")
15
- end
16
-
17
- def self.search(query, params = {})
18
- validate_search_query(query)
19
-
20
- request_params = permit_params(params, :page)
21
- request_params[:query] = query
22
-
23
- get_request("expenses/search.json", request_params: request_params)
24
- end
25
-
26
- def self.fire(id, event, params = {})
27
- request_params = permit_params(params, :paid_on, :paid_amount, :variable_symbol, :bank_account_id) || {}
28
- request_params[:event] = event
29
-
30
- validate_numerical_id(id)
31
- post_request("expenses/#{id}/fire.json", request_params: request_params)
32
- end
33
-
34
- def self.create(payload = {})
35
- post_request("expenses.json", payload: payload)
36
- end
37
-
38
- def self.update(id, payload = {})
39
- validate_numerical_id(id)
40
- patch_request("expenses/#{id}.json", payload: payload)
41
- end
42
-
43
- def self.delete(id)
44
- validate_numerical_id(id)
45
- delete_request("expenses/#{id}.json")
46
- end
47
- end
48
- end
49
- end