slap 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/slap +67 -0
- data/lib/slap.rb +98 -0
- metadata +128 -0
data/bin/slap
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'colorize'
|
3
|
+
require 'trollop'
|
4
|
+
require 'json'
|
5
|
+
require 'clipboard'
|
6
|
+
|
7
|
+
require 'slap'
|
8
|
+
|
9
|
+
opts = Trollop::options do
|
10
|
+
version "slap 0.0.1 (c) 2013 Jeffrey Crowell"
|
11
|
+
banner <<-EOS
|
12
|
+
Slap is a client for pasting to github gists from the command line
|
13
|
+
|
14
|
+
Usage:
|
15
|
+
slap [options] <filenames>+
|
16
|
+
where [options] are:
|
17
|
+
EOS
|
18
|
+
|
19
|
+
opt :description, "description of the gist",
|
20
|
+
:default => "my gist at #{Time.now}",
|
21
|
+
:type => String
|
22
|
+
opt :public, "make the gist public"
|
23
|
+
opt :anonymous, "make gist anonymous"
|
24
|
+
end
|
25
|
+
|
26
|
+
if ARGV.count == 0
|
27
|
+
puts "[!] please specify at least one file".red
|
28
|
+
abort
|
29
|
+
end
|
30
|
+
|
31
|
+
exists = true
|
32
|
+
files = Hash.new
|
33
|
+
|
34
|
+
ARGV.each {|f|
|
35
|
+
if not File.file?(f)
|
36
|
+
exists = false
|
37
|
+
puts "[!] file #{f} does not exist".red
|
38
|
+
else
|
39
|
+
m = Hash.new
|
40
|
+
m["content"] = File.open(f, "rb"){|file| file.read}.force_encoding("utf-8")
|
41
|
+
if m["content"].length == 0
|
42
|
+
puts "[!] ERROR #{f} has size of 0".red
|
43
|
+
abort
|
44
|
+
end
|
45
|
+
files[File.basename(f)] = m
|
46
|
+
end
|
47
|
+
}
|
48
|
+
|
49
|
+
g = Slap.new
|
50
|
+
resp = g.postGist(files, opts[:description], opts[:public].to_s, opts[:anonymous])
|
51
|
+
if resp.nil?
|
52
|
+
puts "[!] ERROR: failed to upload gist".red
|
53
|
+
puts resp
|
54
|
+
abort
|
55
|
+
end
|
56
|
+
|
57
|
+
if resp["html_url"].nil?
|
58
|
+
puts "[!] failed to upload gist".red
|
59
|
+
if not resp["message"].nil?
|
60
|
+
puts "[!] message - #{resp["message"]}".red
|
61
|
+
end
|
62
|
+
abort
|
63
|
+
end
|
64
|
+
url = resp["html_url"]
|
65
|
+
Clipboard.copy(url)
|
66
|
+
puts "[+] gist successfully uploaded to #{url}".green
|
67
|
+
puts "[!] copied to clipboard if xclip is installed".green
|
data/lib/slap.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'colorize'
|
3
|
+
require 'highline/import'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
class Slap
|
7
|
+
def getToken
|
8
|
+
puts "[!] GitHub API Token needed to use gists".red
|
9
|
+
_username = ask("USERNAME: ".green) {|q| q.echo = true}
|
10
|
+
_password = ask("PASSWORD: ".green) {|q| q.echo = false}
|
11
|
+
_headers = Hash.new
|
12
|
+
_headers["Content-Type"] = "application/json"
|
13
|
+
_headers["User-Agent"] = "Slap, not at all like gecko"
|
14
|
+
_auth = {:username=>_username, :password=>_password}
|
15
|
+
_options = {
|
16
|
+
:headers => _headers,
|
17
|
+
:basic_auth => _auth,
|
18
|
+
:body => {
|
19
|
+
"scopes" => ["gist", "repo"],
|
20
|
+
"note" => "slap",
|
21
|
+
"note_url" => "http://raxcity.com/slap"
|
22
|
+
}.to_json,
|
23
|
+
}
|
24
|
+
|
25
|
+
_resp = HTTParty.post("https://api.github.com/authorizations", _options)
|
26
|
+
|
27
|
+
#puts "---DEBUG---".green
|
28
|
+
#puts _resp
|
29
|
+
#puts "---DEBUG---".green
|
30
|
+
|
31
|
+
if _resp.code == 201
|
32
|
+
puts "[+] got and saved token".green
|
33
|
+
else
|
34
|
+
puts "[!] unable to get token: #{_resp["message"]}".red
|
35
|
+
return nil
|
36
|
+
end
|
37
|
+
_token = _resp["token"]
|
38
|
+
return _token
|
39
|
+
end
|
40
|
+
|
41
|
+
def loadToken
|
42
|
+
_dotfile = ENV['HOME']+"/.slaprc"
|
43
|
+
if File.file?(_dotfile)
|
44
|
+
_token = File.open(_dotfile, "rb"){|io| io.read}
|
45
|
+
else
|
46
|
+
return nil
|
47
|
+
end
|
48
|
+
return _token
|
49
|
+
end
|
50
|
+
|
51
|
+
def saveToken(token)
|
52
|
+
_dotfile = ENV['HOME']+"/.slaprc"
|
53
|
+
File.open(_dotfile, "w"){|io| io.write(token)}
|
54
|
+
end
|
55
|
+
|
56
|
+
def getAuthed
|
57
|
+
_tok = loadToken
|
58
|
+
if not _tok.nil?
|
59
|
+
return _tok
|
60
|
+
end
|
61
|
+
_tok = getToken
|
62
|
+
if not _tok.nil?
|
63
|
+
saveToken(_tok)
|
64
|
+
return _tok
|
65
|
+
end
|
66
|
+
puts "[!] ERROR: could not get auth token!".red
|
67
|
+
return nil
|
68
|
+
end
|
69
|
+
|
70
|
+
def postGist(files, description, pub, anon)
|
71
|
+
_headers= Hash.new
|
72
|
+
_headers["Content-Type"] = "application/json"
|
73
|
+
_headers["User-Agent"] = "Slap, not at all like gecko"
|
74
|
+
if anon == false
|
75
|
+
tok = getAuthed
|
76
|
+
if tok.nil?
|
77
|
+
return nil
|
78
|
+
end
|
79
|
+
_headers["Authorization"] = "token #{tok}"
|
80
|
+
else
|
81
|
+
#do nothing
|
82
|
+
end
|
83
|
+
|
84
|
+
_options = {
|
85
|
+
:body => {
|
86
|
+
"description" => description,
|
87
|
+
"public" => pub,
|
88
|
+
"files" => files
|
89
|
+
}.to_json,
|
90
|
+
:headers => _headers
|
91
|
+
}
|
92
|
+
_resp = HTTParty.post("https://api.github.com/gists", _options)
|
93
|
+
#puts "---DEBUG---".green
|
94
|
+
#puts _resp
|
95
|
+
#puts "---DEBUG---".green
|
96
|
+
return _resp
|
97
|
+
end
|
98
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jeffrey Crowell
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: colorize
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: trollop
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: highline
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: clipboard
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: a command line client for github's gists
|
95
|
+
email: crowell@bu.edu
|
96
|
+
executables:
|
97
|
+
- slap
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- lib/slap.rb
|
102
|
+
- bin/slap
|
103
|
+
homepage: https://bitbucket.org/crowell/slaprb
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
post_install_message: slap installed *<:-)
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ! '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 1.8.23
|
125
|
+
signing_key:
|
126
|
+
specification_version: 3
|
127
|
+
summary: slap
|
128
|
+
test_files: []
|