mojfile-uploader-api-client 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 +7 -0
- data/.gitignore +50 -0
- data/.rubocop.yml +1151 -0
- data/.ruby-version +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +143 -0
- data/LICENSE +21 -0
- data/README.md +94 -0
- data/Rakefile +30 -0
- data/bin/.gitkeep +0 -0
- data/circle.yml +7 -0
- data/lib/mojfile_uploader_api_client/add_file.rb +24 -0
- data/lib/mojfile_uploader_api_client/delete_file.rb +18 -0
- data/lib/mojfile_uploader_api_client/file_reference.rb +13 -0
- data/lib/mojfile_uploader_api_client/http_client.rb +66 -0
- data/lib/mojfile_uploader_api_client/list_files.rb +17 -0
- data/lib/mojfile_uploader_api_client/response.rb +27 -0
- data/lib/mojfile_uploader_api_client/status.rb +22 -0
- data/lib/mojfile_uploader_api_client/version.rb +3 -0
- data/lib/mojfile_uploader_api_client.rb +15 -0
- data/lib/tasks/mutant.rake +9 -0
- data/lib/tasks/rubocop.rake +6 -0
- data/mojfile_uploader_api_client.gemspec +26 -0
- metadata +180 -0
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.3.1
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
mojfile-uploader-api-client (0.1.0)
|
|
5
|
+
rest-client (~> 2.0.0)
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
abstract_type (0.0.7)
|
|
11
|
+
adamantium (0.2.0)
|
|
12
|
+
ice_nine (~> 0.11.0)
|
|
13
|
+
memoizable (~> 0.4.0)
|
|
14
|
+
anima (0.3.0)
|
|
15
|
+
abstract_type (~> 0.0.7)
|
|
16
|
+
adamantium (~> 0.2)
|
|
17
|
+
equalizer (~> 0.0.11)
|
|
18
|
+
ast (2.3.0)
|
|
19
|
+
byebug (9.0.6)
|
|
20
|
+
codeclimate-test-reporter (0.6.0)
|
|
21
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
|
22
|
+
coderay (1.1.1)
|
|
23
|
+
concord (0.1.5)
|
|
24
|
+
adamantium (~> 0.2.0)
|
|
25
|
+
equalizer (~> 0.0.9)
|
|
26
|
+
diff-lcs (1.2.5)
|
|
27
|
+
docile (1.1.5)
|
|
28
|
+
domain_name (0.5.20161021)
|
|
29
|
+
unf (>= 0.0.5, < 1.0.0)
|
|
30
|
+
equalizer (0.0.11)
|
|
31
|
+
http-cookie (1.0.3)
|
|
32
|
+
domain_name (~> 0.5)
|
|
33
|
+
ice_nine (0.11.2)
|
|
34
|
+
json (2.0.2)
|
|
35
|
+
memoizable (0.4.2)
|
|
36
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
|
37
|
+
method_source (0.8.2)
|
|
38
|
+
mime-types (3.1)
|
|
39
|
+
mime-types-data (~> 3.2015)
|
|
40
|
+
mime-types-data (3.2016.0521)
|
|
41
|
+
morpher (0.2.6)
|
|
42
|
+
abstract_type (~> 0.0.7)
|
|
43
|
+
adamantium (~> 0.2.0)
|
|
44
|
+
anima (~> 0.3.0)
|
|
45
|
+
ast (~> 2.2)
|
|
46
|
+
concord (~> 0.1.5)
|
|
47
|
+
equalizer (~> 0.0.9)
|
|
48
|
+
ice_nine (~> 0.11.0)
|
|
49
|
+
procto (~> 0.0.2)
|
|
50
|
+
mutant (0.8.12)
|
|
51
|
+
abstract_type (~> 0.0.7)
|
|
52
|
+
adamantium (~> 0.2.0)
|
|
53
|
+
anima (~> 0.3.0)
|
|
54
|
+
ast (~> 2.2)
|
|
55
|
+
concord (~> 0.1.5)
|
|
56
|
+
diff-lcs (~> 1.2)
|
|
57
|
+
equalizer (~> 0.0.9)
|
|
58
|
+
ice_nine (~> 0.11.1)
|
|
59
|
+
memoizable (~> 0.4.2)
|
|
60
|
+
morpher (~> 0.2.6)
|
|
61
|
+
parallel (~> 1.3)
|
|
62
|
+
parser (~> 2.3.1, >= 2.3.1.4)
|
|
63
|
+
procto (~> 0.0.2)
|
|
64
|
+
regexp_parser (~> 0.3.6)
|
|
65
|
+
unparser (~> 0.2.5)
|
|
66
|
+
mutant-rspec (0.8.11)
|
|
67
|
+
mutant (~> 0.8.11)
|
|
68
|
+
rspec-core (>= 3.4.0, < 3.6.0)
|
|
69
|
+
netrc (0.11.0)
|
|
70
|
+
parallel (1.10.0)
|
|
71
|
+
parser (2.3.2.0)
|
|
72
|
+
ast (~> 2.2)
|
|
73
|
+
powerpack (0.1.1)
|
|
74
|
+
procto (0.0.3)
|
|
75
|
+
pry (0.10.4)
|
|
76
|
+
coderay (~> 1.1.0)
|
|
77
|
+
method_source (~> 0.8.1)
|
|
78
|
+
slop (~> 3.4)
|
|
79
|
+
pry-byebug (3.4.1)
|
|
80
|
+
byebug (~> 9.0)
|
|
81
|
+
pry (~> 0.10)
|
|
82
|
+
rainbow (2.1.0)
|
|
83
|
+
rake (10.5.0)
|
|
84
|
+
regexp_parser (0.3.6)
|
|
85
|
+
rest-client (2.0.0)
|
|
86
|
+
http-cookie (>= 1.0.2, < 2.0)
|
|
87
|
+
mime-types (>= 1.16, < 4.0)
|
|
88
|
+
netrc (~> 0.8)
|
|
89
|
+
rspec (3.5.0)
|
|
90
|
+
rspec-core (~> 3.5.0)
|
|
91
|
+
rspec-expectations (~> 3.5.0)
|
|
92
|
+
rspec-mocks (~> 3.5.0)
|
|
93
|
+
rspec-core (3.5.4)
|
|
94
|
+
rspec-support (~> 3.5.0)
|
|
95
|
+
rspec-expectations (3.5.0)
|
|
96
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
97
|
+
rspec-support (~> 3.5.0)
|
|
98
|
+
rspec-mocks (3.5.0)
|
|
99
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
100
|
+
rspec-support (~> 3.5.0)
|
|
101
|
+
rspec-support (3.5.0)
|
|
102
|
+
rubocop (0.45.0)
|
|
103
|
+
parser (>= 2.3.1.1, < 3.0)
|
|
104
|
+
powerpack (~> 0.1)
|
|
105
|
+
rainbow (>= 1.99.1, < 3.0)
|
|
106
|
+
ruby-progressbar (~> 1.7)
|
|
107
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
|
108
|
+
ruby-progressbar (1.8.1)
|
|
109
|
+
simplecov (0.12.0)
|
|
110
|
+
docile (~> 1.1.0)
|
|
111
|
+
json (>= 1.8, < 3)
|
|
112
|
+
simplecov-html (~> 0.10.0)
|
|
113
|
+
simplecov-html (0.10.0)
|
|
114
|
+
slop (3.6.0)
|
|
115
|
+
thread_safe (0.3.5)
|
|
116
|
+
unf (0.1.4)
|
|
117
|
+
unf_ext
|
|
118
|
+
unf_ext (0.0.7.2)
|
|
119
|
+
unicode-display_width (1.1.1)
|
|
120
|
+
unparser (0.2.5)
|
|
121
|
+
abstract_type (~> 0.0.7)
|
|
122
|
+
adamantium (~> 0.2.0)
|
|
123
|
+
concord (~> 0.1.5)
|
|
124
|
+
diff-lcs (~> 1.2.5)
|
|
125
|
+
equalizer (~> 0.0.9)
|
|
126
|
+
parser (~> 2.3.0)
|
|
127
|
+
procto (~> 0.0.2)
|
|
128
|
+
|
|
129
|
+
PLATFORMS
|
|
130
|
+
ruby
|
|
131
|
+
|
|
132
|
+
DEPENDENCIES
|
|
133
|
+
bundler (~> 1.10)
|
|
134
|
+
codeclimate-test-reporter (~> 0.2)
|
|
135
|
+
mojfile-uploader-api-client!
|
|
136
|
+
mutant-rspec (~> 0.8)
|
|
137
|
+
pry-byebug (~> 3.4)
|
|
138
|
+
rake (~> 10.0)
|
|
139
|
+
rspec (~> 3.5)
|
|
140
|
+
rubocop (~> 0.41)
|
|
141
|
+
|
|
142
|
+
BUNDLED WITH
|
|
143
|
+
1.13.6
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 Ministry of Justice
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# mojfile-uploader-api-client
|
|
2
|
+
An API client for mojfile-uploader
|
|
3
|
+
|
|
4
|
+
## Configuration
|
|
5
|
+
|
|
6
|
+
In your project, create an initializer with the following:
|
|
7
|
+
|
|
8
|
+
```ruby
|
|
9
|
+
MojFileUploaderApiClient::HttpClient.configure do |client|
|
|
10
|
+
client.base_url = 'http://localhost:3003' # mandatory
|
|
11
|
+
client.options = {} # optional - supports :headers, :verify_ssl, :open_timeout, :read_timeout
|
|
12
|
+
end
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Operations
|
|
16
|
+
|
|
17
|
+
### Add a file
|
|
18
|
+
|
|
19
|
+
#### When a previous collection reference is known:
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
MojFileUploaderApiClient::AddFile.new(title: 'test', filename: 'test.txt', data: 'bla bla bla', collection_ref: 'a45c556f-a628-41d3-8c29-351f84e63757').call
|
|
23
|
+
|
|
24
|
+
=> #<MojFileUploaderApiClient::Response:0x007fe4e5c85ce0
|
|
25
|
+
@body={:collection=>"a45c556f-a628-41d3-8c29-351f84e63757", :key=>"7c6aca2c-eb7a-4194-8166-9fd6ac82127b.test.txt"},
|
|
26
|
+
@code=200>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
#### No previous collection reference (will create a new one):
|
|
30
|
+
|
|
31
|
+
```ruby
|
|
32
|
+
MojFileUploaderApiClient::AddFile.new(title: 'test', filename: 'test.txt', data: 'bla bla bla').call
|
|
33
|
+
|
|
34
|
+
=> #<MojFileUploaderApiClient::Response:0x007fe4e5b8cc58
|
|
35
|
+
@body={:collection=>"741635f7-488a-49cc-a3f1-9ee38795e28e", :key=>"0543a21d-e884-4076-89be-41cc09b00da1.test.txt"},
|
|
36
|
+
@code=200>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Delete a file
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
MojFileUploaderApiClient::DeleteFile.new(collection_ref: 'a45c556f-a628-41d3-8c29-351f84e63757', filename: 'test1.txt').call
|
|
43
|
+
=> #<MojFileUploaderApiClient::Response:0x007fe4e59c8098 @body={:body_parser_error=>"743: unexpected token at ''"}, @code=204>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### List files
|
|
47
|
+
|
|
48
|
+
```ruby
|
|
49
|
+
MojFileUploaderApiClient::ListFiles.new(collection_ref: 'a45c556f-a628-41d3-8c29-351f84e63757').call
|
|
50
|
+
=> #<MojFileUploaderApiClient::Response:0x007fe4e5ac91e0
|
|
51
|
+
@body=
|
|
52
|
+
{:collection=>"a45c556f-a628-41d3-8c29-351f84e63757",
|
|
53
|
+
:files=>[{:key=>"a45c556f-a628-41d3-8c29-351f84e63757/test1.txt", :title=>"test1.txt", :last_modified=>"2016-11-30T15:30:52.000Z"}]},
|
|
54
|
+
@code=200>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Contributing
|
|
58
|
+
|
|
59
|
+
Fork, then clone the repo:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
git clone git@github.com:your-username/mojfile-uploader-api-client.git
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Make sure the tests pass:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
bundle exec rake
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Make your change. Add specs for your change. Make the specs pass:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
bundle exec rake
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Push to your fork and [submit a pull request][pr].
|
|
78
|
+
|
|
79
|
+
[pr]: https://github.com/ministryofjustice/mojfile-uploader-api-client/compare
|
|
80
|
+
|
|
81
|
+
Some things that will increase the chance that your pull request is
|
|
82
|
+
accepted:
|
|
83
|
+
|
|
84
|
+
* Write specs.
|
|
85
|
+
* Make sure you don’t have any mutants (part of total test suite).
|
|
86
|
+
* Write a [good commit message][commit].
|
|
87
|
+
|
|
88
|
+
[commit]: https://github.com/alphagov/styleguides/blob/master/git.md
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
Released under the [MIT License](http://opensource.org/licenses/MIT).
|
|
93
|
+
Copyright (c) 2016 Ministry of Justice.
|
|
94
|
+
|
data/Rakefile
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# begin
|
|
2
|
+
# require 'bundler/setup'
|
|
3
|
+
# rescue LoadError
|
|
4
|
+
# puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
5
|
+
# end
|
|
6
|
+
|
|
7
|
+
require 'rdoc/task'
|
|
8
|
+
|
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
11
|
+
rdoc.title = 'MojFileUploaderApiClient'
|
|
12
|
+
rdoc.options << '--line-numbers'
|
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
require 'bundler/gem_tasks'
|
|
18
|
+
require 'rspec/core/rake_task'
|
|
19
|
+
|
|
20
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
21
|
+
|
|
22
|
+
# Get rid of rspec background noise.
|
|
23
|
+
task(:spec).clear
|
|
24
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
|
25
|
+
t.verbose = false
|
|
26
|
+
end
|
|
27
|
+
task default: :spec
|
|
28
|
+
|
|
29
|
+
load 'tasks/mutant.rake'
|
|
30
|
+
load 'tasks/rubocop.rake'
|
data/bin/.gitkeep
ADDED
|
File without changes
|
data/circle.yml
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module MojFileUploaderApiClient
|
|
2
|
+
class AddFile < MojFileUploaderApiClient::HttpClient
|
|
3
|
+
attr_accessor :collection_ref, :title, :filename, :data
|
|
4
|
+
|
|
5
|
+
def initialize(collection_ref: nil, title:, filename:, data:)
|
|
6
|
+
self.collection_ref = collection_ref
|
|
7
|
+
self.title = title
|
|
8
|
+
self.filename = filename
|
|
9
|
+
self.data = data
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def verb
|
|
13
|
+
:post
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def payload
|
|
17
|
+
{file_title: title, file_filename: filename, file_data: data}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def endpoint
|
|
21
|
+
File.join(collection_ref.to_s, 'new')
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module MojFileUploaderApiClient
|
|
2
|
+
class DeleteFile < MojFileUploaderApiClient::HttpClient
|
|
3
|
+
attr_accessor :collection_ref, :filename
|
|
4
|
+
|
|
5
|
+
def initialize(collection_ref:, filename:)
|
|
6
|
+
self.collection_ref = collection_ref
|
|
7
|
+
self.filename = filename
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def verb
|
|
11
|
+
:delete
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def endpoint
|
|
15
|
+
[collection_ref, filename].join('/')
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Note: Decide if go with building `file` objects or instead using the uploader API json response directly
|
|
2
|
+
#
|
|
3
|
+
module MojFileUploaderApiClient
|
|
4
|
+
class FileReference
|
|
5
|
+
attr_accessor :key, :title, :last_modified
|
|
6
|
+
|
|
7
|
+
def initialize(key:, title:, last_modified:)
|
|
8
|
+
self.key = key
|
|
9
|
+
self.title = title
|
|
10
|
+
self.last_modified = last_modified
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
module MojFileUploaderApiClient
|
|
2
|
+
class HttpClient
|
|
3
|
+
attr_accessor :response
|
|
4
|
+
|
|
5
|
+
DEFAULT_OPTIONS = {
|
|
6
|
+
headers: {'Content-Type' => 'application/json', 'Accept' => 'application/json'},
|
|
7
|
+
verify_ssl: false,
|
|
8
|
+
open_timeout: 5,
|
|
9
|
+
read_timeout: 15
|
|
10
|
+
}.freeze
|
|
11
|
+
|
|
12
|
+
class << self
|
|
13
|
+
attr_accessor :base_url, :options
|
|
14
|
+
|
|
15
|
+
def configure
|
|
16
|
+
yield(self)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def call
|
|
21
|
+
execute_request
|
|
22
|
+
response
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def endpoint
|
|
26
|
+
raise 'not implemented'
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def verb
|
|
30
|
+
raise 'not implemented'
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def payload; end
|
|
34
|
+
|
|
35
|
+
def payload?
|
|
36
|
+
!payload.nil?
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def options
|
|
40
|
+
DEFAULT_OPTIONS.merge(HttpClient.options || {})
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
def url
|
|
46
|
+
File.join(HttpClient.base_url, endpoint)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def request_details
|
|
50
|
+
{method: verb, url: url}.merge(options).tap do |args|
|
|
51
|
+
args.merge!(payload: payload.to_json) if payload?
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def execute_request
|
|
56
|
+
begin
|
|
57
|
+
res = RestClient::Request.execute(request_details)
|
|
58
|
+
code, body = res.code, res.body
|
|
59
|
+
rescue RestClient::Exception => ex
|
|
60
|
+
code, body = ex.http_code, ex.response
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
self.response = Response.new(code: code, body: body)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module MojFileUploaderApiClient
|
|
2
|
+
class ListFiles < MojFileUploaderApiClient::HttpClient
|
|
3
|
+
attr_accessor :collection_ref
|
|
4
|
+
|
|
5
|
+
def initialize(collection_ref:)
|
|
6
|
+
self.collection_ref = collection_ref
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def verb
|
|
10
|
+
:get
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def endpoint
|
|
14
|
+
collection_ref
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module MojFileUploaderApiClient
|
|
2
|
+
class Response
|
|
3
|
+
attr_accessor :code, :body
|
|
4
|
+
|
|
5
|
+
def initialize(code:, body:)
|
|
6
|
+
self.code = code
|
|
7
|
+
self.body = parse_body(body)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def success?
|
|
11
|
+
[200, 204].include?(code)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def error?
|
|
15
|
+
!success?
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
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}
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module MojFileUploaderApiClient
|
|
2
|
+
class Status < MojFileUploaderApiClient::HttpClient
|
|
3
|
+
|
|
4
|
+
def verb
|
|
5
|
+
:get
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def endpoint
|
|
9
|
+
'status'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def available?
|
|
13
|
+
response.success? && status.eql?('OK')
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def status
|
|
19
|
+
response.body&.fetch(:status)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
require 'rest-client'
|
|
3
|
+
require 'mojfile_uploader_api_client/version'
|
|
4
|
+
require 'mojfile_uploader_api_client/response'
|
|
5
|
+
require 'mojfile_uploader_api_client/http_client'
|
|
6
|
+
require 'mojfile_uploader_api_client/file_reference'
|
|
7
|
+
require 'mojfile_uploader_api_client/status'
|
|
8
|
+
require 'mojfile_uploader_api_client/add_file'
|
|
9
|
+
require 'mojfile_uploader_api_client/delete_file'
|
|
10
|
+
require 'mojfile_uploader_api_client/list_files'
|
|
11
|
+
|
|
12
|
+
module MojFileUploaderApiClient
|
|
13
|
+
class Unavailable < StandardError; end
|
|
14
|
+
class RequestError < StandardError; end
|
|
15
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
|
2
|
+
|
|
3
|
+
require 'mojfile_uploader_api_client/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'mojfile-uploader-api-client'
|
|
7
|
+
spec.version = MojFileUploaderApiClient::VERSION
|
|
8
|
+
spec.authors = ['Jesus Laiz', 'Tax Tribunals Fees']
|
|
9
|
+
spec.email = ['jesus.laiz@digital.justice.gov.uk', 'taxtribsfees@digital.justice.gov.uk']
|
|
10
|
+
|
|
11
|
+
spec.summary = 'API client for integration with the MOJ File Uploader'
|
|
12
|
+
spec.homepage = 'https://github.com/ministryofjustice/mojfile-uploader-api-client'
|
|
13
|
+
spec.licenses = 'MIT'
|
|
14
|
+
|
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
16
|
+
|
|
17
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
|
18
|
+
spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.2'
|
|
19
|
+
spec.add_development_dependency 'mutant-rspec', '~> 0.8'
|
|
20
|
+
spec.add_development_dependency 'pry-byebug', '~> 3.4'
|
|
21
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
22
|
+
spec.add_development_dependency 'rspec', '~> 3.5'
|
|
23
|
+
spec.add_development_dependency 'rubocop', '~> 0.41'
|
|
24
|
+
|
|
25
|
+
spec.add_dependency 'rest-client', '~> 2.0.0'
|
|
26
|
+
end
|