ngrok-tunnel 1.0.1 → 2.0.1
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 +4 -4
- data/README.md +29 -6
- data/lib/ngrok/tunnel.rb +51 -17
- data/lib/ngrok/tunnel/version.rb +1 -1
- data/spec/tunnel/tunnel_spec.rb +22 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c864e0a2db71b2c84350df7daba7ef501c75a2d
|
4
|
+
data.tar.gz: adbc7d33d04e99d3e657f53ff4c203d93a323b0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f97a3e3eb817a84c124029ab9e40ea3d6bbd81548a576ba6c454f261564d9aa7a1150496d0b47035010d93a699b39543b7706d3e9fec113247e3a9f67dc25709
|
7
|
+
data.tar.gz: 96dbd1d0a73e59675ffe02e386953383d202c258b386665de17a6f4965ee40461fe274d5eab3f75e36806b1ed81d33ae804d27ed1b4b8f0720f3e8538293ab2f
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Ngrok::Tunnel
|
2
2
|
|
3
|
-
|
3
|
+
Ngrok-tunnel gem is a ruby wrapper for ngrok
|
4
|
+
|
5
|
+
[](http://badge.fury.io/rb/ngrok-tunnel)
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -23,33 +25,54 @@ Or install it yourself as:
|
|
23
25
|
```ruby
|
24
26
|
require 'ngrok/tunnel'
|
25
27
|
|
26
|
-
# spawn ngrok
|
27
|
-
Ngrok::Tunnel.start
|
28
|
+
# spawn ngrok (default port 3001)
|
29
|
+
Ngrok::Tunnel.start
|
28
30
|
|
29
31
|
# ngrok local_port
|
30
|
-
Ngrok::Tunnel.
|
32
|
+
Ngrok::Tunnel.port
|
33
|
+
=> 3001
|
31
34
|
|
32
35
|
# ngrok external url
|
33
36
|
Ngrok::Tunnel.ngrok_url
|
37
|
+
=> "http://aaa0e65.ngrok.com"
|
38
|
+
|
34
39
|
Ngrok::Tunnel.ngrok_url_https
|
40
|
+
=> "https://aaa0e65.ngrok.com"
|
35
41
|
|
36
42
|
Ngrok::Tunnel.running?
|
43
|
+
=> true
|
44
|
+
|
37
45
|
Ngrok::Tunnel.stopped?
|
46
|
+
=> false
|
38
47
|
|
39
48
|
# ngrok process id
|
40
49
|
Ngrok::Tunnel.pid
|
50
|
+
=> 27384
|
41
51
|
|
42
52
|
# ngrok log file descriptor
|
43
|
-
Ngrok::Tunnel.
|
53
|
+
Ngrok::Tunnel.log
|
54
|
+
=> #<File:/tmp/ngrok20141022-27376-cmmiq4>
|
44
55
|
|
45
56
|
# kill ngrok
|
46
57
|
Ngrok::Tunnel.stop
|
58
|
+
=> :stopped
|
59
|
+
|
60
|
+
```
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
# ngrok custom parameters
|
64
|
+
Ngrok::Tunnel.start(port: 3333,
|
65
|
+
subdomain: 'MY_SUBDOMAIN',
|
66
|
+
authtoken: 'MY_TOKEN',
|
67
|
+
log: 'ngrok.log',
|
68
|
+
config: '~/.ngrok')
|
47
69
|
|
48
70
|
```
|
49
71
|
|
72
|
+
|
50
73
|
## Contributing
|
51
74
|
|
52
|
-
1. Fork it ( https://github.com/
|
75
|
+
1. Fork it ( https://github.com/bogdanovich/ngrok-tunnel/fork )
|
53
76
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
54
77
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
55
78
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/ngrok/tunnel.rb
CHANGED
@@ -5,29 +5,31 @@ module Ngrok
|
|
5
5
|
|
6
6
|
class NotFound < StandardError; end
|
7
7
|
class FetchUrlError < StandardError; end
|
8
|
+
class Error < StandardError; end
|
8
9
|
|
9
10
|
class Tunnel
|
10
11
|
|
11
12
|
class << self
|
12
|
-
attr_reader :pid, :
|
13
|
+
attr_reader :pid, :ngrok_url, :ngrok_url_https, :status
|
13
14
|
|
14
|
-
def init
|
15
|
-
@
|
15
|
+
def init(params = {})
|
16
|
+
@params = {port: 3001, timeout: 10, config: '/dev/null'}.merge(params)
|
17
|
+
@status = :stopped unless @status
|
16
18
|
end
|
17
19
|
|
18
|
-
def start(
|
19
|
-
options[:timeout] ||= 10
|
20
|
-
@options = options
|
21
|
-
|
20
|
+
def start(params = {})
|
22
21
|
ensure_binary
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
init(params)
|
23
|
+
|
24
|
+
if stopped?
|
25
|
+
@params[:log] = (@params[:log]) ? File.open(@params[:log], 'w+') : Tempfile.new('ngrok')
|
26
|
+
@pid = spawn("exec ngrok " + ngrok_exec_params)
|
27
|
+
at_exit { Ngrok::Tunnel.stop }
|
28
|
+
@status = :running
|
29
|
+
fetch_urls
|
30
|
+
end
|
26
31
|
|
27
|
-
@
|
28
|
-
at_exit { Ngrok::Tunnel.stop }
|
29
|
-
@status = :running
|
30
|
-
fetch_urls
|
32
|
+
@ngrok_url
|
31
33
|
end
|
32
34
|
|
33
35
|
def stop
|
@@ -36,6 +38,7 @@ module Ngrok
|
|
36
38
|
@ngrok_url = @ngrok_url_https = @pid = nil
|
37
39
|
@status = :stopped
|
38
40
|
end
|
41
|
+
@status
|
39
42
|
end
|
40
43
|
|
41
44
|
def running?
|
@@ -46,18 +49,49 @@ module Ngrok
|
|
46
49
|
@status == :stopped
|
47
50
|
end
|
48
51
|
|
52
|
+
def port
|
53
|
+
@params[:port]
|
54
|
+
end
|
55
|
+
|
56
|
+
def log
|
57
|
+
@params[:log]
|
58
|
+
end
|
59
|
+
|
60
|
+
def subdomain
|
61
|
+
@params[:subdomain]
|
62
|
+
end
|
63
|
+
|
64
|
+
def authtoken
|
65
|
+
@params[:authtoken]
|
66
|
+
end
|
67
|
+
|
49
68
|
def inherited(subclass)
|
50
69
|
init
|
51
70
|
end
|
52
71
|
|
53
72
|
private
|
54
73
|
|
74
|
+
def ngrok_exec_params
|
75
|
+
exec_params = "-log=stdout "
|
76
|
+
exec_params << "-authtoken=#{@params[:authtoken]} " if @params[:authtoken]
|
77
|
+
exec_params << "-subdomain=#{@params[:subdomain]} " if @params[:subdomain]
|
78
|
+
exec_params << "-config=#{@params[:config]} #{@params[:port].to_i} > #{@params[:log].path}"
|
79
|
+
end
|
80
|
+
|
55
81
|
def fetch_urls
|
56
|
-
@
|
57
|
-
|
82
|
+
@params[:timeout].times do
|
83
|
+
log_content = @params[:log].read
|
84
|
+
@ngrok_url, @ngrok_url_https = log_content.scan(/"Url":"([^"]+)"/).flatten
|
58
85
|
return @ngrok_url if @ngrok_url
|
86
|
+
|
87
|
+
error = log_content.scan(/"Error":"([^"]+)"/).flatten
|
88
|
+
unless error.empty?
|
89
|
+
self.stop
|
90
|
+
raise Ngrok::Error, error.first
|
91
|
+
end
|
92
|
+
|
59
93
|
sleep 1
|
60
|
-
@
|
94
|
+
@params[:log].rewind
|
61
95
|
end
|
62
96
|
raise FetchUrlError, "Unable to fetch external url"
|
63
97
|
@ngrok_url
|
data/lib/ngrok/tunnel/version.rb
CHANGED
data/spec/tunnel/tunnel_spec.rb
CHANGED
@@ -20,8 +20,7 @@ describe Ngrok::Tunnel do
|
|
20
20
|
describe "Run process" do
|
21
21
|
|
22
22
|
before(:all) do
|
23
|
-
|
24
|
-
Ngrok::Tunnel.start(3001)
|
23
|
+
Ngrok::Tunnel.start
|
25
24
|
end
|
26
25
|
|
27
26
|
after(:all) { Ngrok::Tunnel.stop }
|
@@ -39,7 +38,7 @@ describe Ngrok::Tunnel do
|
|
39
38
|
end
|
40
39
|
|
41
40
|
it "should match local_port" do
|
42
|
-
expect(Ngrok::Tunnel.
|
41
|
+
expect(Ngrok::Tunnel.port).to eq(3001)
|
43
42
|
end
|
44
43
|
|
45
44
|
it "should have valid ngrok_url" do
|
@@ -60,4 +59,24 @@ describe Ngrok::Tunnel do
|
|
60
59
|
|
61
60
|
end
|
62
61
|
|
62
|
+
describe "Custom log file" do
|
63
|
+
it "should be able to use custom log file" do
|
64
|
+
Ngrok::Tunnel.start(log: 'test.log')
|
65
|
+
expect(Ngrok::Tunnel.running?).to eq true
|
66
|
+
expect(Ngrok::Tunnel.log.path).to eq 'test.log'
|
67
|
+
Ngrok::Tunnel.stop
|
68
|
+
expect(Ngrok::Tunnel.stopped?).to eq true
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "Custom subdomain" do
|
73
|
+
it "should fail without authtoken" do
|
74
|
+
expect {Ngrok::Tunnel.start(subdomain: 'test-subdomain')}.to raise_error
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should fail with incorrect authtoken" do
|
78
|
+
expect {Ngrok::Tunnel.start(subdomain: 'test-subdomain', authtoken: 'incorrect_token')}.to raise_error
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
63
82
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ngrok-tunnel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Bogdanovich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|