mikedamage-gistr 0.1.0

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/README.textile ADDED
@@ -0,0 +1,19 @@
1
+ h1. Gistr
2
+
3
+ _The *other* Ruby command line gister_
4
+
5
+ by Mike Green
6
+
7
+ h2. Summary
8
+
9
+ I decided to create Gistr after using the pretty schnazzy "Snipplr":http://snipplr.com command line client. The existing "gist.rb":http://github.com/defunkt/gist/tree is cool and I've relied on it as a blueprint for Gistr, but I wanted to include some extra functionality based on the Snipplr gem:
10
+
11
+ * Ability to list your gists, along with descriptions
12
+ * Download a gist to file, STDOUT, or the clipboard
13
+ * Create a new public/private gist from clipboard data
14
+ * Open/edit gists in your editor of choice and transparently update them when you save.
15
+ * Wrap the whole thing up as a Rubygem for easy installation
16
+
17
+ h2. Usage
18
+
19
+ Coming soon
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :minor: 1
3
+ :patch: 0
4
+ :major: 0
data/bin/gistr.rb ADDED
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ require 'optparse'
3
+ require File.join(File.dirname(__FILE__), '../lib/gistr')
4
+
5
+ SUBCOMMANDS = %w(list new get)
6
+ opts = OptionParser.new do |opt|
7
+ opt.banner = <<EOF
8
+ Gistr
9
+ command line gist client for os x
10
+ -------------------------------------
11
+ Usage: gistr [-chvp] action [INPUT]
12
+
13
+ Commands:
14
+ get GIST_ID - Gets specified Gist
15
+
16
+ Options:
17
+ EOF
18
+ opt.on('-c', '--clipboard', "Use the OS X clipboard as input source or output destination, depending on operation.") do
19
+ clipboard = true
20
+ end
21
+ end
22
+
23
+ opts.parse!(ARGV)
24
+
25
+
data/lib/gist.rb ADDED
@@ -0,0 +1,24 @@
1
+ class Gist
2
+
3
+ include Gistr
4
+ attr_accessor :content, :options, :name, :description
5
+
6
+ def initialize(content, options={:filename => "gist.txt", :private => false, :description => nil})
7
+ @content = content
8
+ @options = options
9
+ @name = @options[:filename]
10
+ @private = @options[:private]
11
+ @description = @options[:description]
12
+ end
13
+
14
+ def save
15
+ url = URI.parse($base_uri + '/new')
16
+ files = { "files[#{@name}]" => @content }
17
+ desc = @description ? {'description' => @description} : {}
18
+ priv = @private ? {'private' => 'on'} : {}
19
+ data = files.merge(desc).merge(priv).merge(auth)
20
+ res = Net::HTTP.post_form(url, data)
21
+ return YAML.load(res.body)
22
+ end
23
+
24
+ end
data/lib/gistr.rb ADDED
@@ -0,0 +1,60 @@
1
+ require 'yaml'
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'pathname'
5
+
6
+ module Gistr
7
+ $base_uri = 'http://gist.github.com/api/v1/yaml'
8
+
9
+ def copy(content)
10
+ IO.popen('pbcopy', 'r+') {|clipboard| clipboard.write(content) }
11
+ end
12
+
13
+ def paste
14
+ IO.popen('pbpaste', 'r') {|clipboard| clipboard.read }
15
+ end
16
+
17
+ def auth
18
+ user = `git config --global github.user`.strip
19
+ token = `git config --global github.token`.strip
20
+
21
+ user.empty? ? {} : { :login => user, :token => token }
22
+ end
23
+
24
+ def new_from_clipboard(*args)
25
+ content = paste
26
+ name = args[0] if args.size > 0
27
+ pvt = args[1] if args.size >= 2
28
+ desc = args[2] if args.size >= 3
29
+ name ||= "gist.txt"
30
+ pvt ||= false
31
+ desc ||= nil
32
+ gist = Gist.new(content, :filename => name, :private => pvt, :description => desc)
33
+ response = gist.save
34
+ gist_url = "http://gist.github.com/" + response['gists'][0][:repo]
35
+ copy gist_url
36
+ gist_url
37
+ end
38
+
39
+ def my_gists
40
+ user = auth[:login]
41
+ url = URI.parse($base_uri + '/gists/' + user)
42
+ res = Net::HTTP.start(url.host, url.port) {|http| http.get(url.path) }
43
+ if res.is_a?(Net::HTTPOK)
44
+ return YAML.load(res.body)
45
+ else
46
+ return false
47
+ end
48
+ end
49
+
50
+ def get_gist(id)
51
+ url = URI.parse("http://gist.github.com/" + id.to_s + ".txt")
52
+ res = Net::HTTP.start(url.host, url.port) {|http| http.get(url.path) }
53
+ res.body
54
+ end
55
+
56
+ end
57
+
58
+ Pathname.new(File.dirname(__FILE__)).children.reverse.each do |file|
59
+ require file.to_s unless file.basename.to_s == __FILE__
60
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class GistrTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'mocha'
5
+
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'gistr'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mikedamage-gistr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mike Green
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-02 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Command line client for Github Gists, built for Mac OS X.
17
+ email: mike.is.green@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - README.textile
26
+ - VERSION.yml
27
+ - bin/gistr.rb
28
+ - lib/gist.rb
29
+ - lib/gistr.rb
30
+ - test/gistr_test.rb
31
+ - test/test_helper.rb
32
+ has_rdoc: true
33
+ homepage: http://github.com/mikedamage/gistr
34
+ post_install_message:
35
+ rdoc_options:
36
+ - --inline-source
37
+ - --charset=UTF-8
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ version:
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ requirements: []
53
+
54
+ rubyforge_project:
55
+ rubygems_version: 1.2.0
56
+ signing_key:
57
+ specification_version: 2
58
+ summary: Command line client for Github Gists, built for Mac OS X.
59
+ test_files: []
60
+