active_call-doc_fox 0.1.2 → 0.2.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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -0
  3. data/CHANGELOG.md +10 -0
  4. data/README.md +423 -10
  5. data/lib/doc_fox/access_token/get_service.rb +2 -0
  6. data/lib/doc_fox/authentication/get_service.rb +4 -0
  7. data/lib/doc_fox/base_service.rb +1 -0
  8. data/lib/doc_fox/concerns/enumerable.rb +1 -1
  9. data/lib/doc_fox/data_requirement/facade.rb +25 -0
  10. data/lib/doc_fox/data_requirement/get_service.rb +53 -0
  11. data/lib/doc_fox/data_requirement/list_service.rb +67 -0
  12. data/lib/doc_fox/document/download_service.rb +81 -0
  13. data/lib/doc_fox/document/facade.rb +22 -0
  14. data/lib/doc_fox/document/get_service.rb +54 -0
  15. data/lib/doc_fox/document/list_service.rb +36 -0
  16. data/lib/doc_fox/document/upload_service.rb +62 -0
  17. data/lib/doc_fox/document_token/create_service.rb +57 -0
  18. data/lib/doc_fox/document_token/facade.rb +15 -0
  19. data/lib/doc_fox/document_token/get_service.rb +46 -0
  20. data/lib/doc_fox/document_token/list_service.rb +36 -0
  21. data/lib/doc_fox/evidence_submission/approve_service.rb +54 -0
  22. data/lib/doc_fox/evidence_submission/facade.rb +20 -0
  23. data/lib/doc_fox/evidence_submission/get_service.rb +54 -0
  24. data/lib/doc_fox/evidence_submission/list_service.rb +36 -0
  25. data/lib/doc_fox/evidence_submission/reject_service.rb +58 -0
  26. data/lib/doc_fox/evidence_submission/replace_service.rb +54 -0
  27. data/lib/doc_fox/evidence_submission/update_service.rb +95 -0
  28. data/lib/doc_fox/kyc_application/approve_service.rb +2 -0
  29. data/lib/doc_fox/kyc_application/archive_service.rb +2 -0
  30. data/lib/doc_fox/kyc_application/create_service.rb +2 -0
  31. data/lib/doc_fox/kyc_application/delete_service.rb +2 -0
  32. data/lib/doc_fox/kyc_application/get_service.rb +3 -1
  33. data/lib/doc_fox/kyc_application/list_service.rb +2 -0
  34. data/lib/doc_fox/kyc_application/transfer_service.rb +2 -0
  35. data/lib/doc_fox/kyc_application/unapprove_service.rb +2 -0
  36. data/lib/doc_fox/kyc_application/unarchive_service.rb +2 -0
  37. data/lib/doc_fox/kyc_entity_template/get_service.rb +2 -0
  38. data/lib/doc_fox/kyc_entity_template/list_service.rb +2 -0
  39. data/lib/doc_fox/profile/facade.rb +15 -0
  40. data/lib/doc_fox/profile/get_service.rb +53 -0
  41. data/lib/doc_fox/profile/list_service.rb +36 -0
  42. data/lib/doc_fox/status_summary/facade.rb +14 -0
  43. data/lib/doc_fox/status_summary/get_service.rb +47 -0
  44. data/lib/doc_fox/user/get_service.rb +2 -0
  45. data/lib/doc_fox/user/list_service.rb +2 -0
  46. data/lib/doc_fox/version.rb +1 -1
  47. data/lib/doc_fox.rb +1 -0
  48. metadata +40 -2
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DocFox::DataRequirement::ListService < DocFox::BaseService
4
+ include DocFox::Enumerable
5
+
6
+ attr_reader :kyc_application_id, :account_application_id, :forms
7
+
8
+ validates :kyc_application_id_or_account_application_id, presence: true
9
+
10
+ # List data requirements.
11
+ #
12
+ # https://www.docfoxapp.com/api/v2/documentation#tag/Data-Requirements/paths/~1api~1v2~1kyc_applications~1%7Bkyc_application_id%7D~1data_requirements/get
13
+ #
14
+ # List data requirements associated with an account application.
15
+ #
16
+ # https://www.docfoxapp.com/api/v2/documentation#tag/Data-Requirements/paths/~1api~1v2~1account_applications~1%7Baccount_application_id%7D~1data_requirements/get
17
+ #
18
+ # ==== Examples
19
+ #
20
+ # service = DocFox::DataRequirement::ListService.call(kyc_application_id: '').first
21
+ # service.id
22
+ # service.name
23
+ #
24
+ # service = DocFox::DataRequirement::ListService.call(account_application_id: '').first
25
+ # service.id
26
+ # service.name
27
+ #
28
+ # If you don't provide the `per_page` argument, multiple API requests will be made untill all records have been
29
+ # returned. You could be rate limited, so use wisely.
30
+ #
31
+ # DocFox::DataRequirement::ListService.call(kyc_application_id: '', page: 1, per_page: 10).map { _1 }
32
+ #
33
+ # Filter by forms.
34
+ #
35
+ # DocFox::DataRequirement::ListService.call(kyc_application_id: '', forms: true).map { _1 }
36
+ #
37
+ # GET /api/v2/kyc_applications/:kyc_application_id/data_requirements
38
+ # GET /api/v2/account_applications/:account_application_id/data_requirements
39
+ def initialize(kyc_application_id: nil, account_application_id: nil, page: 1, per_page: Float::INFINITY, forms: false)
40
+ @kyc_application_id = kyc_application_id
41
+ @account_application_id = account_application_id
42
+ @forms = forms
43
+
44
+ entity_path = kyc_application_id.present? ? 'kyc_applications' : 'account_applications'
45
+
46
+ super(
47
+ path: "#{entity_path}/#{kyc_application_id_or_account_application_id}/data_requirements",
48
+ facade_klass: DocFox::DataRequirement::Facade,
49
+ page: page,
50
+ per_page: per_page
51
+ )
52
+ end
53
+
54
+ private
55
+
56
+ def params
57
+ @_params ||= begin
58
+ params = { page: page, per_page: max_per_page_per_request }
59
+ params[:forms] = true if forms == true
60
+ params
61
+ end
62
+ end
63
+
64
+ def kyc_application_id_or_account_application_id
65
+ kyc_application_id.presence || account_application_id.presence
66
+ end
67
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DocFox::Document::DownloadService < DocFox::BaseService
4
+ CONTENT_TYPES = ['image/jpeg', 'image/png', 'application/pdf'].freeze
5
+
6
+ attr_reader :document_id, :document_token_id, :content_type, :url
7
+ private attr_reader :document_token_create_service
8
+
9
+ validates :document_token_id_or_document_id, presence: true
10
+ validates :content_type, presence: true, if: -> { document_token_id.present? }
11
+
12
+ validates :content_type, on: :request,
13
+ inclusion: {
14
+ in: CONTENT_TYPES,
15
+ message: "has to be one of #{CONTENT_TYPES.to_sentence(last_word_connector: ' or ')}"
16
+ }
17
+
18
+ validate on: :request do
19
+ if document_token_id.blank? && !document_token_create_service.success?
20
+ errors.merge!(document_token_create_service.errors)
21
+ end
22
+ end
23
+
24
+ before_call :create_document_token, :set_document_token_id_and_content_type, if: -> { document_token_id.blank? }
25
+
26
+ def initialize(document_id: nil, document_token_id: nil, content_type: nil)
27
+ @document_id = document_id
28
+ @document_token_id = document_token_id
29
+ @content_type = content_type
30
+ end
31
+
32
+ # Download a document file.
33
+ #
34
+ # https://www.docfoxapp.com/api/v2/documentation#tag/Download-Documents/paths/~1api~1v2~1document_file_downloads~1%7Bdocument_token_id%7D/get
35
+ #
36
+ # ==== Examples
37
+ #
38
+ # service = DocFox::Document::DownloadService.call(document_token_id: '', content_type: 'image/png')
39
+ #
40
+ # service.success? # => true
41
+ # service.errors # => #<ActiveModel::Errors []>
42
+ #
43
+ # service.response # => #<Faraday::Response ...>
44
+ # service.response.status # => 200
45
+ # service.response.body # => "\xFF\xD8\xFF\xDB\x00\x84\x00\x04\x05\x..."
46
+ #
47
+ # Possible values for `content_type`.
48
+ #
49
+ # - `image/jpeg`
50
+ # - `image/png`
51
+ # - `application/pdf`
52
+ #
53
+ # You can also provide just the `document_id` and the service will automatically request the `document_token_id` and `content_type` for you.
54
+ #
55
+ # service = DocFox::Document::DownloadService.call(document_id: '')
56
+ #
57
+ # GET /api/v2/document_file_downloads/:document_token_id
58
+ def call
59
+ connection.get("document_file_downloads/#{document_token_id}", nil, { 'Accept' => content_type })
60
+ end
61
+
62
+ private
63
+
64
+ def document_token_id_or_document_id
65
+ document_token_id.presence || document_id.presence
66
+ end
67
+
68
+ def create_document_token
69
+ @document_token_create_service = DocFox::DocumentToken::CreateService.call(
70
+ document_id: document_id,
71
+ data: { type: 'document_token' }
72
+ )
73
+ end
74
+
75
+ def set_document_token_id_and_content_type
76
+ return unless document_token_create_service.success?
77
+
78
+ @document_token_id = document_token_create_service.id
79
+ @content_type = document_token_create_service.content_type
80
+ end
81
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DocFox::Document::Facade
4
+ attr_reader :id, :attributes, :relationships, :included, :content_type, :created_at, :data_capture_fields, :filename,
5
+ :token, :token_expiry, :uploaded_by, :updated_at
6
+
7
+ def initialize(hash)
8
+ @id = hash.dig('data', 'id') || hash['id']
9
+ @attributes = hash.dig('data', 'attributes') || hash['attributes']
10
+ @relationships = hash.dig('data', 'relationships') || hash['relationships']
11
+ @included = hash['included']
12
+
13
+ @content_type = attributes['content_type']
14
+ @created_at = attributes['created_at']
15
+ @data_capture_fields = attributes['data_capture_fields']
16
+ @filename = attributes['filename']
17
+ @token = attributes['token']
18
+ @token_expiry = attributes['token_expiry']
19
+ @uploaded_by = attributes['uploaded_by']
20
+ @updated_at = attributes['updated_at']
21
+ end
22
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DocFox::Document::GetService < DocFox::BaseService
4
+ attr_reader :id, :params
5
+
6
+ validates :id, presence: true
7
+
8
+ after_call :set_facade
9
+
10
+ delegate_missing_to :@facade
11
+
12
+ def initialize(id:, params: {})
13
+ @id = id
14
+ @params = params
15
+ end
16
+
17
+ # Get a document.
18
+ #
19
+ # https://www.docfoxapp.com/api/v2/documentation#tag/Documents/paths/~1api~1v2~1documents~1%7Bdocument_id%7D/get
20
+ #
21
+ # ==== Examples
22
+ #
23
+ # service = DocFox::Document::GetService.call(id: '')
24
+ #
25
+ # service.success? # => true
26
+ # service.errors # => #<ActiveModel::Errors []>
27
+ #
28
+ # service.response # => #<Faraday::Response ...>
29
+ # service.response.status # => 200
30
+ # service.response.body # => {}
31
+ #
32
+ # service.facade # => #<DocFox::Document::Facade ...>
33
+ # service.facade.id
34
+ # service.id
35
+ #
36
+ # service.relationships.dig('evidence_submissions', 'data')
37
+ # service.relationships.dig('document_tokens', 'links', 'related')
38
+ #
39
+ # Include related resources.
40
+ #
41
+ # service = DocFox::Document::GetService.call(id: '', params: { include: 'evidence_submissions' })
42
+ # service.included
43
+ #
44
+ # GET /api/v2/documents/:id
45
+ def call
46
+ connection.get("documents/#{id}", **params)
47
+ end
48
+
49
+ private
50
+
51
+ def set_facade
52
+ @facade = DocFox::Document::Facade.new(response.body)
53
+ end
54
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DocFox::Document::ListService < DocFox::BaseService
4
+ include DocFox::Enumerable
5
+
6
+ attr_reader :evidence_submission_id
7
+
8
+ validates :evidence_submission_id, presence: true
9
+
10
+ # List documents.
11
+ #
12
+ # https://www.docfoxapp.com/api/v2/documentation#tag/Documents/paths/~1api~1v2~1evidence_submissions~1%7Bevidence_submission_id%7D~1documents/get
13
+ #
14
+ # ==== Examples
15
+ #
16
+ # service = DocFox::Document::ListService.call(evidence_submission_id: '').first
17
+ # service.id
18
+ # service.filename
19
+ #
20
+ # If you don't provide the `per_page` argument, multiple API requests will be made untill all records have been
21
+ # returned. You could be rate limited, so use wisely.
22
+ #
23
+ # DocFox::Document::ListService.call(evidence_submission_id: '', page: 1, per_page: 10).map { _1 }
24
+ #
25
+ # GET /api/v2/evidence_submissions/:evidence_submission_id/documents
26
+ def initialize(evidence_submission_id:, page: 1, per_page: Float::INFINITY)
27
+ @evidence_submission_id = evidence_submission_id
28
+
29
+ super(
30
+ path: "evidence_submissions/#{evidence_submission_id}/documents",
31
+ facade_klass: DocFox::Document::Facade,
32
+ page: page,
33
+ per_page: per_page
34
+ )
35
+ end
36
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DocFox::Document::UploadService < DocFox::BaseService
4
+ attr_reader :evidence_submission_id, :data
5
+
6
+ validates :evidence_submission_id, :data, presence: true
7
+
8
+ after_call :set_facade
9
+
10
+ delegate_missing_to :@facade
11
+
12
+ def initialize(evidence_submission_id:, data:)
13
+ @evidence_submission_id = evidence_submission_id
14
+ @data = data
15
+ end
16
+
17
+ # Upload a document file.
18
+ #
19
+ # https://www.docfoxapp.com/api/v2/documentation#tag/Document-Uploads/paths/~1api~1v2~1evidence_submissions~1%7Bevidence_submission_id%7D~1documents/post
20
+ #
21
+ # ==== Examples
22
+ #
23
+ # service = DocFox::Document::UploadService.call(
24
+ # evidence_submission_id: '',
25
+ # data: {
26
+ # type: 'document',
27
+ # attributes: {
28
+ # evidence_type: 'taxes_paid_in_prior_quarter',
29
+ # filename: 'taxes_paid.png',
30
+ # document_data: "data:image/png;base64,#{Base64.encode64(File.read('/path/to/taxes_paid.png'))}"
31
+ # }
32
+ # }
33
+ # )
34
+ #
35
+ # service.success? # => true
36
+ # service.errors # => #<ActiveModel::Errors []>
37
+ #
38
+ # service.response # => #<Faraday::Response ...>
39
+ # service.response.status # => 201
40
+ # service.response.body # => {}
41
+ #
42
+ # service.facade # => #<DocFox::Document::Facade ...>
43
+ # service.facade.id
44
+ # service.id
45
+ #
46
+ # POST /api/v2/evidence_submissions/:evidence_submission_id/documents
47
+ def call
48
+ connection.post("evidence_submissions/#{evidence_submission_id}/documents", **params)
49
+ end
50
+
51
+ private
52
+
53
+ def params
54
+ {
55
+ data: data
56
+ }
57
+ end
58
+
59
+ def set_facade
60
+ @facade = DocFox::Document::Facade.new(response.body)
61
+ end
62
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DocFox::DocumentToken::CreateService < DocFox::BaseService
4
+ attr_reader :document_id, :data
5
+
6
+ validates :document_id, :data, presence: true
7
+
8
+ after_call :set_facade
9
+
10
+ delegate_missing_to :@facade
11
+
12
+ def initialize(document_id:, data:)
13
+ @document_id = document_id
14
+ @data = data
15
+ end
16
+
17
+ # Create a document token.
18
+ #
19
+ # https://www.docfoxapp.com/api/v2/documentation#tag/Document-Tokens/paths/~1api~1v2~1documents~1%7Bdocument_id%7D~1document_tokens/post
20
+ #
21
+ # ==== Examples
22
+ #
23
+ # service = DocFox::DocumentToken::CreateService.call(
24
+ # document_id: '',
25
+ # data: {
26
+ # type: 'document_token'
27
+ # }
28
+ # )
29
+ #
30
+ # service.success? # => true
31
+ # service.errors # => #<ActiveModel::Errors []>
32
+ #
33
+ # service.response # => #<Faraday::Response ...>
34
+ # service.response.status # => 201
35
+ # service.response.body # => {}
36
+ #
37
+ # service.facade # => #<DocFox::DocumentToken::Facade ...>
38
+ # service.facade.id
39
+ # service.id
40
+ #
41
+ # POST /api/v2/documents/:document_id/document_tokens
42
+ def call
43
+ connection.post("documents/#{document_id}/document_tokens", **params)
44
+ end
45
+
46
+ private
47
+
48
+ def params
49
+ {
50
+ data: data
51
+ }
52
+ end
53
+
54
+ def set_facade
55
+ @facade = DocFox::DocumentToken::Facade.new(response.body)
56
+ end
57
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DocFox::DocumentToken::Facade
4
+ attr_reader :id, :attributes, :content_type, :created_at, :expiry, :updated_at
5
+
6
+ def initialize(hash)
7
+ @id = hash.dig('data', 'id') || hash['id']
8
+ @attributes = hash.dig('data', 'attributes') || hash['attributes']
9
+
10
+ @content_type = attributes['content_type']
11
+ @created_at = attributes['created_at']
12
+ @expiry = attributes['expiry']
13
+ @updated_at = attributes['updated_at']
14
+ end
15
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DocFox::DocumentToken::GetService < DocFox::BaseService
4
+ attr_reader :id, :params
5
+
6
+ validates :id, presence: true
7
+
8
+ after_call :set_facade
9
+
10
+ delegate_missing_to :@facade
11
+
12
+ def initialize(id:, params: {})
13
+ @id = id
14
+ @params = params
15
+ end
16
+
17
+ # Get a document token.
18
+ #
19
+ # https://www.docfoxapp.com/api/v2/documentation#tag/Document-Tokens/paths/~1api~1v2~1document_tokens~1%7Bdocument_token_id%7D/get
20
+ #
21
+ # ==== Examples
22
+ #
23
+ # service = DocFox::DocumentToken::GetService.call(id: '')
24
+ #
25
+ # service.success? # => true
26
+ # service.errors # => #<ActiveModel::Errors []>
27
+ #
28
+ # service.response # => #<Faraday::Response ...>
29
+ # service.response.status # => 200
30
+ # service.response.body # => {}
31
+ #
32
+ # service.facade # => #<DocFox::DocumentToken::Facade ...>
33
+ # service.facade.id
34
+ # service.id
35
+ #
36
+ # GET /api/v2/document_tokens/:id
37
+ def call
38
+ connection.get("document_tokens/#{id}", **params)
39
+ end
40
+
41
+ private
42
+
43
+ def set_facade
44
+ @facade = DocFox::DocumentToken::Facade.new(response.body)
45
+ end
46
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DocFox::DocumentToken::ListService < DocFox::BaseService
4
+ include DocFox::Enumerable
5
+
6
+ attr_reader :document_id
7
+
8
+ validates :document_id, presence: true
9
+
10
+ # List document tokens.
11
+ #
12
+ # https://www.docfoxapp.com/api/v2/documentation#tag/Document-Tokens/paths/~1api~1v2~1documents~1%7Bdocument_id%7D~1document_tokens/get
13
+ #
14
+ # ==== Examples
15
+ #
16
+ # service = DocFox::DocumentToken::ListService.call(document_id: '').first
17
+ # service.id
18
+ # service.expiry
19
+ #
20
+ # If you don't provide the `per_page` argument, multiple API requests will be made untill all records have been
21
+ # returned. You could be rate limited, so use wisely.
22
+ #
23
+ # DocFox::DocumentToken::ListService.call(document_id: '', page: 1, per_page: 10).map { _1 }
24
+ #
25
+ # GET /api/v2/documents/:document_id/document_tokens
26
+ def initialize(document_id:, page: 1, per_page: Float::INFINITY)
27
+ @document_id = document_id
28
+
29
+ super(
30
+ path: "documents/#{document_id}/document_tokens",
31
+ facade_klass: DocFox::DocumentToken::Facade,
32
+ page: page,
33
+ per_page: per_page
34
+ )
35
+ end
36
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DocFox::EvidenceSubmission::ApproveService < DocFox::BaseService
4
+ attr_reader :id
5
+
6
+ validates :id, presence: true
7
+
8
+ after_call :set_facade
9
+
10
+ delegate_missing_to :@facade
11
+
12
+ def initialize(id:)
13
+ @id = id
14
+ end
15
+
16
+ # Approve an active evidence submission.
17
+ #
18
+ # https://www.docfoxapp.com/api/v2/documentation#tag/Evidence-Submissions/paths/~1api~1v2~1evidence_submissions~1%7Bevidence_submission_id%7D~1approve/patch
19
+ #
20
+ # ==== Examples
21
+ #
22
+ # service = DocFox::EvidenceSubmission::ApproveService.call(id: '')
23
+ #
24
+ # service.success? # => true
25
+ # service.errors # => #<ActiveModel::Errors []>
26
+ #
27
+ # service.response # => #<Faraday::Response ...>
28
+ # service.response.status # => 200
29
+ # service.response.body # => {}
30
+ #
31
+ # service.facade # => #<DocFox::EvidenceSubmission::Facade ...>
32
+ # service.facade.id
33
+ # service.id
34
+ #
35
+ # PATCH /api/v2/kyc_applications/:id/approve
36
+ def call
37
+ connection.patch("evidence_submissions/#{id}/approve", **params)
38
+ end
39
+
40
+ private
41
+
42
+ def params
43
+ {
44
+ data: {
45
+ type: 'evidence_submission',
46
+ id: id
47
+ }
48
+ }
49
+ end
50
+
51
+ def set_facade
52
+ @facade = DocFox::EvidenceSubmission::Facade.new(response.body)
53
+ end
54
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DocFox::EvidenceSubmission::Facade
4
+ attr_reader :id, :attributes, :relationships, :included, :created_at, :evidence_type, :external, :form, :status,
5
+ :updated_at
6
+
7
+ def initialize(hash)
8
+ @id = hash.dig('data', 'id') || hash['id']
9
+ @attributes = hash.dig('data', 'attributes') || hash['attributes']
10
+ @relationships = hash.dig('data', 'relationships') || hash['relationships']
11
+ @included = hash['included']
12
+
13
+ @created_at = attributes['created_at']
14
+ @evidence_type = attributes['evidence_type']
15
+ @external = attributes['external']
16
+ @form = attributes['form']
17
+ @status = attributes['status']
18
+ @updated_at = attributes['updated_at']
19
+ end
20
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DocFox::EvidenceSubmission::GetService < DocFox::BaseService
4
+ attr_reader :id, :params
5
+
6
+ validates :id, presence: true
7
+
8
+ after_call :set_facade
9
+
10
+ delegate_missing_to :@facade
11
+
12
+ def initialize(id:, params: {})
13
+ @id = id
14
+ @params = params
15
+ end
16
+
17
+ # Get an evidence submission.
18
+ #
19
+ # https://www.docfoxapp.com/api/v2/documentation#tag/Evidence-Submissions/paths/~1api~1v2~1evidence_submissions~1%7Bevidence_submission_id%7D/get
20
+ #
21
+ # ==== Examples
22
+ #
23
+ # service = DocFox::EvidenceSubmission::GetService.call(id: '')
24
+ #
25
+ # service.success? # => true
26
+ # service.errors # => #<ActiveModel::Errors []>
27
+ #
28
+ # service.response # => #<Faraday::Response ...>
29
+ # service.response.status # => 200
30
+ # service.response.body # => {}
31
+ #
32
+ # service.facade # => #<DocFox::EvidenceSubmission::Facade ...>
33
+ # service.facade.id
34
+ # service.id
35
+ #
36
+ # service.relationships.dig('document', 'data')
37
+ # service.relationships.dig('data_requirement', 'links', 'related')
38
+ #
39
+ # Include related resources.
40
+ #
41
+ # service = DocFox::EvidenceSubmission::GetService.call(id: '', params: { include: 'document,qualitative_checks' })
42
+ # service.included
43
+ #
44
+ # GET /api/v2/evidence_submissions/:id
45
+ def call
46
+ connection.get("evidence_submissions/#{id}", **params)
47
+ end
48
+
49
+ private
50
+
51
+ def set_facade
52
+ @facade = DocFox::EvidenceSubmission::Facade.new(response.body)
53
+ end
54
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DocFox::EvidenceSubmission::ListService < DocFox::BaseService
4
+ include DocFox::Enumerable
5
+
6
+ attr_reader :data_requirement_id
7
+
8
+ validates :data_requirement_id, presence: true
9
+
10
+ # List evidence submissions.
11
+ #
12
+ # https://www.docfoxapp.com/api/v2/documentation#tag/Evidence-Submissions/paths/~1api~1v2~1data_requirements~1%7Bdata_requirement_id%7D~1evidence_submissions/get
13
+ #
14
+ # ==== Examples
15
+ #
16
+ # service = DocFox::EvidenceSubmission::ListService.call(data_requirement_id: '').first
17
+ # service.id
18
+ # service.status
19
+ #
20
+ # If you don't provide the `per_page` argument, multiple API requests will be made untill all records have been
21
+ # returned. You could be rate limited, so use wisely.
22
+ #
23
+ # DocFox::EvidenceSubmission::ListService.call(data_requirement_id: '', page: 1, per_page: 10).map { _1 }
24
+ #
25
+ # GET /api/v2/data_requirements/:data_requirement_id/evidence_submissions
26
+ def initialize(data_requirement_id:, page: 1, per_page: Float::INFINITY)
27
+ @data_requirement_id = data_requirement_id
28
+
29
+ super(
30
+ path: "data_requirements/#{data_requirement_id}/evidence_submissions",
31
+ facade_klass: DocFox::EvidenceSubmission::Facade,
32
+ page: page,
33
+ per_page: per_page
34
+ )
35
+ end
36
+ end