mojfile-uploader-api-client 0.1.1 → 0.2

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: aae9dbfec4bdac54e4ba2f30d9b1b1976c479d75
4
- data.tar.gz: 2a1bdac42dfaa9c62ffb7ffc1f088ffe73211f5b
3
+ metadata.gz: 3066638f8cdc9294e76ca66e896be9e92310ee07
4
+ data.tar.gz: 65258501e71ef231634d86c79c56d5851de4ac20
5
5
  SHA512:
6
- metadata.gz: 8885d3f80dbcc410c732745f4020a9f4ad770f86d6a5b31fe22775301456571615d1bb57ba8f82a03411987ecd49db8d64f986d79f3bfd53b4f008c690e4db01
7
- data.tar.gz: e93853d922b4f659f6a6f206569bce11470fbcc76b4cfd5ca5281627fb4ef9a7ac87ab9fea2fada8bd97dc1c1a5763d2d5fb1a94d8635a41ddf6c2c099dfcef0
6
+ metadata.gz: 786bf3d8b142bab2de0ae53f30cdf10e314510b0ee3b2e71727206225ba9ac43984367615ad7ec0ca97aeab14b3bf6315e49c336c33e51b99ea9e45ced98259c
7
+ data.tar.gz: c3eab59fb289635295b6e8f458ad4ba3b0b16e933413d6812b87c39ee5d7e765705dc86572d9e3e563c3b6df1ca960f6d9135cf9161166a228cd7712435bf351
@@ -1 +1 @@
1
- 2.3.1
1
+ 2.4.0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mojfile-uploader-api-client (0.1.1)
4
+ mojfile-uploader-api-client (0.2)
5
5
  rest-client (~> 2.0.0)
6
6
 
7
7
  GEM
@@ -140,4 +140,4 @@ DEPENDENCIES
140
140
  rubocop (~> 0.41)
141
141
 
142
142
  BUNDLED WITH
143
- 1.13.6
143
+ 1.14.4
data/README.md CHANGED
@@ -20,6 +20,13 @@ end
20
20
 
21
21
  #### When a previous collection reference is known:
22
22
 
23
+ ```ruby
24
+ MojFileUploaderApiClient.add_file(title: 'test', filename: 'test.txt', data: 'bla bla bla', collection_ref: 'a45c556f-a628-41d3-8c29-351f84e63757')
25
+ => {:collection=>"a45c556f-a628-41d3-8c29-351f84e63757", :key=>"7c6aca2c-eb7a-4194-8166-9fd6ac82127b.test.txt"}
26
+ ```
27
+
28
+ Or you can use the `AddFile` client directly:
29
+
23
30
  ```ruby
24
31
  MojFileUploaderApiClient::AddFile.new(title: 'test', filename: 'test.txt', data: 'bla bla bla', collection_ref: 'a45c556f-a628-41d3-8c29-351f84e63757').call
25
32
 
@@ -30,6 +37,13 @@ MojFileUploaderApiClient::AddFile.new(title: 'test', filename: 'test.txt', data:
30
37
 
31
38
  #### No previous collection reference (will create a new one):
32
39
 
40
+ ```ruby
41
+ MojFileUploaderApiClient.add_file(title: 'test', filename: 'test.txt', data: 'bla bla bla')
42
+ => {:collection=>"741635f7-488a-49cc-a3f1-9ee38795e28e", :key=>"0543a21d-e884-4076-89be-41cc09b00da1.test.txt"}
43
+ ```
44
+
45
+ Or you can use the `AddFile` client directly:
46
+
33
47
  ```ruby
34
48
  MojFileUploaderApiClient::AddFile.new(title: 'test', filename: 'test.txt', data: 'bla bla bla').call
35
49
 
@@ -40,6 +54,13 @@ MojFileUploaderApiClient::AddFile.new(title: 'test', filename: 'test.txt', data:
40
54
 
41
55
  ### Delete a file
42
56
 
57
+ ```ruby
58
+ MojFileUploaderApiClient.delete_file(collection_ref: 'a45c556f-a628-41d3-8c29-351f84e63757', filename: 'test1.txt')
59
+ => RequestError
60
+ ```
61
+
62
+ Or you can use the `DeleteFile` client directly:
63
+
43
64
  ```ruby
44
65
  MojFileUploaderApiClient::DeleteFile.new(collection_ref: 'a45c556f-a628-41d3-8c29-351f84e63757', filename: 'test1.txt').call
45
66
  => #<MojFileUploaderApiClient::Response:0x007fe4e59c8098 @body={:body_parser_error=>"743: unexpected token at ''"}, @code=204>
@@ -47,12 +68,20 @@ MojFileUploaderApiClient::DeleteFile.new(collection_ref: 'a45c556f-a628-41d3-8c2
47
68
 
48
69
  ### List files
49
70
 
71
+ ```ruby
72
+ MojFileUploaderApiClient.list_files(collection_ref: 'a45c556f-a628-41d3-8c29-351f84e63757')
73
+ => {:collection=>"a45c556f-a628-41d3-8c29-351f84e63757",
74
+ :files=>[{:key=>"a45c556f-a628-41d3-8c29-351f84e63757/test1.txt", :title=>"test1.txt", :last_modified=>"2016-11-30T15:30:52.000Z"}]}
75
+ ```
76
+
77
+ Or you can use the `ListFiles` client directly:
78
+
50
79
  ```ruby
51
80
  MojFileUploaderApiClient::ListFiles.new(collection_ref: 'a45c556f-a628-41d3-8c29-351f84e63757').call
52
81
  => #<MojFileUploaderApiClient::Response:0x007fe4e5ac91e0
53
82
  @body=
54
83
  {:collection=>"a45c556f-a628-41d3-8c29-351f84e63757",
55
- :files=>[{:key=>"a45c556f-a628-41d3-8c29-351f84e63757/test1.txt", :title=>"test1.txt", :last_modified=>"2016-11-30T15:30:52.000Z"}]},
84
+ :files=>[{:key=>"a45c556f-a628-41d3-8c29-351f84e63757/test1.txt", :title=>"test1.txt", :last_modified=>"2016-11-30T15:30:52.000Z"}]}
56
85
  @code=200>
57
86
  ```
58
87
 
@@ -10,6 +10,35 @@ require 'mojfile_uploader_api_client/delete_file'
10
10
  require 'mojfile_uploader_api_client/list_files'
11
11
 
12
12
  module MojFileUploaderApiClient
13
+ INFECTED_FILE_RESPONSE_CODE = 400
14
+
13
15
  class Unavailable < StandardError; end
14
16
  class RequestError < StandardError; end
17
+ class InfectedFileError < StandardError; end
18
+
19
+ def self.add_file(params)
20
+ response = AddFile.new(params).call
21
+
22
+ if response.success?
23
+ response.body
24
+ elsif response.code.equal?(INFECTED_FILE_RESPONSE_CODE)
25
+ raise InfectedFileError
26
+ else
27
+ raise RequestError
28
+ end
29
+ end
30
+
31
+ def self.delete_file(params)
32
+ response = DeleteFile.new(params).call
33
+
34
+ raise RequestError unless response.success?
35
+ response.body
36
+ end
37
+
38
+ def self.list_files(params)
39
+ response = ListFiles.new(params).call
40
+
41
+ raise RequestError unless response.success?
42
+ response.body
43
+ end
15
44
  end
@@ -1,10 +1,12 @@
1
1
  module MojFileUploaderApiClient
2
2
  class Response
3
- attr_accessor :code, :body
3
+ class UnparsableResponseError < RuntimeError; end
4
+
5
+ attr_accessor :code
4
6
 
5
7
  def initialize(code:, body:)
6
- self.code = code
7
- self.body = parse_body(body)
8
+ @code = code
9
+ @raw_body = body
8
10
  end
9
11
 
10
12
  def success?
@@ -15,13 +17,17 @@ module MojFileUploaderApiClient
15
17
  !success?
16
18
  end
17
19
 
20
+ def body
21
+ @body ||= parse_body
22
+ end
23
+
18
24
  private
19
25
 
20
- def parse_body(body)
21
- return body if ['', nil].include?(body)
22
- JSON.parse(body, symbolize_names: true)
23
- rescue JSON::ParserError => ex
24
- {body_parser_error: ex.message}
26
+ def parse_body
27
+ return if @raw_body.nil? || @raw_body.empty?
28
+ JSON.parse(@raw_body, symbolize_names: true)
29
+ rescue JSON::ParserError
30
+ raise UnparsableResponseError
25
31
  end
26
32
  end
27
33
  end
@@ -1,3 +1,3 @@
1
1
  module MojFileUploaderApiClient
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2'
3
3
  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.1.1
4
+ version: '0.2'
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-01-11 00:00:00.000000000 Z
12
+ date: 2017-02-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -173,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
173
  version: '0'
174
174
  requirements: []
175
175
  rubyforge_project:
176
- rubygems_version: 2.5.1
176
+ rubygems_version: 2.6.8
177
177
  signing_key:
178
178
  specification_version: 4
179
179
  summary: API client for integration with the MOJ File Uploader