gist_nuke 0.0.1
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.
- data/lib/gist_nuke.rb +93 -0
- metadata +78 -0
data/lib/gist_nuke.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
require 'uri'
|
4
|
+
require 'typhoeus'
|
5
|
+
|
6
|
+
module GistNuke
|
7
|
+
extend self
|
8
|
+
|
9
|
+
BASE_URL = "https://api.github.com/"
|
10
|
+
AUTH_EXT = "authorizations"
|
11
|
+
|
12
|
+
def login
|
13
|
+
credentials = {}
|
14
|
+
puts "Let's get an Oauth Token from GitHub"
|
15
|
+
print "Enter your username: "
|
16
|
+
credentials[:username] = $stdin.gets.chomp
|
17
|
+
print "Enter your password: "
|
18
|
+
credentials[:password] = begin `stty -echo` rescue nil
|
19
|
+
$stdin.gets.chomp
|
20
|
+
ensure
|
21
|
+
`stty echo` rescue nil
|
22
|
+
end
|
23
|
+
|
24
|
+
puts ""
|
25
|
+
phone_github(credentials)
|
26
|
+
end
|
27
|
+
|
28
|
+
def phone_github(credentials = {})
|
29
|
+
uri = URI(BASE_URL + AUTH_EXT)
|
30
|
+
req = Net::HTTP::Post.new(uri.path)
|
31
|
+
req.content_type = "application/json"
|
32
|
+
req.body = JSON.dump({
|
33
|
+
scopes: [:gist],
|
34
|
+
note: "Batch delete your gists, you know you want to."
|
35
|
+
})
|
36
|
+
|
37
|
+
req.basic_auth(credentials[:username], credentials[:password])
|
38
|
+
|
39
|
+
res = Net::HTTP.start(uri.hostname, uri.port,
|
40
|
+
:use_ssl => uri.scheme == 'https') do |http|
|
41
|
+
http.request(req)
|
42
|
+
end
|
43
|
+
|
44
|
+
save_auth_token(res.body)
|
45
|
+
end
|
46
|
+
|
47
|
+
def save_auth_token(res)
|
48
|
+
token = JSON.parse(res)['token']
|
49
|
+
File.open(".gist_nuke", "w+") do |file|
|
50
|
+
file.write(token)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def load_gists(page_number = 0)
|
55
|
+
token = File.read(".gist_nuke")
|
56
|
+
uri = URI("#{BASE_URL}gists?access_token=#{token}&page=#{page_number}")
|
57
|
+
Net::HTTP.start(uri.host, uri.port,
|
58
|
+
:use_ssl => uri.scheme == 'https') do |http|
|
59
|
+
request = Net::HTTP::Get.new uri.request_uri
|
60
|
+
|
61
|
+
response = http.request(request)
|
62
|
+
|
63
|
+
gist_hash = JSON.parse(response.body)
|
64
|
+
|
65
|
+
just_keys(gist_hash)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def just_keys(gist_hash = {})
|
70
|
+
just_keys = []
|
71
|
+
|
72
|
+
gist_hash.each do |hash|
|
73
|
+
just_keys << hash['id']
|
74
|
+
end
|
75
|
+
|
76
|
+
p just_keys
|
77
|
+
end
|
78
|
+
|
79
|
+
def delete_range(numbers = [])
|
80
|
+
p numbers = numbers.map { |num| num.to_i }
|
81
|
+
p range = (numbers[0]..numbers[-1])
|
82
|
+
p delete_list = load_gists[range]
|
83
|
+
construct_hydra(delete_list)
|
84
|
+
@batch.run
|
85
|
+
end
|
86
|
+
|
87
|
+
def construct_hydra(range)
|
88
|
+
t = File.read(".gist_nuke")
|
89
|
+
@batch = Typhoeus::Hydra.new
|
90
|
+
range.map { |gist_id| @batch.queue(Typhoeus::Request.new("#{BASE_URL}gists/#{gist_id}?access_token=#{t}",
|
91
|
+
method: :delete))}
|
92
|
+
end
|
93
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gist_nuke
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- zachgersh
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: typhoeus
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.6.5
|
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.6.5
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: vcr
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.5.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.5.0
|
46
|
+
description: A great way to clean up your github gist profile
|
47
|
+
email: zachgersh@gmail.com
|
48
|
+
executables: []
|
49
|
+
extensions: []
|
50
|
+
extra_rdoc_files: []
|
51
|
+
files:
|
52
|
+
- lib/gist_nuke.rb
|
53
|
+
homepage: http://zachgersh.github.io
|
54
|
+
licenses:
|
55
|
+
- MIT
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.8.25
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: Batch deletion of gists
|
78
|
+
test_files: []
|