haste 0.2.2 → 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: 57eb2c33980fc428fa8e5405f297b7da65b8f868
4
- data.tar.gz: c9914dae672d56a2e9938374a9faf2d07219666a
2
+ SHA256:
3
+ metadata.gz: 4cc8bef048fb30c944bfbcdac49747d5628bde679d6d0c75651c71ef83c29e54
4
+ data.tar.gz: ab3fe8bfea6e0e4d4c0ab2f5d490f4bc7dc97c948b40f053c80d1ce447a998fd
5
5
  SHA512:
6
- metadata.gz: 6255fab7832fef33453fc9ca0440880269c6ef0a01dc1f1e4e5bf02a15a483cdfc028289eff92fbea9fa0de4f000d61d6187d477a99c17eb51d220c4abcb284f
7
- data.tar.gz: 472960074ee86d45502888a26733a31c8e62d4daf756ce73cbcb5bb479b99844197fc05c001523735675d7d761ebae5c42eee6620b883a8a1cf4ca873ae62d2f
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
@@ -1,18 +1,30 @@
1
1
  require 'json'
2
2
  require 'faraday'
3
+ require 'uri'
3
4
 
4
5
  module Haste
5
6
 
6
- DEFAULT_URL = 'https://hastebin.com'
7
+ DEFAULT_SERVER_URL = 'https://hastebin.com'
8
+ DEFAULT_SHARE_SERVER_URL = 'https://hastebin.com'
7
9
 
8
10
  class Uploader
9
11
 
10
- attr_reader :server_url
12
+ attr_reader :server_url, :server_token, :share_server_url, :server_user, :server_pass, :ssl_certs
11
13
 
12
- def initialize(server_url = nil)
13
- @server_url = server_url || Haste::DEFAULT_URL
14
- @server_url = @server_url.dup
15
- @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
16
28
  end
17
29
 
18
30
  # Take in a path and return a key
@@ -40,16 +52,42 @@ module Haste
40
52
 
41
53
  private
42
54
 
55
+ def post_path
56
+ parsed_uri = URI.parse(server_url)
57
+ "#{parsed_uri.path}/documents"
58
+ end
59
+
43
60
  def do_post(data)
44
- connection.post('/documents', data)
61
+ connection.post(post_path, data)
45
62
  end
46
63
 
47
64
  def connection
48
- @connection ||= Faraday.new(:url => server_url) do |c|
49
- 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)
76
+ end
77
+ end
78
+
79
+ def connection_https
80
+ Faraday.new(:url => server_url, :ssl => { :ca_path => @ssl_certs }) do |c|
81
+ connection_config(c)
50
82
  end
51
83
  end
52
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
+
53
91
  def fail_with(msg)
54
92
  raise Exception.new(msg)
55
93
  end
data/lib/haste/version.rb CHANGED
@@ -1,5 +1,3 @@
1
1
  module Haste
2
-
3
- VERSION = '0.2.2'
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.2
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-01-31 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.6.10
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: