bonsai_client 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/{.gitlab-ci-tempalte.yml → .gitlab-ci.yml} +1 -1
- data/.yardopts +4 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +3 -0
- data/README.md +21 -10
- data/Rakefile +10 -10
- data/bonsai_client.gemspec +2 -1
- data/lib/bonsai_client/client.rb +31 -0
- data/lib/bonsai_client/version.rb +1 -1
- data/lib/bonsai_client.rb +18 -5
- data/test-data/sample.jpg +0 -0
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5cba822dab0323ad666691294efcea55e72cd543
|
4
|
+
data.tar.gz: e44e02ab043734bd4f3d37c196d6934c580fc61a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cac296df7bad1cea1cc1b4ca950f2c255d8306f32b951088dc80b98b09ec874bc630e4744d2a6a1235e61f21942bfbd2b2b44bf672e956468bf4fa8b6570855d
|
7
|
+
data.tar.gz: 14bcc818aa9c8d25836067355e42f5c569cb2f272c143ca61cf49ed58688574f188e950fde9c2eec3fa05230ccf5a5e7ebaec489c8d385d2f02e3d71207fe2c5
|
data/.gitignore
CHANGED
data/.yardopts
ADDED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -16,6 +16,8 @@ gem install bonsai_client
|
|
16
16
|
|
17
17
|
## Usage in shell
|
18
18
|
|
19
|
+
Upload a file:
|
20
|
+
|
19
21
|
```bash
|
20
22
|
bonsai_client upload --url="http://bonsai-server.com" --path="/path/to/file"
|
21
23
|
```
|
@@ -26,16 +28,16 @@ bonsai_client upload --url="http://bonsai-server.com" --path="/path/to/file"
|
|
26
28
|
# Require Bonsai Client gem.
|
27
29
|
require 'bonsai-client'
|
28
30
|
|
29
|
-
#
|
31
|
+
# Create a new instance of Bonsai client:
|
30
32
|
bonsai = BonsaiClient.new(url: 'http://bonsai-server.com')
|
31
33
|
|
32
34
|
# Upload a file to a Bonsai server:
|
33
|
-
|
35
|
+
response = bonsai.upload(path: '/path/to/my-file')
|
34
36
|
|
35
37
|
# URL for a specific file in Bonsai sever:
|
36
|
-
src1 = bonsai.thumbnail_url(checksum:
|
37
|
-
src2 = bonsai.thumbnail_url(name: '
|
38
|
-
src3 = bonsai.thumbnail_url(checksum:
|
38
|
+
src1 = bonsai.thumbnail_url(checksum: response[:data][:file_checksum])
|
39
|
+
src2 = bonsai.thumbnail_url(name: 'my-file')
|
40
|
+
src3 = bonsai.thumbnail_url(checksum: response[:data][:file_checksum]), size: :medium)
|
39
41
|
```
|
40
42
|
|
41
43
|
## Development
|
@@ -43,35 +45,44 @@ src3 = bonsai.thumbnail_url(checksum: 'AF1...', size: :medium) # http://bonsai-s
|
|
43
45
|
### Test
|
44
46
|
|
45
47
|
```bash
|
46
|
-
bundle exec rake test
|
48
|
+
BONSAI_SERVER_URL=https://xxx.yyy BONSAI_CLIENT_ID=zzz bundle exec rake test
|
49
|
+
BONSAI_SERVER_URL=https://xxx.yyy BONSAI_CLIENT_ID=zzz bundle exec rake test TEST=test/upload_file_test.rb
|
47
50
|
```
|
48
51
|
|
49
52
|
### Rake tasks
|
50
53
|
|
51
|
-
|
54
|
+
Create a new version:
|
52
55
|
|
53
56
|
```bash
|
54
57
|
rake release
|
55
58
|
```
|
56
59
|
|
57
|
-
|
60
|
+
Push commits to git repositories (GitLab and GitHub)
|
58
61
|
|
59
62
|
```bash
|
60
63
|
rake push
|
61
64
|
```
|
62
65
|
|
63
|
-
|
66
|
+
Publish the current gem version to Rubygems:
|
64
67
|
|
65
68
|
```bash
|
66
69
|
rake push
|
67
70
|
```
|
68
71
|
|
69
|
-
|
72
|
+
Show current gem version:
|
70
73
|
|
71
74
|
```bash
|
72
75
|
rake version
|
73
76
|
```
|
74
77
|
|
78
|
+
### Documentation
|
79
|
+
|
80
|
+
Create documentation:
|
81
|
+
|
82
|
+
```bash
|
83
|
+
yardoc
|
84
|
+
```
|
85
|
+
|
75
86
|
|
76
87
|
## License
|
77
88
|
|
data/Rakefile
CHANGED
@@ -70,6 +70,16 @@ end
|
|
70
70
|
|
71
71
|
task :default => :test
|
72
72
|
|
73
|
+
desc "Push code to the remote respositories"
|
74
|
+
task :push do
|
75
|
+
show_text ">> Pushing code to GitLab y GitHub"
|
76
|
+
puts ""
|
77
|
+
sh "git push origin master"
|
78
|
+
puts ""
|
79
|
+
sh "git push github master"
|
80
|
+
puts ""
|
81
|
+
end
|
82
|
+
|
73
83
|
desc "Release #{gem_file} (only repository, not RubyGems)"
|
74
84
|
task :release => :build do
|
75
85
|
show_text ">> Releasing #{gem_file}"
|
@@ -97,16 +107,6 @@ task :release => :build do
|
|
97
107
|
show_release
|
98
108
|
end
|
99
109
|
|
100
|
-
desc "Push code to the remote respositories"
|
101
|
-
task :push do
|
102
|
-
show_text ">> Pushing code to GitLab y GitHub"
|
103
|
-
puts ""
|
104
|
-
sh "git push origin master"
|
105
|
-
puts ""
|
106
|
-
sh "git push github master"
|
107
|
-
puts ""
|
108
|
-
end
|
109
|
-
|
110
110
|
desc "Build #{gem_file} into pkg folder"
|
111
111
|
task :build do
|
112
112
|
show_text ">> Creating #{gem_file}"
|
data/bonsai_client.gemspec
CHANGED
@@ -20,7 +20,8 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.executables = all_files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
s.bindir = "exe"
|
22
22
|
s.require_paths = ["lib"]
|
23
|
-
s.
|
23
|
+
s.add_runtime_dependency 'rest-client', '~> 2.0'
|
24
|
+
s.add_development_dependency 'bundler', "~> 1.12"
|
24
25
|
s.add_development_dependency "rake", "~> 10.0"
|
25
26
|
s.add_development_dependency 'minitest', '~> 5.0'
|
26
27
|
end
|
data/lib/bonsai_client/client.rb
CHANGED
@@ -2,7 +2,38 @@ module BonsaiClient
|
|
2
2
|
# Client for a Bonsai server.
|
3
3
|
class Client
|
4
4
|
|
5
|
+
# @param [Hash] opts Otions to create the client.
|
6
|
+
# @option opts [String] :url Bonsai server URL (such as https://bonsai-server.com)
|
7
|
+
# @option opts [String] :client_id Unique ID for each client
|
5
8
|
def initialize(opts = {})
|
9
|
+
@url = opts[:url] || ''
|
10
|
+
@client_id = opts[:client_id] || ''
|
11
|
+
end
|
12
|
+
|
13
|
+
# Upload a file.
|
14
|
+
#
|
15
|
+
# @param [Hash] opts Otions to upload a file.
|
16
|
+
# @option opts [String] :path File path
|
17
|
+
#
|
18
|
+
# @return [Hash] Response from Bonsai server.
|
19
|
+
def upload(opts = {})
|
20
|
+
path = opts[:path] || ''
|
21
|
+
raise_no_file_path! if path.empty?
|
22
|
+
response = RestClient.post(
|
23
|
+
upload_url,
|
24
|
+
file: File.new(path, 'rb')
|
25
|
+
)
|
26
|
+
JSON.parse(response.to_str, symbolize_names: true)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def raise_no_file_path!
|
32
|
+
raise 'No file path'
|
33
|
+
end
|
34
|
+
|
35
|
+
def upload_url
|
36
|
+
"#{@url}/api/client/#{@client_id}/upload"
|
6
37
|
end
|
7
38
|
|
8
39
|
end
|
data/lib/bonsai_client.rb
CHANGED
@@ -1,22 +1,35 @@
|
|
1
1
|
def require_all(path)
|
2
|
-
glob = File.join(__dir__, path,
|
2
|
+
glob = File.join(__dir__, path, '*.rb')
|
3
3
|
Dir[glob].sort.each do |f|
|
4
4
|
require f
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
8
8
|
# stdlib
|
9
|
-
require
|
10
|
-
require
|
11
|
-
|
9
|
+
require 'fileutils'
|
10
|
+
require 'ostruct'
|
11
|
+
require 'json'
|
12
|
+
require 'rest-client'
|
13
|
+
require_all 'bonsai_client'
|
12
14
|
|
13
15
|
module BonsaiClient
|
14
16
|
|
15
|
-
#
|
17
|
+
# Create a new client for a Bonsai server.
|
18
|
+
#
|
19
|
+
# @param [Hash] opts Otions to create the client.
|
20
|
+
# @option opts [String] :url Bonsai server URL (such as https://bonsai-server.com)
|
21
|
+
# @option opts [String] :client_id Unique ID for each client
|
16
22
|
#
|
17
23
|
# @return [Client]
|
18
24
|
def self.create(opts = {})
|
19
25
|
Client.new(opts)
|
20
26
|
end
|
27
|
+
|
28
|
+
# Extract file checksum from response data.
|
29
|
+
#
|
30
|
+
# @return [String]
|
31
|
+
def self.checksum_from_response(response)
|
32
|
+
response[:data][:file_checksum]
|
33
|
+
end
|
21
34
|
|
22
35
|
end
|
Binary file
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bonsai_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -60,8 +74,9 @@ extensions: []
|
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
62
76
|
- ".gitignore"
|
63
|
-
- ".gitlab-ci
|
77
|
+
- ".gitlab-ci.yml"
|
64
78
|
- ".travis-template.yml"
|
79
|
+
- ".yardopts"
|
65
80
|
- CHANGELOG.md
|
66
81
|
- Gemfile
|
67
82
|
- README.md
|
@@ -73,6 +88,7 @@ files:
|
|
73
88
|
- lib/bonsai_client/client.rb
|
74
89
|
- lib/bonsai_client/version.rb
|
75
90
|
- test-data/.keep
|
91
|
+
- test-data/sample.jpg
|
76
92
|
homepage: https://gitlab.com/galfuslab/bonsai-client
|
77
93
|
licenses:
|
78
94
|
- MIT
|