-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
151 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
= Pastie - Simple API wrapper to communicate with Pastie.org website | ||
|
||
Pastie gem is a simplified API to communicate with Pastie.org website. | ||
It is based on HTML processing since pastie.org does not provide any API access. | ||
This gem comes as a library and executable file. | ||
All pastes are private by default. | ||
History tracking feature is available from version 0.2.0. | ||
|
||
== Installation | ||
|
||
gem install pastie-api | ||
|
||
== Usage: API | ||
|
||
require 'rubygems' | ||
require 'pastie-api' | ||
|
||
# Create a new private paste | ||
p = Pastie.create('Test string') | ||
|
||
# Create a new public paste | ||
p = Pastie.create('Hello!', false) | ||
|
||
# View paste details | ||
puts "Paste ID: #{p.id}" | ||
puts "Paste Key: #{p.key}" | ||
puts "URL: #{p.link}" | ||
puts "Raw link: #{p.raw_link}" | ||
|
||
# Find existing paste | ||
p = Pastie.get(1234567) # find by paste's ID | ||
p = Pastie.get('abcdefabcdef') # find by paste's private code | ||
|
||
== Usage: Terminal | ||
|
||
Usage: pastie [options] file1 file2 ... fileN | ||
-i, --info Display this information. | ||
-p, --public Paste files as public. | ||
-h, --history Show pastes history. | ||
-c, --clear Clear your pastes history. | ||
|
||
== Authors & Contributors | ||
|
||
Dan Sosedoff, author, github.com/sosedoff | ||
Barry Hess, contributor, github.com/bjhess |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,26 @@ | ||
module Pastie | ||
module Console | ||
# Prompt for input | ||
def ask(title, opts={}) | ||
print("#{title}#{opts.key?(:default) ? " [#{opts[:default]}]" : ''}: ") ; result = gets.strip | ||
result = opts[:default] if result.empty? && opts.key?(:default) | ||
result = result.scan(/[a-z\d\_\-]{1,}/i) if opts.key?(:array) | ||
result.empty? && opts.key?(:required) ? ask(title, opts) : result | ||
end | ||
end | ||
end | ||
|
||
class String | ||
def red; colorize(self, "\e[1m\e[31m"); end | ||
def green; colorize(self, "\e[1m\e[32m"); end | ||
def dark_green; colorize(self, "\e[32m"); end | ||
def yellow; colorize(self, "\e[1m\e[33m"); end | ||
def blue; colorize(self, "\e[1m\e[34m"); end | ||
def dark_blue; colorize(self, "\e[34m"); end | ||
def purple; colorize(self, "\e[1m\e[35m"); end | ||
def magenta; colorize(self, "\e[1m\e[36m"); end | ||
def colorize(text, color_code) ; "#{color_code}#{text}\e[0m" ; end | ||
def colorize(text, color_code) | ||
"#{color_code}#{text}\e[0m" | ||
end | ||
|
||
def red; colorize(self, "\e[1m\e[31m"); end | ||
def green; colorize(self, "\e[1m\e[32m"); end | ||
def dark_green; colorize(self, "\e[32m"); end | ||
def yellow; colorize(self, "\e[1m\e[33m"); end | ||
def blue; colorize(self, "\e[1m\e[34m"); end | ||
def dark_blue; colorize(self, "\e[34m"); end | ||
def purple; colorize(self, "\e[1m\e[35m"); end | ||
def magenta; colorize(self, "\e[1m\e[36m"); end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module Pastie | ||
module Share | ||
# Email configuration file location | ||
def email_file | ||
"#{ENV['HOME']}/.pastie_email" | ||
end | ||
|
||
# Load configuration | ||
def email_config | ||
YAML.load(File.read(email_file)) | ||
end | ||
|
||
# Configure local email sharer | ||
def configure_email | ||
config = { | ||
:username => ask('Gmail', :required => true), | ||
:password => ask('Password', :required => true) | ||
} | ||
File.open(email_file, 'w') { |f| f.write(YAML.dump(config)) } | ||
end | ||
|
||
# Share link | ||
def share(links, email) | ||
unless File.exists?(email_file) | ||
configure_email | ||
end | ||
|
||
config = email_config | ||
|
||
begin | ||
Pony.mail( | ||
:from => config[:username], | ||
:to => email, | ||
:subject => "Pastie.org - New paste!", | ||
:body => links.join("\r\n"), | ||
:via => :smtp, | ||
:via_options => { | ||
:address => 'smtp.gmail.com', | ||
:port => '587', | ||
:enable_starttls_auto => true, | ||
:user_name => config[:username], | ||
:password => config[:password], | ||
:authentication => :plain, | ||
:domain => "localhost.localdomain" | ||
} | ||
) | ||
rescue Net::SMTPAuthenticationError | ||
puts "Invalid username or password!".red | ||
rescue Exception => ex | ||
puts "Uncaught exception: #{ex.inspect}".red | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters