veryfi 0.0.0 → 0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71ed0e3845f85312d16f9821240b9e04bb86bbeb0637a25970251543472d9edc
4
- data.tar.gz: 5daffbc243cc62df5bfbb4d18d72a5741850ddc59be6ba970f3f2f098db03f56
3
+ metadata.gz: 972fb13315f5c1012a72fbfe8d2c9647c6bf84cd4f5647df3d520d28aed07e28
4
+ data.tar.gz: a61e364851843f93804116308577155722ec30b6366e946eb4057025a4cc5b4d
5
5
  SHA512:
6
- metadata.gz: ee64c026cd35bde32a2d116c5d2bfc9ee5e3581b3d096540b3c98688e6e94e161b2c7cf7cb342e862de7785dcb311864822e7563cebf4f6b0114535da2248d32
7
- data.tar.gz: fe14f1092b352c8b20a64fc61d92f5c450d9189abeeb0d325ab1acf1069732fb1a1d34eb6bb12ed54536eef1c1dd7eeec0922c13dcae8d09d8939b6fe93375d3
6
+ metadata.gz: 397640a0588d132fcd069665a32252653f57518fbc55d7e49c520ad61bede0a3f19c56594e3c5f33df9cd5ac313f0eaf16c540a60f26a993b7f660eba2f1adb2
7
+ data.tar.gz: 15defaabd5b76bdc06ad95eb20c6336d26736a986e8c6a4d136f46a6406076aa49a9d2ed278f805d415db8482a8697bdfe0b72e8636216bb31e784265c242901
data/.rubocop.yml CHANGED
@@ -60,6 +60,24 @@ Metrics/BlockLength:
60
60
  Naming/MemoizedInstanceVariableName:
61
61
  EnforcedStyleForLeadingUnderscores: required
62
62
 
63
+ RSpec/AnyInstance:
64
+ Enabled: false
65
+
66
+ RSpec/ExampleLength:
67
+ Max: 10
68
+
69
+ RSpec/DescribeClass:
70
+ Enabled: false
71
+
72
+ RSpec/MultipleExpectations:
73
+ Max: 5
74
+
75
+ RSpec/SharedExamples:
76
+ Enabled: false
77
+
78
+ Style/GuardClause:
79
+ Enabled: false
80
+
63
81
  Style/HashEachMethods:
64
82
  Enabled: true
65
83
 
data/Gemfile.lock CHANGED
@@ -92,17 +92,17 @@ PLATFORMS
92
92
  ruby
93
93
 
94
94
  DEPENDENCIES
95
- bundler
96
- bundler-audit
97
- pry
98
- rake
99
- rspec
100
- rspec-its
101
- rubocop
102
- rubocop-rspec
103
- vcr
95
+ bundler (~> 1.17)
96
+ bundler-audit (~> 0.6)
97
+ pry (~> 0.14)
98
+ rake (~> 13.0)
99
+ rspec (~> 3.9)
100
+ rspec-its (~> 1.3)
101
+ rubocop (~> 0.82)
102
+ rubocop-rspec (~> 1.38)
103
+ vcr (~> 6.0)
104
104
  veryfi!
105
- webmock
105
+ webmock (~> 3.14)
106
106
 
107
107
  BUNDLED WITH
108
108
  1.17.2
data/README.md CHANGED
@@ -11,8 +11,8 @@
11
11
  - [Obtaining Client ID and user keys](#obtaining-client-id-and-user-keys)
12
12
  - [Ruby API Client Library](#ruby-api-client-library)
13
13
  - [Extracting Data](#extracting-data)
14
- - [Response](#response)
15
- - [Updating a document](#updating-a-document)
14
+ - [Document Response Example](#document-response-example)
15
+ - [Other methods](#other-methods)
16
16
  - [Need help?](#need-help)
17
17
  - [Learn more at our blog](#learn-more-at-our-blog)
18
18
  - [Tutorial Video](#tutorial-video)
@@ -31,7 +31,7 @@ gem install veryfi
31
31
 
32
32
  Or add to your Gemfile:
33
33
  ```ruby
34
- gem 'veryfi'
34
+ gem 'veryfi', '>= 0.1.0'
35
35
  ```
36
36
 
37
37
  ## Getting Started
@@ -57,15 +57,26 @@ veryfi_client = Veryfi::Client.new(
57
57
  username: 'your_username',
58
58
  api_key: 'your_password'
59
59
  )
60
-
61
- categories = ['Grocery', 'Utilities', 'Travel'];
62
- file_path = './test/receipt.png';
63
60
  ```
64
61
 
65
62
  This submits a document for processing (3-5 seconds for a response)
66
63
 
67
64
  ```ruby
68
- response = veryfi_client.process_document(file_path, categories)
65
+ params = {
66
+ file_path: './test/receipt.jpg',
67
+ auto_delete: 1,
68
+ boost_mode: 1,
69
+ async: 1,
70
+ external_id: '123456789',
71
+ max_pages_to_process: 10,
72
+ tags: ['tag1'],
73
+ categories: [
74
+ 'Advertising & Marketing',
75
+ 'Automotive'
76
+ ]
77
+ }
78
+
79
+ response = veryfi_client.document.process(params)
69
80
 
70
81
  puts response
71
82
  ```
@@ -73,12 +84,26 @@ puts response
73
84
  ...or with a URL
74
85
 
75
86
  ```ruby
76
- response = veryfi_client.process_document_url(url, external_id)
87
+ params = {
88
+ file_url: "https://raw.githubusercontent.com/veryfi/veryfi-python/master/tests/assets/receipt_public.jpg",
89
+ auto_delete: 1,
90
+ boost_mode: 1,
91
+ async: 1,
92
+ external_id: "123456789",
93
+ max_pages_to_process: 10,
94
+ tags: ["tag1"],
95
+ categories: [
96
+ "Advertising & Marketing",
97
+ "Automotive"
98
+ ]
99
+ }
100
+
101
+ response = veryfi_client.document.process_url(params)
77
102
 
78
103
  puts response
79
104
  ```
80
105
 
81
- ### Response
106
+ ### Document Response Example
82
107
 
83
108
  ```json
84
109
  {
@@ -215,9 +240,50 @@ puts response
215
240
  }
216
241
  ```
217
242
 
218
- ### Updating a document
243
+ ### Other methods
219
244
 
220
245
  ```ruby
246
+ # Update document
247
+ veryfi_client.document.update(document_id, params)
248
+
249
+ # Delete document by ID
250
+ veryfi_client.document.delete(document_id)
251
+
252
+ # Get document by ID
253
+ veryfi_client.document.get(document_id)
254
+
255
+ # List all documents
256
+ veryfi_client.document.all
257
+
258
+ # Get document line items
259
+ veryfi_client.line_items.all(document_id)
260
+
261
+ # Get line item by document id and line item id
262
+ veryfi_client.line_items.get(document_id, id)
263
+
264
+ # Create/update/delete document line item
265
+ veryfi_client.line_items.create(document_id, params)
266
+ veryfi_client.line_items.update(document_id, params)
267
+ veryfi_client.line_items.delete(document_id, params)
268
+
269
+ # Tags
270
+ # List all tags
271
+ veryfi_client.tag.all
272
+
273
+ # Delete a tag by ID
274
+ veryfi_client.tag.delete(id)
275
+
276
+ # List all document tags
277
+ veryfi_client.document_tag.all(document_id)
278
+
279
+ # Add tag to document
280
+ veryfi_client.document_tag.add(document_id, name: "tag_name")
281
+
282
+ # Delete tag by document id and tag id
283
+ veryfi_client.document_tag.delete(document_id, id)
284
+
285
+ # Delete all document tags
286
+ veryfi_client.document_tag.delete_all(document_id)
221
287
  ```
222
288
 
223
289
  ## Need help?
@@ -225,7 +291,6 @@ puts response
225
291
  If you run into any issue or need help installing or using the library, please contact support@veryfi.com.
226
292
 
227
293
  If you found a bug in this library or would like new features added, then open an issue or pull requests against this repo!
228
-
229
294
  ### [Learn more at our blog](https://www.veryfi.com/ruby/)
230
295
 
231
296
  ## Tutorial Video
@@ -1,8 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "Base64"
4
+
3
5
  module Veryfi
4
6
  module Api
5
7
  class Document
8
+ CATEGORIES = [
9
+ "Advertising & Marketing",
10
+ "Automotive",
11
+ "Bank Charges & Fees",
12
+ "Legal & Professional Services",
13
+ "Insurance",
14
+ "Meals & Entertainment",
15
+ "Office Supplies & Software",
16
+ "Taxes & Licenses",
17
+ "Travel",
18
+ "Rent & Lease",
19
+ "Repairs & Maintenance",
20
+ "Payroll",
21
+ "Utilities",
22
+ "Job Supplies",
23
+ "Grocery"
24
+ ].freeze
25
+
6
26
  attr_reader :request
7
27
 
8
28
  def initialize(request)
@@ -12,12 +32,51 @@ module Veryfi
12
32
  def all(params = {})
13
33
  response = request.get("/partner/documents/", params)
14
34
 
15
- Array(response)
35
+ response.is_a?(Hash) ? [response] : response
36
+ end
37
+
38
+ def process(raw_params)
39
+ params = setup_create_params(raw_params)
40
+
41
+ file_content = File.read(params[:file_path])
42
+ file_name = File.basename(params[:file_path], ".*")
43
+ file_data = Base64.encode64(file_content).gsub("\n", "")
44
+
45
+ payload = params.reject { |k| k == :file_path }.merge(
46
+ file_name: file_name,
47
+ file_data: file_data
48
+ )
49
+
50
+ request.post("/partner/documents/", payload)
51
+ end
52
+
53
+ def process_url(raw_params)
54
+ params = setup_create_params(raw_params)
55
+
56
+ request.post("/partner/documents/", params)
16
57
  end
17
58
 
18
59
  def get(id, params = {})
19
60
  request.get("/partner/documents/#{id}", params)
20
61
  end
62
+
63
+ def update(id, params)
64
+ request.put("/partner/documents/#{id}", params)
65
+ end
66
+
67
+ def delete(id)
68
+ request.delete("/partner/documents/#{id}")
69
+ end
70
+
71
+ private
72
+
73
+ def setup_create_params(raw_params)
74
+ params = raw_params.transform_keys(&:to_sym)
75
+
76
+ params[:categories] = CATEGORIES if params[:categories].to_a.empty?
77
+
78
+ params
79
+ end
21
80
  end
22
81
  end
23
82
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Veryfi
4
+ module Api
5
+ class DocumentTag
6
+ attr_reader :request
7
+
8
+ def initialize(request)
9
+ @request = request
10
+ end
11
+
12
+ def all(document_id, params = {})
13
+ response = request.get("/partner/documents/#{document_id}/tags/", params)
14
+
15
+ response["tags"]
16
+ end
17
+
18
+ def add(document_id, params)
19
+ request.put("/partner/documents/#{document_id}/tags/", params)
20
+ end
21
+
22
+ def delete_all(document_id)
23
+ request.delete("/partner/documents/#{document_id}/tags/")
24
+ end
25
+
26
+ def delete(document_id, id)
27
+ request.delete("/partner/documents/#{document_id}/tags/#{id}")
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Veryfi
4
+ module Api
5
+ class LineItem
6
+ attr_reader :request
7
+
8
+ def initialize(request)
9
+ @request = request
10
+ end
11
+
12
+ def all(document_id, params = {})
13
+ response = request.get("/partner/documents/#{document_id}/line-items/", params)
14
+
15
+ response["line_items"]
16
+ end
17
+
18
+ def create(document_id, params)
19
+ request.post("/partner/documents/#{document_id}/line-items/", params)
20
+ end
21
+
22
+ def get(document_id, id, params = {})
23
+ request.get("/partner/documents/#{document_id}/line-items/#{id}", params)
24
+ end
25
+
26
+ def update(document_id, id, params)
27
+ request.put("/partner/documents/#{document_id}/line-items/#{id}", params)
28
+ end
29
+
30
+ def delete(document_id, id)
31
+ request.delete("/partner/documents/#{document_id}/line-items/#{id}")
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Veryfi
4
+ module Api
5
+ class Tag
6
+ attr_reader :request
7
+
8
+ def initialize(request)
9
+ @request = request
10
+ end
11
+
12
+ def all(params = {})
13
+ response = request.get("/partner/tags/", params)
14
+
15
+ response["tags"]
16
+ end
17
+
18
+ def delete(id)
19
+ request.delete("/partner/tags/#{id}")
20
+ end
21
+ end
22
+ end
23
+ end
data/lib/veryfi/client.rb CHANGED
@@ -2,24 +2,6 @@
2
2
 
3
3
  module Veryfi
4
4
  class Client
5
- CATEGORIES = [
6
- "Advertising & Marketing",
7
- "Automotive",
8
- "Bank Charges & Fees",
9
- "Legal & Professional Services",
10
- "Insurance",
11
- "Meals & Entertainment",
12
- "Office Supplies & Software",
13
- "Taxes & Licenses",
14
- "Travel",
15
- "Rent & Lease",
16
- "Repairs & Maintenance",
17
- "Payroll",
18
- "Utilities",
19
- "Job Supplies",
20
- "Grocery"
21
- ].freeze
22
-
23
5
  attr_reader :request
24
6
 
25
7
  def initialize(
@@ -29,7 +11,7 @@ module Veryfi
29
11
  api_key:,
30
12
  base_url: "https://api.veryfi.com/api/",
31
13
  api_version: "v7",
32
- timeout: 120
14
+ timeout: 20
33
15
  )
34
16
  @request = Veryfi::Request.new(client_id, client_secret, username, api_key, base_url, api_version, timeout)
35
17
  end
@@ -38,6 +20,18 @@ module Veryfi
38
20
  @_document ||= Veryfi::Api::Document.new(request)
39
21
  end
40
22
 
23
+ def line_item
24
+ @_line_item ||= Veryfi::Api::LineItem.new(request)
25
+ end
26
+
27
+ def tag
28
+ @_tag ||= Veryfi::Api::Tag.new(request)
29
+ end
30
+
31
+ def document_tag
32
+ @_document_tag ||= Veryfi::Api::DocumentTag.new(request)
33
+ end
34
+
41
35
  def api_url
42
36
  request.api_url
43
37
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Veryfi
4
+ class Error
5
+ def self.from_response(response)
6
+ case response.status
7
+ when 400 then BadRequest
8
+ when 401 then UnauthorizedAccessToken
9
+ when 405 then UnexpectedHTTPMethod
10
+ when 409 then AccessLimitReached
11
+ else InternalError
12
+ end
13
+ end
14
+
15
+ class BadRequest < StandardError
16
+ def to_s
17
+ "Bad Request"
18
+ end
19
+ end
20
+
21
+ class UnauthorizedAccessToken < StandardError
22
+ def to_s
23
+ "Unauthorized Access Token"
24
+ end
25
+ end
26
+
27
+ class UnexpectedHTTPMethod < StandardError
28
+ def to_s
29
+ "Unexpected HTTP Method"
30
+ end
31
+ end
32
+
33
+ class AccessLimitReached < StandardError
34
+ def to_s
35
+ "Access Limit Reached"
36
+ end
37
+ end
38
+
39
+ class InternalError < StandardError
40
+ def to_s
41
+ "Internal Server Error"
42
+ end
43
+ end
44
+ end
45
+ end
@@ -8,6 +8,8 @@ module Veryfi
8
8
  class Request
9
9
  attr_reader :client_id, :client_secret, :username, :api_key, :base_url, :api_version, :timeout
10
10
 
11
+ VERBS_WITH_BODIES = %i[post put].freeze
12
+
11
13
  def initialize(
12
14
  client_id,
13
15
  client_secret,
@@ -26,11 +28,20 @@ module Veryfi
26
28
  @timeout = timeout
27
29
  end
28
30
 
29
- def get(path, params)
30
- url = [api_url, path].join
31
- headers = generate_headers(params)
32
- response = Faraday.get(url, params, headers)
33
- JSON.parse(response.body)
31
+ def get(path, params = {})
32
+ make_request(:get, path, params)
33
+ end
34
+
35
+ def put(path, params)
36
+ make_request(:put, path, params)
37
+ end
38
+
39
+ def post(path, params)
40
+ make_request(:post, path, params)
41
+ end
42
+
43
+ def delete(path)
44
+ make_request(:delete, path)
34
45
  end
35
46
 
36
47
  def api_url
@@ -39,6 +50,32 @@ module Veryfi
39
50
 
40
51
  private
41
52
 
53
+ def make_request(http_verb, path, params = {})
54
+ url = [api_url, path].join
55
+ body = generate_body(http_verb, params)
56
+ headers = generate_headers(params)
57
+
58
+ response = conn.public_send(http_verb, url, body, headers)
59
+
60
+ if response.success?
61
+ process_response(http_verb, response)
62
+ else
63
+ raise Veryfi::Error.from_response(response)
64
+ end
65
+ end
66
+
67
+ def conn
68
+ @_conn ||= Faraday.new do |conn|
69
+ conn.options.timeout = timeout
70
+ end
71
+ end
72
+
73
+ def generate_body(http_verb, params)
74
+ return params unless VERBS_WITH_BODIES.include?(http_verb)
75
+
76
+ params.to_json
77
+ end
78
+
42
79
  def generate_headers(params = {})
43
80
  return default_headers if client_secret.nil?
44
81
 
@@ -64,5 +101,11 @@ module Veryfi
64
101
  def generate_signature(params, timestamp)
65
102
  Veryfi::Signature.new(client_secret, params, timestamp).to_base64
66
103
  end
104
+
105
+ def process_response(_http_verb, response)
106
+ # return response if http_verb == :delete
107
+
108
+ JSON.parse(response.body)
109
+ end
67
110
  end
68
111
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Veryfi
4
- VERSION = "0.0.0"
4
+ VERSION = "0.1.0"
5
5
  end
data/lib/veryfi.rb CHANGED
@@ -4,9 +4,13 @@ module Veryfi
4
4
  autoload :VERSION, "veryfi/version"
5
5
  autoload :Signature, "veryfi/signature"
6
6
  autoload :Request, "veryfi/request"
7
+ autoload :Error, "veryfi/error"
7
8
 
8
9
  module Api
9
10
  autoload :Document, "veryfi/api/document"
11
+ autoload :LineItem, "veryfi/api/line_item"
12
+ autoload :Tag, "veryfi/api/tag"
13
+ autoload :DocumentTag, "veryfi/api/document_tag"
10
14
  end
11
15
 
12
16
  autoload :Client, "veryfi/client"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: veryfi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Veryfi
@@ -205,7 +205,11 @@ files:
205
205
  - lib/.keep
206
206
  - lib/veryfi.rb
207
207
  - lib/veryfi/api/document.rb
208
+ - lib/veryfi/api/document_tag.rb
209
+ - lib/veryfi/api/line_item.rb
210
+ - lib/veryfi/api/tag.rb
208
211
  - lib/veryfi/client.rb
212
+ - lib/veryfi/error.rb
209
213
  - lib/veryfi/request.rb
210
214
  - lib/veryfi/signature.rb
211
215
  - lib/veryfi/version.rb