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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/super_parser/client.rb +14 -10
- data/lib/super_parser/client_error.rb +2 -2
- data/lib/super_parser/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5e0636d567f2013c3794af9fff80d0b8a25ad9ca16638b9e771a81527751510
|
4
|
+
data.tar.gz: d833ac00a7db001f0758527e3259634022809b6b6978026a1cf8e65d963c1cb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da120f9282c2879e70c9f6886c59d32263f5e3cde9c1d32d94b001aba6db11e84ee5647d458c5ad7a8ecdb94c697656026bc19b8d27e3a936d610877c5767d49
|
7
|
+
data.tar.gz: f9e807599f26e67938f46c899618673a4af0f83815d41740d85612dc57fd64d32f4a01761ab87543dc8baa52a6c4525c7c8451280a1235aa8636f1f49acb89f3
|
data/Gemfile.lock
CHANGED
data/lib/super_parser/client.rb
CHANGED
@@ -5,23 +5,27 @@ require_relative 'client_error'
|
|
5
5
|
|
6
6
|
module SuperParser # :nodoc:
|
7
7
|
class Client
|
8
|
-
def parse(
|
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
|
-
|
16
|
+
File.open(filepath) do |file|
|
17
|
+
form_data = [['file_name', file]]
|
15
18
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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 :
|
5
|
+
attr_reader :code
|
6
6
|
|
7
7
|
def initialize(response)
|
8
8
|
error = JSON.parse response.body
|
9
|
-
@
|
9
|
+
@code = response.code
|
10
10
|
super(error['message'])
|
11
11
|
end
|
12
12
|
end
|
data/lib/super_parser/version.rb
CHANGED