super_parser 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 176c6ac3b2f40ff38ce140c0039214ea60be539551d4cd660157d0aa66e851aa
4
- data.tar.gz: 4621470b5e42eb7cfc0f1ac242a6816d3f7f3df6e6a18ac53ea522539ba29bac
3
+ metadata.gz: b5e0636d567f2013c3794af9fff80d0b8a25ad9ca16638b9e771a81527751510
4
+ data.tar.gz: d833ac00a7db001f0758527e3259634022809b6b6978026a1cf8e65d963c1cb5
5
5
  SHA512:
6
- metadata.gz: f83cf590b3c663f743771909b33b9f0abea5639d77b09e783a6b4049d5ac1eac7134b36feeabfa792d0c6bd97f9328d892fb5daa95e7fcd907bd71539fe30661
7
- data.tar.gz: f0a04af71ee6edea83bdb1795fa2aa89b109595bbeca695542f8a93cfd0a34c08f62d461c12b645e1eb3742d8707f9ca6083d248b3d230fbcbd45fd521acfa0b
6
+ metadata.gz: da120f9282c2879e70c9f6886c59d32263f5e3cde9c1d32d94b001aba6db11e84ee5647d458c5ad7a8ecdb94c697656026bc19b8d27e3a936d610877c5767d49
7
+ data.tar.gz: f9e807599f26e67938f46c899618673a4af0f83815d41740d85612dc57fd64d32f4a01761ab87543dc8baa52a6c4525c7c8451280a1235aa8636f1f49acb89f3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- super_parser (0.1.1)
4
+ super_parser (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -5,23 +5,27 @@ require_relative 'client_error'
5
5
 
6
6
  module SuperParser # :nodoc:
7
7
  class Client
8
- def parse(file)
8
+ def parse(filepath)
9
+ puts "Parsing #{filepath}..."
10
+
9
11
  uri = URI('https://api.superparser.com/parse')
10
12
  request = Net::HTTP::Post.new(uri)
11
13
  request['X-API-KEY'] = SuperParser.api_key
12
14
  request['accept'] = 'application/json'
13
15
 
14
- form_data = [['file_name', file]]
16
+ File.open(filepath) do |file|
17
+ form_data = [['file_name', file]]
15
18
 
16
- request.set_form form_data, 'multipart/form-data'
17
- response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
18
- http.request(request)
19
- end
19
+ request.set_form form_data, 'multipart/form-data'
20
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
21
+ http.request(request)
22
+ end
20
23
 
21
- if response.code != 200
22
- SuperParser::ClientError.new response
23
- else
24
- SuperParser::Response.new(response.body)
24
+ if response.code != '200'
25
+ SuperParser::ClientError.new response
26
+ else
27
+ SuperParser::Response.new(response.body)
28
+ end
25
29
  end
26
30
  end
27
31
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  module SuperParser # :nodoc:
4
4
  class ClientError < StandardError
5
- attr_reader :status
5
+ attr_reader :code
6
6
 
7
7
  def initialize(response)
8
8
  error = JSON.parse response.body
9
- @status = response.status
9
+ @code = response.code
10
10
  super(error['message'])
11
11
  end
12
12
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SuperParser
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Watling