pasting 0.0.2
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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/bin/pasting +113 -0
- data/lib/pasting.rb +135 -0
- data/lib/pasting/version.rb +3 -0
- data/pasting.gemspec +25 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c84025b7272dddaab384dacec167a2ae723b2e30
|
4
|
+
data.tar.gz: be149daa1ddbff03679c80973515eadd9aad4d6a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 70c885417083c0a203b4b61a1f2db16ba3ca9cc0ab05ce74401b811669080dd9459b32273114a6af869a50c023644cdee6be171582149dc6b26b2d61da29df05
|
7
|
+
data.tar.gz: 8282a8cd6914ab5e2a41e0e36d521ffdedf0ae0d0dd5c729f3a6142c412904ab7148fbabfdac22a923449de27ae783acc7c690e5f51ae0955fdb6dbcf149f2c2
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Facundo Guerrero
|
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,31 @@
|
|
1
|
+
# Pasting
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'pasting'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install pasting
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/pasting/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/pasting
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Silence Ctrl-C's
|
4
|
+
trap('INT'){ exit 1 }
|
5
|
+
|
6
|
+
require 'optparse'
|
7
|
+
require 'pasting'
|
8
|
+
|
9
|
+
# For the holdings of options.
|
10
|
+
options = {}
|
11
|
+
filenames = []
|
12
|
+
|
13
|
+
|
14
|
+
OptionParser.new do |opts|
|
15
|
+
executable_name = File.split($0)[1]
|
16
|
+
opts.banner = <<-EOS
|
17
|
+
Pasting (v#{Pasting::VERSION}) lets you upload to https://Pasting.io/
|
18
|
+
|
19
|
+
The content to be uploaded can be passed as a list of files, if none are
|
20
|
+
specified STDIN will be read. The default filename for STDIN is "a.rb", and all
|
21
|
+
filenames can be overridden by repeating the "-f" flag. The most useful reason
|
22
|
+
to do this is to change the syntax highlighting.
|
23
|
+
|
24
|
+
If you'd like your Pastings to be associated with your GitHub account, so that you
|
25
|
+
can edit them and find them in future, first use `Pasting --login` to obtain an
|
26
|
+
Oauth2 access token. This is stored and used by Pasting in the future.
|
27
|
+
|
28
|
+
Private Pastings do not have guessable URLs and can be created with "-p", you can
|
29
|
+
also set the description at the top of the Pasting by passing "-d".
|
30
|
+
|
31
|
+
Anonymous Pastings are not associated with your GitHub account, they can be created
|
32
|
+
with "-a" even after you have used "Pasting --login".
|
33
|
+
|
34
|
+
If you would like to shorten the resulting Pasting URL, use the -s flag. This will
|
35
|
+
use GitHub's URL shortener, git.io. You can also use -R to get the link to the
|
36
|
+
raw Pasting.
|
37
|
+
|
38
|
+
To copy the resulting URL to your clipboard you can use the -c option, or to
|
39
|
+
just open it directly in your browser, use -o. Using the -e option will copy the
|
40
|
+
embeddable URL to the clipboard. You can add `alias Pasting='Pasting -c'` to your
|
41
|
+
shell's rc file to configure this behaviour by default.
|
42
|
+
|
43
|
+
Instead of creating a new Pasting, you can update an existing one by passing its ID
|
44
|
+
or URL with "-u". For this to work, you must be logged in, and have created the
|
45
|
+
original Pasting with the same GitHub account.
|
46
|
+
|
47
|
+
Usage: cat file.txt | #{executable_name}
|
48
|
+
#{executable_name} --login
|
49
|
+
|
50
|
+
EOS
|
51
|
+
|
52
|
+
opts.on("--login", "Authenticate Pasting on this computer.") do
|
53
|
+
Pasting.login
|
54
|
+
exit
|
55
|
+
end
|
56
|
+
|
57
|
+
opts.on("-p", "--private", "Makes your Pasting private.") do
|
58
|
+
options[:private] = true
|
59
|
+
end
|
60
|
+
|
61
|
+
opts.on_tail("-h","--help", "Show this message.") do
|
62
|
+
puts opts
|
63
|
+
exit
|
64
|
+
end
|
65
|
+
|
66
|
+
opts.on_tail("-v", "--version", "Print the version.") do
|
67
|
+
puts "pasting v#{Pasting::VERSION}"
|
68
|
+
exit
|
69
|
+
end
|
70
|
+
|
71
|
+
end.parse!
|
72
|
+
|
73
|
+
begin
|
74
|
+
stdin = ARGF.read
|
75
|
+
options[:output] = if options[:embed] && options[:shorten]
|
76
|
+
raise Pasting::Error, "--embed does not make sense with --shorten"
|
77
|
+
elsif options[:embed]
|
78
|
+
:javascript
|
79
|
+
elsif options[:shorten] and options[:raw]
|
80
|
+
:short_raw_url
|
81
|
+
elsif options[:shorten]
|
82
|
+
:short_url
|
83
|
+
elsif options[:raw]
|
84
|
+
:raw_url
|
85
|
+
else
|
86
|
+
:html_url
|
87
|
+
end
|
88
|
+
|
89
|
+
if options[:paste]
|
90
|
+
puts Pasting.Pasting(Pasting.paste, stdin)
|
91
|
+
else
|
92
|
+
to_read = ARGV.empty? ? ['-'] : ARGV
|
93
|
+
files = {}
|
94
|
+
to_read.zip(filenames).each do |(file, name)|
|
95
|
+
files[name || file] =
|
96
|
+
begin
|
97
|
+
if file == '-'
|
98
|
+
$stderr.puts "(type a Pasting. <ctrl-c> to cancel, <ctrl-d> when done)" if $stdin.tty?
|
99
|
+
STDIN.read
|
100
|
+
else
|
101
|
+
File.read(File.expand_path(file))
|
102
|
+
end
|
103
|
+
rescue => e
|
104
|
+
raise e.extend(Pasting::Error)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
Pasting.paste(stdin)
|
108
|
+
end
|
109
|
+
|
110
|
+
rescue Pasting::Error => e
|
111
|
+
puts "Error: #{e.message}"
|
112
|
+
exit 1
|
113
|
+
end
|
data/lib/pasting.rb
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'cgi'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'json'
|
7
|
+
rescue LoadError
|
8
|
+
require File.join File.dirname(File.dirname(__FILE__)), 'vendor', 'json.rb'
|
9
|
+
end
|
10
|
+
|
11
|
+
module Pasting
|
12
|
+
extend self
|
13
|
+
|
14
|
+
VERSION = '1.0.0'
|
15
|
+
|
16
|
+
PASTING_API_URL = URI.encode("http://api.pasting.io/".strip)
|
17
|
+
|
18
|
+
PASTING_BASE_PATH = "/"
|
19
|
+
|
20
|
+
USER_AGENT = "pasting/#{VERSION} (Net::HTTP, #{RUBY_DESCRIPTION})"
|
21
|
+
|
22
|
+
# Exception tag for errors raised while gisting.
|
23
|
+
module Error;
|
24
|
+
def self.exception(*args)
|
25
|
+
RuntimeError.new(*args).extend(self)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
class ClipboardError < RuntimeError; include Error end
|
29
|
+
|
30
|
+
# helper module for authentication token actions
|
31
|
+
module AuthTokenFile
|
32
|
+
def self.filename
|
33
|
+
File.expand_path "~/.pastingKey"
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.read
|
37
|
+
File.read(filename).chomp
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.write(token)
|
41
|
+
File.open(filename, 'w', 0600) do |f|
|
42
|
+
f.write token
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# auth token for authentication
|
48
|
+
#
|
49
|
+
# @return [String] string value of access token or `nil`, if not found
|
50
|
+
def auth_token
|
51
|
+
@token ||= AuthTokenFile.read rescue nil
|
52
|
+
end
|
53
|
+
|
54
|
+
def pasting_post(post_uri, body)
|
55
|
+
uri = URI.parse(api_url)
|
56
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
57
|
+
request = Net::HTTP::Post.new(post_uri)
|
58
|
+
request.add_field('Content-Type', 'application/json')
|
59
|
+
request.body = body.to_json
|
60
|
+
response = http.request(request)
|
61
|
+
response
|
62
|
+
end
|
63
|
+
|
64
|
+
def login
|
65
|
+
print "Pasting username: "
|
66
|
+
username = $stdin.gets.strip
|
67
|
+
print "Pasting password: "
|
68
|
+
password = $stdin.gets.strip
|
69
|
+
body = {:username => username, :pwd => password}
|
70
|
+
response = pasting_post('/createConsoleKey', body)
|
71
|
+
if Net::HTTPSuccess === response
|
72
|
+
json = JSON.parse(response.body)
|
73
|
+
if json['st'] == 'error'
|
74
|
+
puts json['msg']
|
75
|
+
else
|
76
|
+
AuthTokenFile.write(json['console_key'])
|
77
|
+
end
|
78
|
+
else
|
79
|
+
puts "Fail to register"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# Upload a paste to http://pasting.io
|
84
|
+
#
|
85
|
+
# @param [String] content the code you'd like to paste
|
86
|
+
#
|
87
|
+
# @see http://pasting.io/
|
88
|
+
def paste(content, options = {})
|
89
|
+
|
90
|
+
body = {:consoleKey => auth_token, :text => content }
|
91
|
+
uri = URI.parse(api_url)
|
92
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
93
|
+
request = Net::HTTP::Post.new("/createFromConsole")
|
94
|
+
request.add_field('Content-Type', 'application/json')
|
95
|
+
request.body = body.to_json
|
96
|
+
response = http.request(request)
|
97
|
+
|
98
|
+
if Net::HTTPSuccess === response
|
99
|
+
messsage = on_success(response.body)
|
100
|
+
puts "#{messsage}"
|
101
|
+
begin
|
102
|
+
IO.popen('pbcopy', 'r+') { |clip| clip.print messsage }
|
103
|
+
rescue
|
104
|
+
puts
|
105
|
+
end
|
106
|
+
else
|
107
|
+
puts "Fail to register, please check user and password"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
# Called after an HTTP response to gist to perform post-processing.
|
113
|
+
#
|
114
|
+
# @param [String] body the text body from the github api
|
115
|
+
# @param [Hash] options more detailed options, see
|
116
|
+
# the documentation for {multi_gist}
|
117
|
+
def on_success(body, options={})
|
118
|
+
json = JSON.parse(body)
|
119
|
+
|
120
|
+
output = "http://pasting.io/p/#{json["documentId"]}"
|
121
|
+
|
122
|
+
output
|
123
|
+
end
|
124
|
+
|
125
|
+
# Get the API base path
|
126
|
+
def base_path
|
127
|
+
PASTING_BASE_PATH
|
128
|
+
end
|
129
|
+
|
130
|
+
# Get the API URL
|
131
|
+
def api_url
|
132
|
+
PASTING_API_URL
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
data/pasting.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pasting/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "pasting"
|
8
|
+
spec.version = Pasting::VERSION
|
9
|
+
spec.authors = ["Facundo Guerrero"]
|
10
|
+
spec.email = ["guerremdq@gmail.com"]
|
11
|
+
spec.summary = "pasting.io client"
|
12
|
+
spec.description = "Command line tool to generate new paste on pasting.io"
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.executables << 'pasting'
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0")
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pasting
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Facundo Guerrero
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Command line tool to generate new paste on pasting.io
|
42
|
+
email:
|
43
|
+
- guerremdq@gmail.com
|
44
|
+
executables:
|
45
|
+
- pasting
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- lib/pasting.rb
|
55
|
+
- lib/pasting/version.rb
|
56
|
+
- pasting.gemspec
|
57
|
+
- bin/pasting
|
58
|
+
homepage: ''
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.0.14
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: pasting.io client
|
82
|
+
test_files: []
|