sharenow_cli 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +45 -0
- data/LICENSE.txt +21 -0
- data/README.md +48 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/sharenow +5 -0
- data/lib/sharenow_cli/cli.rb +70 -0
- data/lib/sharenow_cli/version.rb +3 -0
- data/lib/sharenow_cli.rb +6 -0
- data/sharenow_cli.gemspec +31 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c09a1fa57e2d526c36114eb37e0bc500aafc0a6de69dad1615666fd9b99d6136
|
4
|
+
data.tar.gz: '068566cc38f6e5bfe0d8c2939a5473e76e945b50fdf35a61c853d739fa569605'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 30c91e9d1b4b4798f401c2f08319439d0881b7f251ffb3cbdea30fdc9db56e98c1de9983c78f978101958d6e26659e48b5573f3c210354d29d4689df5fd498de
|
7
|
+
data.tar.gz: 0150dfc34e50fb99fe2073985be05c6dd578faec28bc30d70a35cbef8ebf4ef060187c2d62a188b53e791ed3854f284821c66a24bb5e2984147f03ea154f7ba7
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
sharenow_cli (0.1.0)
|
5
|
+
faraday
|
6
|
+
mime-types
|
7
|
+
thor
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
diff-lcs (1.3)
|
13
|
+
faraday (0.15.2)
|
14
|
+
multipart-post (>= 1.2, < 3)
|
15
|
+
mime-types (3.1)
|
16
|
+
mime-types-data (~> 3.2015)
|
17
|
+
mime-types-data (3.2016.0521)
|
18
|
+
multipart-post (2.0.0)
|
19
|
+
rake (10.5.0)
|
20
|
+
rspec (3.7.0)
|
21
|
+
rspec-core (~> 3.7.0)
|
22
|
+
rspec-expectations (~> 3.7.0)
|
23
|
+
rspec-mocks (~> 3.7.0)
|
24
|
+
rspec-core (3.7.1)
|
25
|
+
rspec-support (~> 3.7.0)
|
26
|
+
rspec-expectations (3.7.0)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.7.0)
|
29
|
+
rspec-mocks (3.7.0)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.7.0)
|
32
|
+
rspec-support (3.7.1)
|
33
|
+
thor (0.20.0)
|
34
|
+
|
35
|
+
PLATFORMS
|
36
|
+
ruby
|
37
|
+
|
38
|
+
DEPENDENCIES
|
39
|
+
bundler (~> 1.16)
|
40
|
+
rake (~> 10.0)
|
41
|
+
rspec (~> 3.0)
|
42
|
+
sharenow_cli!
|
43
|
+
|
44
|
+
BUNDLED WITH
|
45
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 shun.hikita
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# SharenowCli
|
2
|
+
|
3
|
+
sharenow-cli is a gem that provides cli that can upload files from the command line to the file upload service [share-now](https://www.share-now.me)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install sharenow_cli
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
basic usage
|
12
|
+
|
13
|
+
Please specify the file path you want to register as the first argument.
|
14
|
+
|
15
|
+
|
16
|
+
```
|
17
|
+
$ sharenow push './sample.rb' -t 'title' -d 'description' -l 3
|
18
|
+
```
|
19
|
+
|
20
|
+
options
|
21
|
+
|
22
|
+
|option|alias|about|default|
|
23
|
+
|:---|:---|:---|:---|
|
24
|
+
|--title|-t|set title|""|
|
25
|
+
|--desc|-d|set description|""|
|
26
|
+
|--delete_limit|-l|set file and content delte limit|14|
|
27
|
+
|
28
|
+
|
29
|
+
Multiple files can be specified
|
30
|
+
|
31
|
+
```
|
32
|
+
$ sharenow push './foo.rb ./bar.rb' -t 'title' -d 'description' -l 3
|
33
|
+
$ sharenow push './.*rb' -t 'title' -d 'description' -l 3
|
34
|
+
```
|
35
|
+
|
36
|
+
## Development
|
37
|
+
|
38
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
39
|
+
|
40
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sharenow_cli.
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "sharenow_cli"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/sharenow
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'mime/types'
|
3
|
+
require 'faraday'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module SharenowCli
|
7
|
+
class CLI < Thor
|
8
|
+
|
9
|
+
BASE_URL = 'https://www.share-now.me'.freeze
|
10
|
+
|
11
|
+
SharenowError = Class.new(StandardError)
|
12
|
+
|
13
|
+
desc "push {target_file_paths}", "upload the {target_file_paths} to share-now.me. "
|
14
|
+
option :title, type: :string, desc: 'set file content title', aliases: '-t'
|
15
|
+
option :desc, type: :string, desc: 'set file content description', aliases: '-d'
|
16
|
+
option :delete_limit, type: :string, desc: 'set file content description', aliases: '-l'
|
17
|
+
def push(target_file_paths)
|
18
|
+
raise SharenowError.new('API token is not set in ENV["SHARENOW_API_TOKEN"] variable') if ENV['SHARENOW_API_TOKEN'].nil?
|
19
|
+
|
20
|
+
title, desc, delete_limit = options[:title], options[:desc], options[:delete_limit]
|
21
|
+
|
22
|
+
target_file_paths = target_file_paths.split(' ')
|
23
|
+
|
24
|
+
raise SharenowError.new('The correct file path is not specified') if target_file_paths.size == 0
|
25
|
+
|
26
|
+
upload_files = target_file_paths.inject([]) do |upload_files, file_path|
|
27
|
+
file_paths = Dir.glob(file_path)
|
28
|
+
|
29
|
+
raise SharenowError.new('Directory is not supported') if file_paths.find{|file| FileTest.directory?(file) }
|
30
|
+
|
31
|
+
upload_ios = file_paths.map { |file_path| Faraday::UploadIO.new(file_path, MIME::Types.type_for(file_path)[0].to_s) }
|
32
|
+
upload_files.concat(upload_ios).uniq
|
33
|
+
end
|
34
|
+
|
35
|
+
res = faraday_multipart_conn("#{BASE_URL}/api/v1/contents").post do |req|
|
36
|
+
req.body = body_params(title, desc, delete_limit, upload_files)
|
37
|
+
end
|
38
|
+
|
39
|
+
if res.status == 201
|
40
|
+
res_body = JSON.parse(res.body)
|
41
|
+
puts res_body['shared_link']
|
42
|
+
elsif res.status == 400
|
43
|
+
puts JSON.parse(res.body).join("\n")
|
44
|
+
else
|
45
|
+
puts res.body
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def faraday_multipart_conn(url)
|
52
|
+
Faraday.new(url) do |conn|
|
53
|
+
conn.token_auth "#{ENV['SHARENOW_API_TOKEN']}"
|
54
|
+
conn.request :multipart
|
55
|
+
conn.request :url_encoded
|
56
|
+
conn.adapter :net_http
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def body_params(title, desc, delete_limit, files)
|
61
|
+
params = {content: {}}
|
62
|
+
params[:content][:title] = title unless title.nil?
|
63
|
+
params[:content][:description] = desc unless desc.nil?
|
64
|
+
params[:content][:delete_limit] = delete_limit.to_i unless delete_limit.nil?
|
65
|
+
params[:content][:files] = files
|
66
|
+
params
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
data/lib/sharenow_cli.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "sharenow_cli/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sharenow_cli"
|
8
|
+
spec.version = SharenowCli::VERSION
|
9
|
+
spec.authors = ['h1kita']
|
10
|
+
|
11
|
+
spec.summary = 'It provides a command line interface that allows file upload to share-now.me .'
|
12
|
+
spec.description = 'It provides a command line interface that allows file upload to share-now.me .'
|
13
|
+
spec.homepage = "https://github.com/shunhikita/sharenow_cli"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
|
28
|
+
spec.add_dependency "thor"
|
29
|
+
spec.add_dependency "faraday"
|
30
|
+
spec.add_dependency "mime-types"
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sharenow_cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- h1kita
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-07-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: faraday
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: mime-types
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: It provides a command line interface that allows file upload to share-now.me
|
98
|
+
.
|
99
|
+
email:
|
100
|
+
executables:
|
101
|
+
- sharenow
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
108
|
+
- Gemfile
|
109
|
+
- Gemfile.lock
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- bin/console
|
114
|
+
- bin/setup
|
115
|
+
- exe/sharenow
|
116
|
+
- lib/sharenow_cli.rb
|
117
|
+
- lib/sharenow_cli/cli.rb
|
118
|
+
- lib/sharenow_cli/version.rb
|
119
|
+
- sharenow_cli.gemspec
|
120
|
+
homepage: https://github.com/shunhikita/sharenow_cli
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.7.6
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: It provides a command line interface that allows file upload to share-now.me
|
144
|
+
.
|
145
|
+
test_files: []
|