glsnip 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/glsnip +0 -1
- data/lib/glsnip/base.rb +19 -5
- data/lib/glsnip/formatter.rb +51 -0
- data/lib/glsnip/snippets.rb +4 -6
- data/lib/glsnip/version.rb +1 -2
- data/lib/glsnip.rb +0 -1
- data/test/test_hello.rb +0 -1
- metadata +16 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf475a86b786f39f02332a4ac5354b5850d97426f40996df210cc97423d383a8
|
4
|
+
data.tar.gz: 118f452ce53a154e4553efc3f401b42d4ef70ecfd976d18218761d4977b8799c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9cabb1c6f9ac74f3f8a00ed77ffcd18bbfe57ece4aa716ce349d5e4418879fdcc7a5fa6419a1b94f91b2e909bf855bb341a6c5c1d15b9ef902d7e21ee6afcbc
|
7
|
+
data.tar.gz: 2582132c604d951929fb983774fd48c50b14e939486add278aab3d587b770ef8b23b6fdf0191cb1d6b2cf824af72addba3efd14d62d11a835ec95dffc3b927f3
|
data/bin/glsnip
CHANGED
data/lib/glsnip/base.rb
CHANGED
@@ -27,9 +27,11 @@
|
|
27
27
|
|
28
28
|
require 'optparse'
|
29
29
|
require 'English'
|
30
|
+
require 'colorize'
|
30
31
|
|
31
32
|
require 'glsnip/version'
|
32
33
|
require 'glsnip/snippets'
|
34
|
+
require 'glsnip/formatter'
|
33
35
|
|
34
36
|
trap('INT') do
|
35
37
|
puts "\nTerminating..."
|
@@ -43,7 +45,13 @@ optparse = OptionParser.new do |opts|
|
|
43
45
|
|
44
46
|
opts.on('-a', '--all', 'Lists all of the snippets for a user') do
|
45
47
|
gl_response = Glsnip::Snippets.list
|
46
|
-
|
48
|
+
|
49
|
+
if gl_response.success?
|
50
|
+
puts Glsnip::Formatter.list(gl_response.body)
|
51
|
+
else
|
52
|
+
puts Glsnip::Formatter.error(gl_response.body)
|
53
|
+
end
|
54
|
+
|
47
55
|
exit
|
48
56
|
end
|
49
57
|
|
@@ -52,14 +60,23 @@ optparse = OptionParser.new do |opts|
|
|
52
60
|
|
53
61
|
print 'Enter a title for the snippet -> '
|
54
62
|
title = gets.chomp
|
63
|
+
|
55
64
|
print 'Is this snippet private? (y/n) -> '
|
56
65
|
visibility = gets.chomp.casecmp?('y') ? 'private' : 'public'
|
66
|
+
|
57
67
|
content = File.read(file_name)
|
68
|
+
|
58
69
|
gl_response = Glsnip::Snippets.create(title: title,
|
59
70
|
file_name: File.split(file_name).last,
|
60
71
|
content: content,
|
61
72
|
visibility: visibility)
|
62
|
-
|
73
|
+
|
74
|
+
if gl_response.success?
|
75
|
+
puts Glsnip::Formatter.create_success(gl_response.body)
|
76
|
+
else
|
77
|
+
puts Glsnip::Formatter.error(gl_response.body)
|
78
|
+
end
|
79
|
+
|
63
80
|
exit
|
64
81
|
end
|
65
82
|
|
@@ -96,6 +113,3 @@ rescue OptionParser::InvalidOption, OptionParser::MissingArgument
|
|
96
113
|
puts 'Use -h or --help for options.'
|
97
114
|
exit 1
|
98
115
|
end
|
99
|
-
|
100
|
-
ARGV.each do |filename|
|
101
|
-
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2019 Richard Davis
|
4
|
+
#
|
5
|
+
# This file is part of glsnip.
|
6
|
+
#
|
7
|
+
# glsnip is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# glsnip is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with glsnip. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
require 'colorize'
|
21
|
+
require 'json'
|
22
|
+
|
23
|
+
module Glsnip
|
24
|
+
##
|
25
|
+
# = Formatter
|
26
|
+
# Author:: Richard Davis
|
27
|
+
# Copyright:: Copyright 2019 Richard Davis
|
28
|
+
# License:: GNU Public License 3
|
29
|
+
#
|
30
|
+
# Formats execution results and prints to the terminal
|
31
|
+
class Formatter
|
32
|
+
def self.error(json)
|
33
|
+
body = JSON.parse(json)
|
34
|
+
"Failure: #{body['message']}".colorize(:red)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.list(json)
|
38
|
+
body = JSON.parse(json)
|
39
|
+
snippets = []
|
40
|
+
body.each do |snippet|
|
41
|
+
snippets.push "\"#{snippet['title']}\" (#{snippet['file_name']} | #{snippet['id']}): #{snippet['web_url']}".colorize(:light_blue)
|
42
|
+
end
|
43
|
+
snippets
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.create_success(json)
|
47
|
+
body = JSON.parse(json)
|
48
|
+
"Snippet \"#{body['title']}\" (#{body['file_name']} | #{body['id']}) successfully created: #{body['web_url']}".colorize(:green)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/glsnip/snippets.rb
CHANGED
@@ -24,12 +24,12 @@ require 'glsnip/delete_request'
|
|
24
24
|
|
25
25
|
module Glsnip
|
26
26
|
##
|
27
|
-
# =
|
27
|
+
# = Snippets
|
28
28
|
# Author:: Richard Davis
|
29
29
|
# Copyright:: Copyright 2019 Richard Davis
|
30
30
|
# License:: GNU Public License 3
|
31
31
|
#
|
32
|
-
#
|
32
|
+
# Provides interactions with the GitLab Snippets API
|
33
33
|
class Snippets
|
34
34
|
ENDPOINT = 'snippets'
|
35
35
|
private_constant :ENDPOINT
|
@@ -49,10 +49,8 @@ module Glsnip
|
|
49
49
|
req.send
|
50
50
|
end
|
51
51
|
|
52
|
-
def self.update
|
53
|
-
end
|
52
|
+
def self.update; end
|
54
53
|
|
55
|
-
def self.delete
|
56
|
-
end
|
54
|
+
def self.delete; end
|
57
55
|
end
|
58
56
|
end
|
data/lib/glsnip/version.rb
CHANGED
@@ -17,7 +17,6 @@
|
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with glsnip. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
|
-
|
21
20
|
##
|
22
21
|
# = version.rb
|
23
22
|
# Author:: Richard Davis
|
@@ -27,5 +26,5 @@
|
|
27
26
|
# Module for namespacing application classes.
|
28
27
|
module Glsnip
|
29
28
|
# Program version number
|
30
|
-
VERSION = '0.0.
|
29
|
+
VERSION = '0.0.2'
|
31
30
|
end
|
data/lib/glsnip.rb
CHANGED
data/test/test_hello.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glsnip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Davis
|
@@ -10,6 +10,20 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2019-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.8.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.8.1
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: faraday
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +52,7 @@ files:
|
|
38
52
|
- lib/glsnip.rb
|
39
53
|
- lib/glsnip/base.rb
|
40
54
|
- lib/glsnip/delete_request.rb
|
55
|
+
- lib/glsnip/formatter.rb
|
41
56
|
- lib/glsnip/get_request.rb
|
42
57
|
- lib/glsnip/post_request.rb
|
43
58
|
- lib/glsnip/put_request.rb
|