jist 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.
Files changed (2) hide show
  1. data/lib/jist.rb +55 -0
  2. metadata +61 -0
@@ -0,0 +1,55 @@
1
+ require 'net/http'
2
+ require 'multi_json'
3
+
4
+ # It just gists.
5
+ module Jist
6
+
7
+ module_function
8
+ # Upload a gist to https://gist.github.com/
9
+ #
10
+ # @param content the code you'd like to gist
11
+ #
12
+ # @option :description the description
13
+ # @option :filename the filename (default 'a.rb')
14
+ # @option :public to make it a public gist (default private)
15
+ # @option :username if you wish to log in to github
16
+ # @option :password (required if username is set)
17
+ #
18
+ # @return Hash the decoded JSON response from the server
19
+ # @raise Exception if something went wrong
20
+ def gist(content, options={})
21
+ json = {}
22
+
23
+ json[:description] = options[:description] if options[:description]
24
+ json[:public] = !!options[:public]
25
+
26
+ filename = options[:filename] || 'a.rb'
27
+
28
+ json[:files] = {
29
+ filename => {
30
+ :content => content
31
+ }
32
+ }
33
+
34
+ connection = Net::HTTP.new("api.github.com", 443)
35
+ connection.use_ssl = true
36
+ connection.read_timeout = 10
37
+
38
+ request = Net::HTTP::Post.new("/gists")
39
+ request.body = MultiJson.encode(json)
40
+
41
+ if options[:username]
42
+ request.basic_auth(options[:username], options[:password])
43
+ end
44
+
45
+ response = connection.start do |http|
46
+ http.request(request)
47
+ end
48
+
49
+ if Net::HTTPCreated === response
50
+ MultiJson.decode(response.body)
51
+ else
52
+ raise RuntimeError.new "Got #{response.class} from gist: #{response.body}"
53
+ end
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jist
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Conrad Irwin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: multi_json
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
+ description: Provides a single function (Jist.gist) that uploads a gist.
31
+ email: conrad.irwin@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - lib/jist.rb
37
+ homepage: https://github.com/ConradIrwin/jist
38
+ licenses: []
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 1.8.19
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: Just allows you to upload gists
61
+ test_files: []