mojfile-uploader-api-client 0.4 → 0.5
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0198b271e429f4657e7a7d850e448b2b9b88b2a
|
4
|
+
data.tar.gz: 4a159a3c4c6c550a3d1bbd8b72ec73ccf4189383
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '015208cbdd25303db59d402d79efa0f4546ac5e4159e2738f8b9c12d79441866b8696e0b4f631b9ee322efed0a1e8c668cf7b4fc4e8061600bd4eadf76aafcdb'
|
7
|
+
data.tar.gz: 04fc4660751d8bc150af1d108a0d82e1d92e71db62cb05b5f28d87d8452f828da70154806a2b6790a0d7b14240f4086a13f71967296271ce8188d75ceaf048e7
|
data/.rubocop.yml
CHANGED
@@ -711,7 +711,7 @@ Style/LineEndConcatenation:
|
|
711
711
|
line end.
|
712
712
|
Enabled: false
|
713
713
|
|
714
|
-
Style/
|
714
|
+
Style/MethodCallWithoutArgsParentheses:
|
715
715
|
Description: 'Do not use parentheses for method calls with no arguments.'
|
716
716
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-args-no-parens'
|
717
717
|
Enabled: false
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mojfile-uploader-api-client (0.
|
4
|
+
mojfile-uploader-api-client (0.5)
|
5
5
|
rest-client (~> 2.0.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -79,7 +79,7 @@ GEM
|
|
79
79
|
pry-byebug (3.4.1)
|
80
80
|
byebug (~> 9.0)
|
81
81
|
pry (~> 0.10)
|
82
|
-
rainbow (2.1
|
82
|
+
rainbow (2.2.1)
|
83
83
|
rake (10.5.0)
|
84
84
|
regexp_parser (0.3.6)
|
85
85
|
rest-client (2.0.0)
|
@@ -99,8 +99,8 @@ GEM
|
|
99
99
|
diff-lcs (>= 1.2.0, < 2.0)
|
100
100
|
rspec-support (~> 3.5.0)
|
101
101
|
rspec-support (3.5.0)
|
102
|
-
rubocop (0.
|
103
|
-
parser (>= 2.3.
|
102
|
+
rubocop (0.47.1)
|
103
|
+
parser (>= 2.3.3.1, < 3.0)
|
104
104
|
powerpack (~> 0.1)
|
105
105
|
rainbow (>= 1.99.1, < 3.0)
|
106
106
|
ruby-progressbar (~> 1.7)
|
@@ -116,7 +116,7 @@ GEM
|
|
116
116
|
unf (0.1.4)
|
117
117
|
unf_ext
|
118
118
|
unf_ext (0.0.7.2)
|
119
|
-
unicode-display_width (1.1.
|
119
|
+
unicode-display_width (1.1.3)
|
120
120
|
unparser (0.2.5)
|
121
121
|
abstract_type (~> 0.0.7)
|
122
122
|
adamantium (~> 0.2.0)
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'rest-client'
|
3
3
|
require 'mojfile_uploader_api_client/version'
|
4
|
+
require 'mojfile_uploader_api_client/errors'
|
4
5
|
require 'mojfile_uploader_api_client/response'
|
5
6
|
require 'mojfile_uploader_api_client/http_client'
|
6
7
|
require 'mojfile_uploader_api_client/file_reference'
|
@@ -13,11 +14,6 @@ module MojFileUploaderApiClient
|
|
13
14
|
INFECTED_FILE_RESPONSE_CODE = 400
|
14
15
|
NOT_FOUND_RESPONSE_CODE = 404
|
15
16
|
|
16
|
-
class Unavailable < StandardError; end
|
17
|
-
class RequestError < StandardError; end
|
18
|
-
class InfectedFileError < StandardError; end
|
19
|
-
class NotFoundError < StandardError; end
|
20
|
-
|
21
17
|
def self.add_file(params)
|
22
18
|
response = AddFile.new(params).call
|
23
19
|
|
@@ -26,14 +22,14 @@ module MojFileUploaderApiClient
|
|
26
22
|
elsif response.code.equal?(INFECTED_FILE_RESPONSE_CODE)
|
27
23
|
raise InfectedFileError
|
28
24
|
else
|
29
|
-
raise RequestError
|
25
|
+
raise RequestError.new('Could not add file', response.code, response.body)
|
30
26
|
end
|
31
27
|
end
|
32
28
|
|
33
29
|
def self.delete_file(params)
|
34
30
|
response = DeleteFile.new(params).call
|
35
31
|
|
36
|
-
raise RequestError unless response.success?
|
32
|
+
raise RequestError.new('Could not delete file', response.code, response.body) unless response.success?
|
37
33
|
response.body
|
38
34
|
end
|
39
35
|
|
@@ -45,7 +41,7 @@ module MojFileUploaderApiClient
|
|
45
41
|
elsif response.code.equal?(NOT_FOUND_RESPONSE_CODE)
|
46
42
|
raise NotFoundError
|
47
43
|
else
|
48
|
-
raise RequestError
|
44
|
+
raise RequestError.new('Could not list files', response.code, response.body)
|
49
45
|
end
|
50
46
|
end
|
51
47
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module MojFileUploaderApiClient
|
2
|
+
class RequestError < StandardError
|
3
|
+
attr_reader :code, :body
|
4
|
+
|
5
|
+
def initialize(message, code, body)
|
6
|
+
super(message)
|
7
|
+
@code = code
|
8
|
+
@body = body
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class UnparsableResponseError < RuntimeError
|
13
|
+
attr_reader :raw_body
|
14
|
+
|
15
|
+
def initialize(message, raw_body)
|
16
|
+
super(message)
|
17
|
+
@raw_body = raw_body
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class InfectedFileError < StandardError; end
|
22
|
+
class NotFoundError < StandardError; end
|
23
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
module MojFileUploaderApiClient
|
2
2
|
class Response
|
3
|
-
|
4
|
-
|
5
|
-
attr_accessor :code
|
3
|
+
attr_accessor :code, :raw_body
|
6
4
|
|
7
5
|
def initialize(code:, body:)
|
8
6
|
@code = code
|
@@ -24,10 +22,10 @@ module MojFileUploaderApiClient
|
|
24
22
|
private
|
25
23
|
|
26
24
|
def parse_body
|
27
|
-
return if
|
28
|
-
JSON.parse(
|
25
|
+
return if raw_body.nil? || raw_body.empty?
|
26
|
+
JSON.parse(raw_body, symbolize_names: true)
|
29
27
|
rescue JSON::ParserError
|
30
|
-
raise UnparsableResponseError
|
28
|
+
raise UnparsableResponseError.new('Invalid JSON response', raw_body)
|
31
29
|
end
|
32
30
|
end
|
33
31
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mojfile-uploader-api-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.5'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jesus Laiz
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-03-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -144,6 +144,7 @@ files:
|
|
144
144
|
- lib/mojfile_uploader_api_client.rb
|
145
145
|
- lib/mojfile_uploader_api_client/add_file.rb
|
146
146
|
- lib/mojfile_uploader_api_client/delete_file.rb
|
147
|
+
- lib/mojfile_uploader_api_client/errors.rb
|
147
148
|
- lib/mojfile_uploader_api_client/file_reference.rb
|
148
149
|
- lib/mojfile_uploader_api_client/http_client.rb
|
149
150
|
- lib/mojfile_uploader_api_client/list_files.rb
|