mirror of
https://github.com/seejohnrun/haste-client.git
synced 2025-12-16 16:51:29 +00:00
Compare commits
14 Commits
v0.2.2
...
fix-codeow
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6170ad7de6 | ||
|
|
06d4afb1ca | ||
|
|
eeede13a3c | ||
|
|
6e9801e547 | ||
|
|
fb77a2e9f5 | ||
|
|
baeeb2874a | ||
|
|
32c4523e1c | ||
|
|
c307e8c904 | ||
|
|
1037d899b9 | ||
|
|
b5aa8fbacc | ||
|
|
1f3318adeb | ||
|
|
4c0e5f311d | ||
|
|
dab2d08f42 | ||
|
|
0ea5e5c61c |
1
.github/CODEOWNERS
vendored
Normal file
1
.github/CODEOWNERS
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
* @toptal/site-acquisition-eng
|
||||||
30
.github/workflows/close-inactive.yaml
vendored
Normal file
30
.github/workflows/close-inactive.yaml
vendored
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
name: Close inactive issues and PRs
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
schedule:
|
||||||
|
- cron: "30 1 * * *"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
close-stale:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
issues: write
|
||||||
|
pull-requests: write
|
||||||
|
steps:
|
||||||
|
- uses: actions/stale@v3
|
||||||
|
with:
|
||||||
|
days-before-stale: 30
|
||||||
|
days-before-close: 14
|
||||||
|
stale-issue-label: "stale"
|
||||||
|
stale-pr-label: "stale"
|
||||||
|
|
||||||
|
exempt-issue-labels: backlog,triage,nostale
|
||||||
|
exempt-pr-labels: backlog,triage,nostale
|
||||||
|
|
||||||
|
stale-pr-message: "This PR is stale because it has been open for 30 days with no activity."
|
||||||
|
close-pr-message: "This PR was closed because it has been inactive for 14 days since being marked as stale."
|
||||||
|
|
||||||
|
stale-issue-message: "This issue is stale because it has been open for 30 days with no activity."
|
||||||
|
close-issue-message: "This issue was closed because it has been inactive for 14 days since being marked as stale."
|
||||||
|
|
||||||
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
@@ -4,6 +4,6 @@ branches:
|
|||||||
- master
|
- master
|
||||||
rvm:
|
rvm:
|
||||||
- 1.8.7
|
- 1.8.7
|
||||||
- 1.9.2
|
|
||||||
- 1.9.3
|
- 1.9.3
|
||||||
- 2.0.0
|
- 2.0.0
|
||||||
|
- 2.4.0
|
||||||
|
|||||||
1
Gemfile
1
Gemfile
@@ -1,3 +1,2 @@
|
|||||||
source 'https://rubygems.org'
|
source 'https://rubygems.org'
|
||||||
gemspec
|
gemspec
|
||||||
gem 'transpec'
|
|
||||||
|
|||||||
35
README.md
35
README.md
@@ -10,7 +10,7 @@ And once the output makes it to the server, it will print the URL to STDOUT.
|
|||||||
|
|
||||||
This can be really really cool in combination with `pbcopy`, like:
|
This can be really really cool in combination with `pbcopy`, like:
|
||||||
|
|
||||||
* mac osx: `cat file | haste | pbcopy`
|
* mac osx: `cat file | haste | pbcopy`
|
||||||
* linux: `cat file | haste | xsel`
|
* linux: `cat file | haste | xsel`
|
||||||
|
|
||||||
after which the contents of `file` will be accessible at a URL which has been copied to your pasteboard.
|
after which the contents of `file` will be accessible at a URL which has been copied to your pasteboard.
|
||||||
@@ -42,14 +42,30 @@ haste file --raw
|
|||||||
|
|
||||||
## Changing the location of your haste server
|
## Changing the location of your haste server
|
||||||
|
|
||||||
By default, haste will point at `http://hastebin.com`. You can change this by setting the value of `ENV['HASTE_SERVER']` to the URL of your haste server. You can also use `alias` to make easy shortcuts if you commonly use a few hastes intermingled with each other. To do that, you'd put something like this into ~.bash_profile:
|
By default, haste will point at `https://hastebin.com`. You can change this by setting the value of `ENV['HASTE_SERVER']` to the URL of your haste server. You can also use `alias` to make easy shortcuts if you commonly use a few hastes intermingled with each other. To do that, you'd put something like this into ~.bash_profile:
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
alias work_haste="HASTE_SERVER=http://something.com haste"
|
alias work_haste="HASTE_SERVER=https://something.com haste"
|
||||||
```
|
```
|
||||||
|
|
||||||
After which you can use `work_haste` to send hastes to that server instead.
|
After which you can use `work_haste` to send hastes to that server instead.
|
||||||
|
|
||||||
|
### Authentication
|
||||||
|
|
||||||
|
If your haste installation requires http authentication,
|
||||||
|
add the following to your ~.bash_profile:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export HASTE_USER="myusername"
|
||||||
|
export HASTE_PASS="mypassword"
|
||||||
|
```
|
||||||
|
|
||||||
|
if you are using SSL, you will need to supply your certs path
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export HASTE_SSL_CERTS="/System/Library/OpenSSL/certs"
|
||||||
|
```
|
||||||
|
|
||||||
## Use as a library
|
## Use as a library
|
||||||
|
|
||||||
You can also use `Haste` as a library to upload hastes:
|
You can also use `Haste` as a library to upload hastes:
|
||||||
@@ -70,13 +86,22 @@ If you'd like an alternative on Windows that supports functionality similar to `
|
|||||||
Han Boetes and @nickthename have contributed a simple shell-script alternative for those not interested in installing a RubyGem:
|
Han Boetes and @nickthename have contributed a simple shell-script alternative for those not interested in installing a RubyGem:
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
haste() { a=$(cat); curl -X POST -s -d "$a" http://hastebin.com/documents | awk -F '"' '{print "http://hastebin.com/"$4}'; }
|
haste() {
|
||||||
|
local S="https" H="hastebin.com" P="" L="$1"
|
||||||
|
local SHP="${S}://${H}${P}/"
|
||||||
|
curl -X POST -s --data-binary @- "${SHP}documents" \
|
||||||
|
| awk -F '"' 'b{ b="."b }; {print a$4b}' a="${SHP}" b="${L}"
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Where `S` is the scheme, `H` is the host, `P` is the port, and `L` is the language. Requires `curl`
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
cat file.txt | haste
|
cat file.txt | haste # cat file into hate, output url
|
||||||
|
haste sh < script.sh # Same as above, but ensure shell syntax highlighting
|
||||||
|
xsel -b | haste txt # Output clipboard buffer into haste, ensure no highlighting
|
||||||
```
|
```
|
||||||
|
|
||||||
And a more expansive BASH option by @diethnis can be found at:
|
And a more expansive BASH option by @diethnis can be found at:
|
||||||
|
|||||||
@@ -4,7 +4,11 @@ module Haste
|
|||||||
|
|
||||||
# Create a new uploader
|
# Create a new uploader
|
||||||
def initialize
|
def initialize
|
||||||
@uploader = Uploader.new ENV['HASTE_SERVER']
|
@uploader = Uploader.new(
|
||||||
|
ENV['HASTE_SERVER'],
|
||||||
|
ENV['HASTE_USER'],
|
||||||
|
ENV['HASTE_PASS'],
|
||||||
|
ENV['HASTE_SSL_CERTS'])
|
||||||
end
|
end
|
||||||
|
|
||||||
# And then handle the basic usage
|
# And then handle the basic usage
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
require 'json'
|
require 'json'
|
||||||
require 'faraday'
|
require 'faraday'
|
||||||
|
require 'uri'
|
||||||
|
|
||||||
module Haste
|
module Haste
|
||||||
|
|
||||||
@@ -7,12 +8,16 @@ module Haste
|
|||||||
|
|
||||||
class Uploader
|
class Uploader
|
||||||
|
|
||||||
attr_reader :server_url
|
attr_reader :server_url, :server_user, :server_pass, :ssl_certs
|
||||||
|
|
||||||
def initialize(server_url = nil)
|
def initialize(server_url = nil, server_user = nil, server_pass = nil, ssl_certs = nil)
|
||||||
@server_url = server_url || Haste::DEFAULT_URL
|
@server_url = server_url || Haste::DEFAULT_URL
|
||||||
@server_url = @server_url.dup
|
@server_url = @server_url.dup
|
||||||
@server_url = @server_url.chop if @server_url.end_with?('/')
|
@server_url = @server_url.chop if @server_url.end_with?('/')
|
||||||
|
|
||||||
|
@server_user = server_user
|
||||||
|
@server_pass = server_pass
|
||||||
|
@ssl_certs = ssl_certs
|
||||||
end
|
end
|
||||||
|
|
||||||
# Take in a path and return a key
|
# Take in a path and return a key
|
||||||
@@ -40,16 +45,41 @@ module Haste
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def post_path
|
||||||
|
parsed_uri = URI.parse(server_url)
|
||||||
|
"#{parsed_uri.path}/documents"
|
||||||
|
end
|
||||||
|
|
||||||
def do_post(data)
|
def do_post(data)
|
||||||
connection.post('/documents', data)
|
connection.post(post_path, data)
|
||||||
end
|
end
|
||||||
|
|
||||||
def connection
|
def connection
|
||||||
@connection ||= Faraday.new(:url => server_url) do |c|
|
@connection ||= connection_set
|
||||||
c.adapter Faraday.default_adapter
|
end
|
||||||
|
|
||||||
|
def connection_set
|
||||||
|
return connection_https if @ssl_certs
|
||||||
|
connection_http
|
||||||
|
end
|
||||||
|
|
||||||
|
def connection_http
|
||||||
|
Faraday.new(:url => server_url) do |c|
|
||||||
|
connection_config(c)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def connection_https
|
||||||
|
Faraday.new(:url => server_url, :ssl => { :ca_path => @ssl_certs }) do |c|
|
||||||
|
connection_config(c)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def connection_config(config)
|
||||||
|
config.basic_auth(@server_user, @server_pass) if @server_user
|
||||||
|
config.adapter Faraday.default_adapter
|
||||||
|
end
|
||||||
|
|
||||||
def fail_with(msg)
|
def fail_with(msg)
|
||||||
raise Exception.new(msg)
|
raise Exception.new(msg)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
module Haste
|
module Haste
|
||||||
|
|
||||||
VERSION = '0.2.2'
|
VERSION = '0.2.3'
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -126,6 +126,42 @@ describe Haste::Uploader do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe :post_path do
|
||||||
|
|
||||||
|
let(:post_path) { uploader.send(:post_path) }
|
||||||
|
|
||||||
|
context "when the server URL doesn't have a path" do
|
||||||
|
|
||||||
|
let(:base) { 'http://example.com/' }
|
||||||
|
|
||||||
|
it 'should return /documents' do
|
||||||
|
expect(post_path).to eq('/documents')
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when the server URL has a path" do
|
||||||
|
|
||||||
|
let(:base) { 'http://example.com/friend' }
|
||||||
|
|
||||||
|
it 'should return /documents' do
|
||||||
|
expect(post_path).to eq('/friend/documents')
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when the server URL has a path that ends with slash" do
|
||||||
|
|
||||||
|
let(:base) { 'http://example.com/friend/' }
|
||||||
|
|
||||||
|
it 'should return /documents appended to the path without a duplicate slash' do
|
||||||
|
expect(post_path).to eq('/friend/documents')
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
describe :server_url do
|
describe :server_url do
|
||||||
|
|
||||||
let(:server_url) { uploader.server_url }
|
let(:server_url) { uploader.server_url }
|
||||||
|
|||||||
Reference in New Issue
Block a user