cleangist 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cleangist.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Michael Rose
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # CleanGist
2
+
3
+ This gem helps you clean up your gists. It will iterate through your gists and ask to keep your gist or to remove it.
4
+
5
+
6
+ ########################################################################
7
+ Files: Test.java,TopologySetup.java
8
+ Languages: Java,Java
9
+ Visibility: public
10
+ https://api.github.com/gists/xx
11
+ ------------------------------------------------------------------------
12
+ Test gist
13
+ ------------------------------------------------------------------------
14
+ This is a test gist
15
+ file contents
16
+
17
+ Keep gist? [y]/n/q q
18
+
19
+ ## Installation
20
+
21
+ $ gem install cleangist
22
+
23
+ ## Get an access token
24
+
25
+ Go to your Account Settings on Github and create a new Personal Access Token. Put this in an environmental variable
26
+ called `GITHUB_TOKEN` e.x (in a .bash_profile):
27
+
28
+ export GITHUB_TOKEN 64154e0cd2082e1e7fb3f59aa6fd39dc6b9e770d
29
+
30
+ ## Usage
31
+
32
+ `cleangist` with environmental variable OR `cleangist <personal access token>`
33
+
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/cleangist ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'cleangist'
4
+
5
+ CleanGist.check_gists (ENV['GITHUB_TOKEN'] || ARGV[0])
data/cleangist.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cleangist/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cleangist"
8
+ spec.version = CleanGist::VERSION
9
+ spec.authors = ["Michael Rose"]
10
+ spec.email = ["elementation@gmail.com"]
11
+ spec.description = %q{Helps clean up unwanted gists}
12
+ spec.summary = %q{Helps clean up unwanted gists}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency 'highline'
22
+ spec.add_runtime_dependency 'httparty'
23
+
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency "rake"
27
+ end
data/lib/cleangist.rb ADDED
@@ -0,0 +1,55 @@
1
+ require "cleangist/version"
2
+ require "cleangist/github_api"
3
+
4
+ module CleanGist
5
+ require "highline/import"
6
+
7
+ def self.print_gist_header(gist)
8
+ puts "#{"#"*72}"
9
+ puts "Files: " + gist['files'].map { |k, v| k }.join(',')
10
+ puts "Languages: " + gist['files'].map { |k, v| v['language'] }.join(',')
11
+ puts "Visibility: " + (gist['public'] ? "public" : "secret")
12
+ puts gist['url']
13
+
14
+ if gist['description'].length > 0
15
+ puts "-"*72
16
+ puts " #{gist['description']}"
17
+ end
18
+
19
+ puts "-"*72
20
+ end
21
+
22
+ def self.print_file_contents(api, gist)
23
+ puts api.get_gist((gist['files'].first).last["raw_url"])
24
+ end
25
+
26
+ def self.agree( yes_or_no_question, character = nil )
27
+ ask(yes_or_no_question, lambda { |yn| yn.downcase[0] }) do |q|
28
+ q.responses[:not_valid] = 'Please enter "yes", "no", or "quit".'
29
+ q.responses[:ask_on_error] = :question
30
+ q.character = character
31
+
32
+ yield q if block_given?
33
+ end
34
+ end
35
+
36
+ def self.check_gists(api_key)
37
+ api = GithubApi.new api_key
38
+
39
+ api.with_gists do |gist|
40
+ print_gist_header(gist)
41
+ print_file_contents(api, gist)
42
+
43
+ # y, n, see file, quit
44
+ keep = agree "Keep gist? [y]/n/q "
45
+
46
+ case keep
47
+ when "n"
48
+ api.delete_gist gist['id']
49
+ puts "Removed gist:#{gist['id']}"
50
+ when "q"
51
+ exit!(0)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,28 @@
1
+ require "httparty"
2
+
3
+ class GithubApi
4
+ include HTTParty
5
+ base_uri 'https://api.github.com'
6
+
7
+ def initialize(token)
8
+ self.class.headers 'Authorization' => "token #{token}"
9
+ end
10
+
11
+ def gists()
12
+ self.class.get('/gists')
13
+ end
14
+
15
+ def get_gist(gist_url)
16
+ self.class.get(gist_url)
17
+ end
18
+
19
+ def delete_gist(gist_id)
20
+ self.class.delete("/gists/#{gist_id}")
21
+ end
22
+
23
+ def with_gists()
24
+ gists().each do |gist|
25
+ yield gist
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module CleanGist
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cleangist
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michael Rose
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: highline
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: httparty
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: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.3'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
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
+ description: Helps clean up unwanted gists
79
+ email:
80
+ - elementation@gmail.com
81
+ executables:
82
+ - cleangist
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .gitignore
87
+ - Gemfile
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - bin/cleangist
92
+ - cleangist.gemspec
93
+ - lib/cleangist.rb
94
+ - lib/cleangist/github_api.rb
95
+ - lib/cleangist/version.rb
96
+ homepage: ''
97
+ licenses:
98
+ - MIT
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ segments:
110
+ - 0
111
+ hash: -2788234802300653461
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ segments:
119
+ - 0
120
+ hash: -2788234802300653461
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 1.8.25
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: Helps clean up unwanted gists
127
+ test_files: []