haste 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b0a30cd28db8b86bddf18e6566da74606f8ff696
4
- data.tar.gz: ed8009b3dc3d1a66e62d78f122117bddc1b7c1f2
2
+ SHA256:
3
+ metadata.gz: 4cc8bef048fb30c944bfbcdac49747d5628bde679d6d0c75651c71ef83c29e54
4
+ data.tar.gz: ab3fe8bfea6e0e4d4c0ab2f5d490f4bc7dc97c948b40f053c80d1ce447a998fd
5
5
  SHA512:
6
- metadata.gz: 491b3fb08ee4d71703e52794390eb247926407aa6cf5d0d2bf053a53e6eb4c7beb882ea2ae90d416cc2aa423700c72031a33df202db6e2db76cf4562586e2728
7
- data.tar.gz: 53f96da87beeeff259d4a1ca43a953b0c47aae0dd15c2a3f369b914e78983c6c388c8184e13cbb51e3222c9a9de9eb16a93be6f2ec625d94c90d7ef2b726d449
6
+ metadata.gz: 331cf67f756c7384644f4d00c8877e1d611cfe1187e40ed877d1babba413f4dea50e70f1352409b40613eb1af7ebfcad2761b7e145438c6e4c3382d3e9d6c9be
7
+ data.tar.gz: 5ddc100be5baa4c28f0acdb5eea37fe12cd2fe6fe052df246ad8a61767a11e728d62942dc1d70ccf1a38ba3414e663a7ef942fb8f78de2fc53f0a76248dc5e44
data/lib/haste/cli.rb CHANGED
@@ -4,7 +4,13 @@ module Haste
4
4
 
5
5
  # Create a new uploader
6
6
  def initialize
7
- @uploader = Uploader.new ENV['HASTE_SERVER']
7
+ @uploader = Uploader.new(
8
+ ENV['HASTE_SERVER'],
9
+ ENV['HASTE_SERVER_TOKEN'],
10
+ ENV['HASTE_SHARE_SERVER'],
11
+ ENV['HASTE_USER'],
12
+ ENV['HASTE_PASS'],
13
+ ENV['HASTE_SSL_CERTS'])
8
14
  end
9
15
 
10
16
  # And then handle the basic usage
@@ -16,11 +22,7 @@ module Haste
16
22
  key = @uploader.upload_raw STDIN.readlines.join
17
23
  end
18
24
  # Put together a URL
19
- if ARGV.include?('--raw')
20
- url = "#{@uploader.server_url}/raw/#{key}"
21
- else
22
- url = "#{@uploader.server_url}/#{key}"
23
- end
25
+ url = "#{@uploader.share_server_url}/share/#{key}"
24
26
  # And write data out
25
27
  if STDOUT.tty?
26
28
  STDOUT.puts url
@@ -4,16 +4,27 @@ require 'uri'
4
4
 
5
5
  module Haste
6
6
 
7
- DEFAULT_URL = 'https://hastebin.com'
7
+ DEFAULT_SERVER_URL = 'https://hastebin.com'
8
+ DEFAULT_SHARE_SERVER_URL = 'https://hastebin.com'
8
9
 
9
10
  class Uploader
10
11
 
11
- attr_reader :server_url
12
+ attr_reader :server_url, :server_token, :share_server_url, :server_user, :server_pass, :ssl_certs
12
13
 
13
- def initialize(server_url = nil)
14
- @server_url = server_url || Haste::DEFAULT_URL
15
- @server_url = @server_url.dup
16
- @server_url = @server_url.chop if @server_url.end_with?('/')
14
+ def initialize(server_url = nil, server_token = nil, share_server_url = nil, server_user = nil, server_pass = nil, ssl_certs = nil)
15
+ @server_url = generate_url(server_url || Haste::DEFAULT_SERVER_URL)
16
+ @share_server_url = generate_url(share_server_url || Haste::DEFAULT_SHARE_SERVER_URL)
17
+
18
+ @server_user = server_user
19
+ @server_token = server_token
20
+ @server_pass = server_pass
21
+ @ssl_certs = ssl_certs
22
+ end
23
+
24
+ def generate_url(url)
25
+ url = url.dup
26
+ url = url.chop if url.end_with?('/')
27
+ return url
17
28
  end
18
29
 
19
30
  # Take in a path and return a key
@@ -51,11 +62,32 @@ module Haste
51
62
  end
52
63
 
53
64
  def connection
54
- @connection ||= Faraday.new(:url => server_url) do |c|
55
- c.adapter Faraday.default_adapter
65
+ @connection ||= connection_set
66
+ end
67
+
68
+ def connection_set
69
+ return connection_https if @ssl_certs
70
+ connection_http
71
+ end
72
+
73
+ def connection_http
74
+ Faraday.new(:url => server_url) do |c|
75
+ connection_config(c)
56
76
  end
57
77
  end
58
78
 
79
+ def connection_https
80
+ Faraday.new(:url => server_url, :ssl => { :ca_path => @ssl_certs }) do |c|
81
+ connection_config(c)
82
+ end
83
+ end
84
+
85
+ def connection_config(config)
86
+ config.request :authorization, 'Bearer', @server_token if @server_token
87
+ config.basic_auth(@server_user, @server_pass) if @server_user
88
+ config.adapter Faraday.default_adapter
89
+ end
90
+
59
91
  def fail_with(msg)
60
92
  raise Exception.new(msg)
61
93
  end
data/lib/haste/version.rb CHANGED
@@ -1,5 +1,3 @@
1
1
  module Haste
2
-
3
- VERSION = '0.2.3'
4
-
2
+ VERSION = '0.3.0'
5
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haste
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - John Crepezzi
8
- autorequire:
7
+ - Toptal
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-19 00:00:00.000000000 Z
11
+ date: 2023-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.9'
55
55
  description: CLI Haste Client
56
- email: john.crepezzi@gmail.com
56
+ email: open-source@toptal.com
57
57
  executables:
58
58
  - haste
59
59
  extensions: []
@@ -66,11 +66,11 @@ files:
66
66
  - lib/haste/uploader.rb
67
67
  - lib/haste/version.rb
68
68
  - spec/spec_helper.rb
69
- homepage: https://github.com/seejohnrun/haste-client
69
+ homepage: https://github.com/toptal/haste-client
70
70
  licenses:
71
71
  - MIT License
72
72
  metadata: {}
73
- post_install_message:
73
+ post_install_message:
74
74
  rdoc_options: []
75
75
  require_paths:
76
76
  - lib
@@ -85,9 +85,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  - !ruby/object:Gem::Version
86
86
  version: '0'
87
87
  requirements: []
88
- rubyforge_project:
89
- rubygems_version: 2.5.2
90
- signing_key:
88
+ rubygems_version: 3.3.26
89
+ signing_key:
91
90
  specification_version: 4
92
91
  summary: Haste Client
93
92
  test_files: