thefox-pastebin 1.2.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a09e8b5e53795d202a2734db32742ad8351191fa
4
+ data.tar.gz: 367fe94608cc4d05999f52133b412fad643551d5
5
+ SHA512:
6
+ metadata.gz: b339c442e62567948c240a708533919a8428d637220d54452a61f3f697e3feba331063c63bac5ba78889f7cd981de12c61645b91005e28b051a007e84ad9e2ee
7
+ data.tar.gz: 2ccf5088abcd131c8e24cba4c1fa546635e4b46f5475cef79a940c13e102723a41f033d9a40c1db604196177f56e9bfb906d2eabb7497646c7afca5434ad247d
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .setup
2
+ CHANGELOG-*.txt
3
+ /releases/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+
2
+ source 'https://rubygems.org'
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ thefox-pastebin (1.2.0.pre.dev)
5
+ dotenv (~> 2.0)
6
+ highline (~> 1.7)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ dotenv (2.0.2)
12
+ highline (1.7.8)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ bundler (~> 1.10)
19
+ thefox-pastebin!
20
+
21
+ BUNDLED WITH
22
+ 1.10.2
data/Makefile ADDED
@@ -0,0 +1,4 @@
1
+
2
+ GEM_NAME = thefox-pastebin
3
+
4
+ include Makefile.common
data/Makefile.common ADDED
@@ -0,0 +1,50 @@
1
+
2
+ # Ruby Common Big
3
+ # 2015-12-07
4
+
5
+ MV = mv -nv
6
+ RM = rm -rf
7
+ MKDIR = mkdir -p
8
+ BUNDLER = bundle
9
+ GEMSPEC_FILE = $(GEM_NAME).gemspec
10
+
11
+ .PHONY: all
12
+ all: setup
13
+
14
+ .PHONY: setup
15
+ setup: .setup
16
+
17
+ .setup:
18
+ $(BUNDLER) install
19
+ touch $@
20
+
21
+ .PHONY: install
22
+ install:
23
+ gem_file=$$(gem build $(GEMSPEC_FILE) | grep 'File:' | tail -1 | awk '{ print $$2 }'); \
24
+ sudo gem install $$gem_file; \
25
+ $(RM) $$gem_file
26
+
27
+ .PHONY: uninstall
28
+ uninstall:
29
+ sudo gem uninstall $(GEM_NAME)
30
+
31
+ .PHONY: update
32
+ update:
33
+ $(BUNDLER) update
34
+
35
+ .PHONY: clean
36
+ clean:
37
+ $(RM) .setup
38
+
39
+ .PHONY: release
40
+ release: | releases
41
+ set -e; \
42
+ gem_file=$$(gem build $(GEMSPEC_FILE) | grep 'File:' | tail -1 | awk '{ print $$2 }'); \
43
+ dst="releases/$$gem_file"; \
44
+ [ ! -f $$dst ]; \
45
+ $(MV) $$gem_file releases; \
46
+ gem push $$dst; \
47
+ echo 'done'
48
+
49
+ releases:
50
+ $(MKDIR) $@
data/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # Pastebin
2
+
3
+ Command line interface for [Pastebin.com](https://pastebin.com/).
4
+
5
+ Just another Pastebin.com CLI script, but you can even login with your user account.
6
+
7
+ ## Install
8
+
9
+ The preferred method of installation is via RubyGems.org:
10
+ <https://rubygems.org/gems/thefox-pastebin>
11
+
12
+ gem install thefox-pastebin
13
+
14
+ or via `Gemfile`:
15
+
16
+ gem 'thefox-pastebin', '~>1.2'
17
+
18
+ Use it in your sources:
19
+
20
+ require 'thefox-pastebin'
21
+
22
+ ## Usage
23
+
24
+ Unless you are using `-f` the default input is [STDIN](https://en.wikipedia.org/wiki/Standard_streams).
25
+
26
+ ### Help
27
+
28
+ pastebin -h
29
+
30
+ ### Skel example
31
+
32
+ pastebin --skel
33
+
34
+ The default settings file is under `~/.pastebinrc`. You need to create it by yourself.
35
+
36
+ ### Create a settings file
37
+
38
+ pastebin --skel > ~/.pastebinrc
39
+
40
+ ### Print default settings
41
+
42
+ pastebin -D
43
+
44
+ ### Use a different settings file
45
+
46
+ pastebin -c ~/.pastebinrc_user2
47
+
48
+ ### Set a name for a paste
49
+
50
+ pastebin -n 'hello world'
51
+
52
+ ### Set an expiration date for a paste (10 minutes)
53
+
54
+ pastebin -e 10m
55
+
56
+ ### Set a format/language for a paste (PHP)
57
+
58
+ pastebin -l php
59
+
60
+ ### Paste a specific file
61
+
62
+ pastebin -f file.txt
63
+
64
+ ### Create an unlisted paste
65
+
66
+ pastebin -u
67
+
68
+ ### Create a private paste
69
+
70
+ pastebin -p
71
+
72
+ ### Get the raw contents of a paste
73
+
74
+ pastebin -r <ID>
75
+
76
+ ### Login
77
+
78
+ As a registered pastebin.com user you can login and let `pastebin` create pastes on behalf of you. You need to enter your username and password. The login credentials are not stored to any configuration file or anywhere else.
79
+
80
+ pastebin --login
81
+
82
+ After a successfull login you need to add the `API_USER_KEY=` line to your settings file (`~/.pastebinrc`). This user key is associated to your pastebin.com user.
83
+
84
+ You can also use your own Developer API Key. See [pastebin.com API documentation](https://pastebin.com/api) for more details.
85
+
86
+ ### Examples
87
+
88
+ - `pastebin -n hello_world -e 10m -f hello_world.txt`
89
+ - `pastebin -n 'PHP Script' -l php -f login.php`
90
+ - `pastebin -u -e 1m -l php -f test.php`
91
+ - `pastebin -n 'Collect Script' -p -e 10m -l awk -f collect.awk`
92
+ - `pastebin -r UJwPUmKp`
93
+ - `cat /tmp/hello_world.txt | pastebin`
94
+
95
+ ## License
96
+ Copyright (C) 2015 Christian Mayer <http://fox21.at>
97
+
98
+ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
99
+
100
+ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
data/bin/pastebin ADDED
@@ -0,0 +1,153 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: UTF-8
3
+
4
+ require 'bundler/setup'
5
+ require 'dotenv'
6
+ require 'pastebin'
7
+ require 'highline/import'
8
+
9
+ rc_path = "#{ENV['HOME']}/.pastebinrc" # runtime configuration
10
+ raw_id = nil
11
+ is_login_mode = false
12
+ is_raw_mode = false
13
+ is_skel_mode = false
14
+ is_defaults_mode = false
15
+
16
+ options = {}
17
+
18
+ opts = OptionParser.new do |opts|
19
+ opts.banner =<<EOB
20
+ Pastebin is a CLI to https://pastebin.com
21
+ Usage: pastebin [options]
22
+
23
+ Examples:
24
+ pastebin -f foo.rb -n rub_script -l ruby -e 10m
25
+ cat foo.rb | pastebin -l ruby
26
+ EOB
27
+
28
+ opts.separator('')
29
+ opts.separator('Options:')
30
+
31
+ opts.on('-c <file>', '--config <file>', String, "Used config file.", "Default: #{rc_path}") do |f|
32
+ rc_path = f
33
+ end
34
+
35
+ opts.on('-f <file>', '--file <file>', String, "Use a file for input, '-' for STDIN.") do |f|
36
+ options["api_paste_code"] = f
37
+ end
38
+
39
+ opts.on('-n', '--name <name>', String, 'Assign a name to your paste.') do |n|
40
+ options['api_paste_name'] = n
41
+ end
42
+
43
+ expire_a = ['n', '10m', '1h', '1d', '1m']
44
+ expire_s = expire_a.join(', ')
45
+ opts.on('-e', '--expire <time>', expire_a, 'These can be abbriviated, as long as they are unambigous.', "#{expire_s}", 'Default: n (never)' ) do |e|
46
+ options['api_paste_expire_date'] = e.upcase
47
+ end
48
+
49
+ opts.on('-l', '--language <syntax>', String, "See https://pastebin.com/api - The 'api_paste_format' Paramater.") do |l|
50
+ options['api_paste_format'] = l
51
+ end
52
+
53
+ opts.on('-u', '--unlisted', 'Make paste unlisted. (API_PASTE_PRIVATE=1)') do
54
+ options['api_paste_private'] = '1'
55
+ end
56
+
57
+ opts.on('-p', '--private', 'Make paste private. (API_PASTE_PRIVATE=2)') do
58
+ options['api_paste_private'] = '2'
59
+ end
60
+
61
+ opts.on('-r', '--raw <link>', String, 'Return raw text from a paste link.') do |r|
62
+ is_raw_mode = true
63
+ raw_id = r
64
+ end
65
+
66
+ opts.on_tail(nil, '--login', 'Login on pastebin.com with your user credentials.') do
67
+ is_login_mode = true
68
+ end
69
+
70
+ opts.on_tail(nil, '--skel', 'Print a basic example configuration.') do
71
+ is_skel_mode = true
72
+ end
73
+
74
+ opts.on('-D', '--defaults', String, 'Print defaults.') do |r|
75
+ is_defaults_mode = true
76
+ end
77
+
78
+ opts.on_tail('--version', 'Show version.') do
79
+ puts "#{TheFox::Pastebin::NAME} #{TheFox::Pastebin::VERSION} (#{TheFox::Pastebin::DATE})"
80
+ puts TheFox::Pastebin::HOMEPAGE
81
+ exit
82
+ end
83
+
84
+ opts.on_tail('-h', '--help', 'Show this message.') do
85
+ puts opts
86
+ exit 3
87
+ end
88
+ end
89
+
90
+ opts.parse(ARGV)
91
+
92
+ if File.exist?(rc_path)
93
+ Dotenv.load(rc_path)
94
+ end
95
+
96
+ if ENV.has_key?('API_DEV_KEY') && ENV['API_DEV_KEY'] != ''
97
+ options['api_dev_key'] = ENV['API_DEV_KEY']
98
+ end
99
+ if ENV.has_key?('API_USER_KEY') && ENV['API_USER_KEY'] != ''
100
+ options['api_user_key'] = ENV['API_USER_KEY']
101
+ end
102
+ if !options.has_key?('api_paste_expire_date') && ENV.has_key?('API_PASTE_EXPIRE_DATE') && ENV['API_PASTE_EXPIRE_DATE'] != ''
103
+ options['api_paste_expire_date'] = ENV['API_PASTE_EXPIRE_DATE'].upcase
104
+ end
105
+ if !options.has_key?('api_paste_format') && ENV.has_key?('API_PASTE_FORMAT') && ENV['API_PASTE_FORMAT'] != ''
106
+ options['api_paste_format'] = ENV['API_PASTE_FORMAT']
107
+ end
108
+ if !options.has_key?('api_paste_private') && ENV.has_key?('API_PASTE_PRIVATE') && ENV['API_PASTE_PRIVATE'] != ''
109
+ options['api_paste_private'] = ENV['API_PASTE_PRIVATE']
110
+ end
111
+ if ENV.has_key?('NAME_PREFIX') && ENV['NAME_PREFIX'] != ''
112
+ options['name_prefix'] = ENV['NAME_PREFIX']
113
+ end
114
+ if ENV.has_key?('NAME_POSTFIX') && ENV['NAME_POSTFIX'] != ''
115
+ options['name_postfix'] = ENV['NAME_POSTFIX']
116
+ end
117
+
118
+ pastebin = TheFox::Pastebin::Pastebin.new(options)
119
+
120
+ begin
121
+ if is_login_mode
122
+ api_user_name = ask('Username: ') do |q|
123
+ q.validate = /^./
124
+ end
125
+ api_user_password = ask('Password: ') do |q|
126
+ q.echo = '*'
127
+ q.validate = /^./
128
+ end
129
+
130
+ api_user_key = pastebin.login(api_user_name, api_user_password)
131
+
132
+ puts
133
+ puts 'Login OK.'
134
+ puts
135
+ puts "Now you need to set your key to '#{rc_path}'."
136
+ puts 'Like this:'
137
+ puts "API_USER_KEY=#{api_user_key}"
138
+ puts
139
+ elsif is_raw_mode
140
+ if !raw_id.nil?
141
+ print pastebin.raw(raw_id)
142
+ end
143
+ elsif is_skel_mode
144
+ pastebin.print_skel
145
+ elsif is_defaults_mode
146
+ pastebin.print_defaults
147
+ else
148
+ puts pastebin.paste
149
+ end
150
+ rescue Exception => e
151
+ puts "ERROR: #{e}"
152
+ exit 1
153
+ end
data/bin/test ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ puts 'cwd: ' + Dir.pwd
4
+
5
+ #require 'bundler/setup'
6
+
7
+
8
+
9
+
10
+
11
+ require 'rubygems'
12
+ #require 'dotenv'
13
+
14
+ gem 'pastebin'
15
+
16
+ puts
17
+ puts $:.join("\n")
18
+ puts
19
+
20
+
21
+
22
+
23
+
data/lib/pastebin.rb ADDED
@@ -0,0 +1,3 @@
1
+
2
+ require 'pastebin/version'
3
+ require 'pastebin/pastebin'
@@ -0,0 +1,109 @@
1
+
2
+ require 'net/http'
3
+ require 'uri'
4
+
5
+ module TheFox
6
+ module Pastebin
7
+
8
+ class Pastebin
9
+
10
+ API_DEV_KEY = 'd46f57321035e4a1eba3ce9b1a70d3cd'
11
+
12
+ def initialize(options = {})
13
+ if options.nil?
14
+ options = {}
15
+ else
16
+ @options = options
17
+ end
18
+
19
+ if !@options.has_key?('api_dev_key')
20
+ @options['api_dev_key'] = API_DEV_KEY
21
+ end
22
+ if !@options.has_key?('api_paste_expire_date')
23
+ @options['api_paste_expire_date'] = 'N'
24
+ end
25
+ if !@options.has_key?('api_paste_private')
26
+ @options['api_paste_private'] = '0'
27
+ end
28
+
29
+ @name_prefix = ''
30
+ if @options.has_key?('name_prefix')
31
+ @name_prefix = @options['name_prefix']
32
+ end
33
+ @name_postfix = ''
34
+ if @options.has_key?('name_postfix')
35
+ @name_postfix = @options['name_postfix']
36
+ end
37
+
38
+ if @options.has_key?('api_paste_name') && @options['api_paste_name'] != '' && (@name_prefix != '' || @name_postfix != '')
39
+ @options['api_paste_name'] = "#{@name_prefix}#{@options['api_paste_name']}#{@name_postfix}"
40
+ end
41
+ end
42
+
43
+ def login(username, password)
44
+ @options['api_user_name'] = username
45
+ @options['api_user_password'] = password
46
+
47
+ uri = URI.parse('https://pastebin.com/api/api_login.php')
48
+ res = Net::HTTP.post_form(uri, @options)
49
+
50
+ if res.code.to_i == 200
51
+ if /^[a-f0-9]{32}$/.match(res.body)
52
+ return res.body
53
+ end
54
+ end
55
+
56
+ raise res.body
57
+ end
58
+
59
+ def paste
60
+ @options['api_option'] = 'paste'
61
+
62
+ if @options.has_key?('api_paste_code')
63
+ if @options['api_paste_code'] == '-'
64
+ @options['api_paste_code'] = STDIN.read
65
+ else
66
+ File.open(@options['api_paste_code']) do |file|
67
+ @options['api_paste_code'] = file.read
68
+ end
69
+ end
70
+ else
71
+ @options['api_paste_code'] = STDIN.read
72
+ end
73
+
74
+ if @options.has_key?('api_paste_code') && @options['api_paste_code']
75
+ uri = URI.parse('https://pastebin.com/api/api_post.php')
76
+ return Net::HTTP.post_form(uri, @options).body
77
+ else
78
+ raise 'no code to paste'
79
+ end
80
+ end
81
+
82
+ def raw(id)
83
+ uri = URI.parse("https://pastebin.com/raw.php?i=#{id}")
84
+ Net::HTTP.get_response(uri).body
85
+ end
86
+
87
+ def print_skel
88
+ puts "API_DEV_KEY=#{API_DEV_KEY}"
89
+ puts 'API_USER_KEY='
90
+ puts 'API_PASTE_EXPIRE_DATE=n'
91
+ puts 'API_PASTE_FORMAT='
92
+ puts 'API_PASTE_PRIVATE=2'
93
+ puts 'NAME_PREFIX='
94
+ puts 'NAME_POSTFIX='
95
+ end
96
+
97
+ def print_defaults
98
+ puts "API_DEV_KEY=#{@options['api_dev_key']}"
99
+ puts "API_USER_KEY=#{@options['api_user_key']}"
100
+ puts "API_PASTE_EXPIRE_DATE=#{@options['api_paste_expire_date']}"
101
+ puts "API_PASTE_FORMAT=#{@options['api_paste_format']}"
102
+ puts "API_PASTE_PRIVATE=#{@options['api_paste_private']}"
103
+ puts "NAME_PREFIX=#{@name_prefix}"
104
+ puts "NAME_POSTFIX=#{@name_postfix}"
105
+ end
106
+ end
107
+
108
+ end
109
+ end
@@ -0,0 +1,9 @@
1
+
2
+ module TheFox
3
+ module Pastebin
4
+ NAME = 'Pastebin'
5
+ VERSION = '1.2.0'
6
+ DATE = '2015-12-07'
7
+ HOMEPAGE = 'https://github.com/TheFox/pastebin'
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ {
2
+ "folders":[
3
+ {
4
+ "path": ".",
5
+ "name": "Pastebin",
6
+ "folder_exclude_patterns": [ ],
7
+ "file_exclude_patterns": [ ]
8
+ }
9
+ ]
10
+ }
@@ -0,0 +1,30 @@
1
+ # coding: UTF-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'pastebin/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'thefox-pastebin'
10
+ spec.version = TheFox::Pastebin::VERSION
11
+ spec.date = TheFox::Pastebin::DATE
12
+ spec.author = 'Christian Mayer'
13
+ spec.email = 'christian@fox21.at'
14
+
15
+ spec.summary = %q{Pastebin.com CLI}
16
+ spec.description = %q{Just another Pastebin.com CLI script, but you can even login with your user account.}
17
+ spec.homepage = TheFox::Pastebin::HOMEPAGE
18
+ spec.license = 'GPL-3.0'
19
+
20
+ spec.files = `git ls-files -z`.split("\x0").reject{ |f| f.match(%r{^(test|spec|features)/}) }
21
+ spec.bindir = 'bin'
22
+ spec.executables = ['pastebin']
23
+ spec.require_paths = ['lib']
24
+ spec.required_ruby_version = '>=2.2.0'
25
+
26
+ spec.add_development_dependency 'bundler', '~>1.10'
27
+
28
+ spec.add_dependency 'dotenv', '~>2.0'
29
+ spec.add_dependency 'highline', '~>1.7'
30
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thefox-pastebin
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Christian Mayer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-07 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dotenv
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: highline
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ description: Just another Pastebin.com CLI script, but you can even login with your
56
+ user account.
57
+ email: christian@fox21.at
58
+ executables:
59
+ - pastebin
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - Makefile
67
+ - Makefile.common
68
+ - README.md
69
+ - bin/pastebin
70
+ - bin/test
71
+ - lib/pastebin.rb
72
+ - lib/pastebin/pastebin.rb
73
+ - lib/pastebin/version.rb
74
+ - pastebin.sublime-project
75
+ - thefox-pastebin.gemspec
76
+ homepage: https://github.com/TheFox/pastebin
77
+ licenses:
78
+ - GPL-3.0
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 2.2.0
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.4.7
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Pastebin.com CLI
100
+ test_files: []
101
+ has_rdoc: