gistrb 0.1.0 → 0.1.2
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 +5 -5
- data/.rubocop.yml +5 -0
- data/.travis.yml +0 -2
- data/LICENSE +1 -1
- data/README.md +2 -1
- data/Rakefile +1 -1
- data/bin/gistrb +10 -7
- data/gistrb.gemspec +1 -0
- data/lib/gist.rb +2 -0
- data/lib/gist/clipboard.rb +1 -1
- data/lib/gist/helpers.rb +1 -1
- data/lib/gist/post.rb +7 -11
- data/lib/gist/user.rb +30 -11
- data/lib/gist/version.rb +1 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f57c0cc5c36dd8ef2baebaeb474fd3b0b4d91312869375f5fc9df0f1c5780cc5
|
4
|
+
data.tar.gz: 5a061644fd3aa98c3de9a64eccb65e9fd0d89cf87e7efed27f373ce5227bb6a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ca6612dd6b0846aaaeb2f511fc92fc2902c867e62e28586f45f1ebfcad02178f148ea93e381eaccc06cd345a209529ea694589a89062cd716060832d903db6e
|
7
|
+
data.tar.gz: 9daca6856b2667e75649a5126f13e0a2bc41d69d2bfbaff28b74eafb23025409cf21b8e24b9ba24654f0f05fe679c0a297c6ccd1247c4be0822439f44ab646f2
|
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -29,6 +29,7 @@ Option | Description
|
|
29
29
|
-p | --public | Post the Gist as public (it posts as private by default)
|
30
30
|
-d [DESC] | --description [DESC] | Use [DESC] as the description for the Gist
|
31
31
|
-c | --clipboard | Automatically put the created Gist URL into your clipboard (beta)
|
32
|
+
-n | --netrc | Utilize .netrc file for storing/retrieving authorization token
|
32
33
|
|
33
34
|
## Installation:
|
34
35
|
Using RubyGems, simply run this command:
|
@@ -45,4 +46,4 @@ sudo apt-get install xclip
|
|
45
46
|
## License
|
46
47
|
MIT License
|
47
48
|
|
48
|
-
Copyright ©
|
49
|
+
Copyright © 2018 Cameron Roe
|
data/Rakefile
CHANGED
data/bin/gistrb
CHANGED
@@ -13,6 +13,10 @@ OptionParser.new do |opts|
|
|
13
13
|
options[:sign_in] = s
|
14
14
|
end
|
15
15
|
|
16
|
+
opts.on('-n', '--netrc', 'Use information from netrc when signing in') do |n|
|
17
|
+
options[:netrc] = n
|
18
|
+
end
|
19
|
+
|
16
20
|
opts.on('--sign-out', 'Clear out saved user') do |s|
|
17
21
|
options[:sign_out] = s
|
18
22
|
end
|
@@ -34,11 +38,6 @@ end.parse!
|
|
34
38
|
files = ARGV.clone
|
35
39
|
ARGV.clear
|
36
40
|
|
37
|
-
# Get anything sent by STDIN to support cat and pasting.
|
38
|
-
if !STDIN.tty? || files.empty? then
|
39
|
-
stdin = STDIN.read
|
40
|
-
end
|
41
|
-
|
42
41
|
if options[:sign_out]
|
43
42
|
File.delete(Gist::ACCESS_TOKEN_PATH) if File.exist?(Gist::ACCESS_TOKEN_PATH)
|
44
43
|
exit
|
@@ -48,12 +47,16 @@ if options[:sign_in]
|
|
48
47
|
print 'Username: '
|
49
48
|
username = gets.chomp
|
50
49
|
password = Gist::Helpers.get_password
|
51
|
-
@user = Gist::User.new(username, password)
|
50
|
+
@user = Gist::User.new(username, password, options[:netrc])
|
52
51
|
@user.authenticate
|
52
|
+
exit
|
53
53
|
end
|
54
54
|
|
55
|
+
# Get anything sent by STDIN to support cat and pasting.
|
56
|
+
stdin = STDIN.read if !STDIN.tty? || files.empty?
|
57
|
+
|
55
58
|
if options[:user]
|
56
|
-
@user = Gist::User.new
|
59
|
+
@user = Gist::User.new(nil, nil, options[:netrc])
|
57
60
|
@user.authenticate
|
58
61
|
unless @user.access_token
|
59
62
|
STDERR.puts 'ERROR: There is no user saved. You need to sign in.'
|
data/gistrb.gemspec
CHANGED
data/lib/gist.rb
CHANGED
data/lib/gist/clipboard.rb
CHANGED
data/lib/gist/helpers.rb
CHANGED
@@ -2,7 +2,7 @@ module Gist
|
|
2
2
|
# Helper methods for getting input
|
3
3
|
class Helpers
|
4
4
|
# Method to wrap a highline call to hide a passworded input
|
5
|
-
def self
|
5
|
+
def self.get_password(prompt = 'Password: ')
|
6
6
|
ask(prompt) { |q| q.echo = false }
|
7
7
|
end
|
8
8
|
end
|
data/lib/gist/post.rb
CHANGED
@@ -15,27 +15,23 @@ module Gist
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def submit(stdin)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
unless stdin.nil?
|
19
|
+
@source_files['STDIN'] = {
|
20
|
+
'content' => stdin
|
21
|
+
}
|
22
|
+
end
|
23
23
|
body = {
|
24
24
|
'files' => @source_files,
|
25
25
|
'public' => @public,
|
26
26
|
'description' => @description
|
27
27
|
}.to_json
|
28
28
|
headers ||= {}
|
29
|
-
unless @user.nil?
|
30
|
-
headers['Authorization'] = "token #{@user.access_token}"
|
31
|
-
end
|
29
|
+
headers['Authorization'] = "token #{@user.access_token}" unless @user.nil?
|
32
30
|
response = @http.post('/gists', body, headers)
|
33
31
|
JSON.parse(response.body)['html_url']
|
34
32
|
end
|
35
33
|
|
36
|
-
private
|
37
|
-
|
38
|
-
def load_code(filename)
|
34
|
+
private def load_code(filename)
|
39
35
|
file = File.open(filename)
|
40
36
|
file_str = ''
|
41
37
|
file.each do |line|
|
data/lib/gist/user.rb
CHANGED
@@ -6,9 +6,10 @@ module Gist
|
|
6
6
|
attr_accessor :access_token # Personal access token
|
7
7
|
|
8
8
|
# Create the GistUser instance
|
9
|
-
def initialize(username = nil, password = nil)
|
10
|
-
@username
|
11
|
-
@password
|
9
|
+
def initialize(username = nil, password = nil, netrc = nil)
|
10
|
+
@username ||= username
|
11
|
+
@password ||= password
|
12
|
+
@netrc ||= netrc
|
12
13
|
@http = Net::HTTP.new(Gist::API_URL, Gist::API_PORT)
|
13
14
|
@http.use_ssl = true
|
14
15
|
@access_token = load_token if saved?
|
@@ -42,20 +43,38 @@ module Gist
|
|
42
43
|
end
|
43
44
|
|
44
45
|
private def saved?
|
45
|
-
|
46
|
+
if @netrc.nil?
|
47
|
+
File.exist?(Gist::ACCESS_TOKEN_PATH)
|
48
|
+
else
|
49
|
+
netrc = Netrc.read
|
50
|
+
_username, token = netrc['api.github.com']
|
51
|
+
!token.nil?
|
52
|
+
end
|
46
53
|
end
|
47
54
|
|
48
55
|
private def save
|
49
|
-
|
50
|
-
Dir.
|
56
|
+
if @netrc.nil?
|
57
|
+
unless Dir.exist?(File.dirname(Gist::ACCESS_TOKEN_PATH))
|
58
|
+
Dir.mkdir(File.dirname(Gist::ACCESS_TOKEN_PATH))
|
59
|
+
end
|
60
|
+
token_file = File.new(Gist::ACCESS_TOKEN_PATH, 'w+')
|
61
|
+
token_file << @access_token
|
62
|
+
token_file.close
|
63
|
+
else
|
64
|
+
netrc = Netrc.read
|
65
|
+
netrc['api.github.com'] = @username, @access_token
|
66
|
+
netrc.save
|
51
67
|
end
|
52
|
-
token_file = File.new(Gist::ACCESS_TOKEN_PATH, 'w+')
|
53
|
-
token_file << @access_token
|
54
|
-
token_file.close
|
55
68
|
end
|
56
69
|
|
57
70
|
private def load_token
|
58
|
-
|
71
|
+
if @netrc.nil?
|
72
|
+
File.readlines(Gist::ACCESS_TOKEN_PATH).first
|
73
|
+
else
|
74
|
+
netrc = Netrc.read
|
75
|
+
_username, token = netrc['api.github.com']
|
76
|
+
token
|
77
|
+
end
|
59
78
|
end
|
60
79
|
|
61
80
|
private def auth_obj
|
@@ -64,7 +83,7 @@ module Gist
|
|
64
83
|
req['Content-Type'] = 'application/json'
|
65
84
|
req.body = {
|
66
85
|
scopes: ['gist'], # Only need Gist scope
|
67
|
-
note:
|
86
|
+
note: "Gist access for GistRB client on #{Socket.gethostname}",
|
68
87
|
note_url: 'https://github.com/cameronbroe/gistrb'
|
69
88
|
}.to_json
|
70
89
|
req
|
data/lib/gist/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gistrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cameron Roe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '1.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: netrc
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.11.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.11.0
|
69
83
|
description:
|
70
84
|
email:
|
71
85
|
- cameron@cameronbroe.com
|
@@ -77,6 +91,7 @@ extensions: []
|
|
77
91
|
extra_rdoc_files: []
|
78
92
|
files:
|
79
93
|
- ".gitignore"
|
94
|
+
- ".rubocop.yml"
|
80
95
|
- ".travis.yml"
|
81
96
|
- Gemfile
|
82
97
|
- LICENSE
|
@@ -112,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
127
|
version: '0'
|
113
128
|
requirements: []
|
114
129
|
rubyforge_project:
|
115
|
-
rubygems_version: 2.6
|
130
|
+
rubygems_version: 2.7.6
|
116
131
|
signing_key:
|
117
132
|
specification_version: 4
|
118
133
|
summary: A command-line utility to manage GitHub Gists
|