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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0436aa3576974561c877f20e7ed166c0481329b9
4
- data.tar.gz: 516009c69e91c5c26abc5ca827f85308a79a42eb
3
+ metadata.gz: 5cba822dab0323ad666691294efcea55e72cd543
4
+ data.tar.gz: e44e02ab043734bd4f3d37c196d6934c580fc61a
5
5
  SHA512:
6
- metadata.gz: 8e98178eafc87223eeef24fe87b86f1140741372510f6f4b2dee0d9821a3175f5e77455b8bf7027806a58586dd4e68f78579b6761314f4eb9cdbdc256dac2b89
7
- data.tar.gz: df4534e6eafb5a2900a72b568161291d01a902982893b728544a402a248635d0500cf518ec63d9f6a0566137b09d7e504932f48f7af1debb40e4c09e277b651e
6
+ metadata.gz: cac296df7bad1cea1cc1b4ca950f2c255d8306f32b951088dc80b98b09ec874bc630e4744d2a6a1235e61f21942bfbd2b2b44bf672e956468bf4fa8b6570855d
7
+ data.tar.gz: 14bcc818aa9c8d25836067355e42f5c569cb2f272c143ca61cf49ed58688574f188e950fde9c2eec3fa05230ccf5a5e7ebaec489c8d385d2f02e3d71207fe2c5
data/.gitignore CHANGED
@@ -1,4 +1,7 @@
1
1
 
2
+ # Local files
3
+ NOTES.local.md
4
+
2
5
  # Specific environment configuration
3
6
  /config/environments/*
4
7
  !/config/environments/.keep
@@ -2,7 +2,7 @@ image: "ruby:2.4"
2
2
 
3
3
  before_script:
4
4
  - ruby -v
5
- - gem install bundler --no-ri --no-rdoc
5
+ - gem install bundler --version "~> 1.12" --no-document
6
6
  - bundle install
7
7
 
8
8
  tests:
data/.yardopts ADDED
@@ -0,0 +1,4 @@
1
+
2
+ --markup-provider=redcarpet
3
+ --markup=markdown
4
+
data/CHANGELOG.md CHANGED
@@ -3,6 +3,10 @@
3
3
  ## [Unreleased]
4
4
  * ...
5
5
 
6
+ ## [0.1.1] - 2019-03-02
7
+ * Upload a file.
8
+ * Documentation.
9
+
6
10
  ## [0.1.0] - 2019-03-01
7
11
  * First version.
8
12
 
data/Gemfile CHANGED
@@ -5,4 +5,7 @@ gemspec
5
5
 
6
6
  group :test, :development do
7
7
  gem 'minitest-reporters'
8
+ gem 'yard'
9
+ gem 'redcarpet'
10
+ gem 'github-markup'
8
11
  end
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
- # Creata a new instance of Bonsai client:
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
- result = bonsai.upload(path: '/path/to/file')
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: 'AF1...') # http://bonsai-server.com/thumbnails/AF1...
37
- src2 = bonsai.thumbnail_url(name: 'myfile') # http://bonsai-server.com/...
38
- src3 = bonsai.thumbnail_url(checksum: 'AF1...', size: :medium) # http://bonsai-server.com/thumbnails/AF1.../size/medium
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
- Crea una nueva versión de la gema (sin subirla a ruby gems pero sí a GitLab y GitHub):
54
+ Create a new version:
52
55
 
53
56
  ```bash
54
57
  rake release
55
58
  ```
56
59
 
57
- Sube commits a los repositorios git:
60
+ Push commits to git repositories (GitLab and GitHub)
58
61
 
59
62
  ```bash
60
63
  rake push
61
64
  ```
62
65
 
63
- Publica la última versión de la gema en Rubygems:
66
+ Publish the current gem version to Rubygems:
64
67
 
65
68
  ```bash
66
69
  rake push
67
70
  ```
68
71
 
69
- Muestar la versión actual de la gema:
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}"
@@ -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.add_development_dependency "bundler", "~> 1.12"
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
@@ -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
@@ -1,4 +1,4 @@
1
1
  module BonsaiClient
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  NAME = 'bonsai_client'.freeze
4
4
  end
data/lib/bonsai_client.rb CHANGED
@@ -1,22 +1,35 @@
1
1
  def require_all(path)
2
- glob = File.join(__dir__, path, "*.rb")
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 "fileutils"
10
- require "ostruct"
11
- require_all "bonsai_client"
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
- # Client for a Bonsai server.
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.0
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-01 00:00:00.000000000 Z
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-tempalte.yml"
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