localtunnel 1.0.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 543fdc1332a8724208b1a08e0f67b64f2993be06
4
+ data.tar.gz: b2c87adc35113cc4fb5c99cb1f1e74eefd0ad4e4
5
+ SHA512:
6
+ metadata.gz: ea6d2b05cc0bb93b9c2b560239f2d5c8126bffac7f30ea8c381f5374864effde44fba4a34fab6498bf5e6e858f75037ed85af1a1b1dce8e3883ede5e133a9359
7
+ data.tar.gz: d289b41d5c340a274c020bf5eb4cb939c80a7d78696ca4d811bd7e58af1abc918a8962d1a67e5f46eed38a5e8eb51b7fe7bb447d28ac5e1bfe3b30c9c573c2c2
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Swinburne Software Innovation Lab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,27 @@
1
+ # localtunnel
2
+
3
+ Ruby gem wrapping the [localtunnel](https://localtunnel.me/) npm package.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'localtunnel'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ $ bundle install
17
+ ```
18
+
19
+ Lastly, install the localtunnel npm package and ensure that it is available in your `PATH`:
20
+
21
+ ```bash
22
+ $ npm install -g localtunnel
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ TODO.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,2 @@
1
+ require "localtunnel/client"
2
+ require "localtunnel/version"
@@ -0,0 +1,75 @@
1
+ require "tempfile"
2
+
3
+ module Localtunnel
4
+ class Client
5
+ @@pid = nil
6
+ @@url = nil
7
+
8
+ def self.start(options = {})
9
+ return if running?
10
+
11
+ raise NpmPackageNotFoundError unless package_installed?
12
+
13
+ log = Tempfile.new("localtunnel")
14
+ @@pid = Process.spawn(execution_string(log, options))
15
+ @@url = parse_url!(log)
16
+
17
+ at_exit { stop } # Ensure process is killed if Ruby exits.
18
+
19
+ return # Explicitly return nil.
20
+ end
21
+
22
+ def self.stop
23
+ return unless running?
24
+
25
+ `kill -9 #{@@pid} 1>/dev/null 2>&1` # Can't use Process.kill, since JRuby on Raspbian doesn't support it.
26
+ @@pid = nil
27
+
28
+ return # Explicitly return nil.
29
+ end
30
+
31
+ def self.running?
32
+ !@@pid.nil?
33
+ end
34
+
35
+ def self.url
36
+ @@url if running?
37
+ end
38
+
39
+ def self.package_installed?
40
+ !`lt --version`.to_s.empty?
41
+ rescue Errno::ENOENT
42
+ false
43
+ end
44
+
45
+ def self.execution_string(log, options)
46
+ s = "exec lt"
47
+ s << " -p '#{options[:port]}'" if options.key?(:port)
48
+ s << " -s '#{options[:subdomain]}'" if options.key?(:subdomain)
49
+ s << " -h '#{options[:remote_host]}'" if options.key?(:remote_host)
50
+ s << " -l '#{options[:local_host]}'" if options.key?(:local_host)
51
+ s << " > #{log.path}"
52
+ end
53
+
54
+ def self.parse_url!(log, max_seconds = 10)
55
+ max_seconds.times do
56
+ sleep 1
57
+ raise ClientConnectionFailedError unless running?
58
+
59
+ log.rewind
60
+ if match_data = log.read.match(/^your url is: (.*)$/)
61
+ return match_data.captures[0]
62
+ end
63
+ end
64
+
65
+ stop
66
+ raise ClientConnectionFailedError
67
+ end
68
+ end
69
+
70
+ class NpmPackageNotFoundError < StandardError
71
+ end
72
+
73
+ class ClientConnectionFailedError < StandardError
74
+ end
75
+ end
@@ -0,0 +1,3 @@
1
+ module Localtunnel
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'localtunnel/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "localtunnel"
8
+ spec.version = Localtunnel::VERSION
9
+ spec.authors = ["Swinburne Software Innovation Lab"]
10
+ spec.email = ["god@ssil.com.au"]
11
+ spec.summary = %q{Ruby gem wrapping the localtunnel npm package.}
12
+ spec.description = %q{Ruby gem wrapping the localtunnel npm package.}
13
+ spec.homepage = "https://github.com/ssilab/localtunnel"
14
+ spec.license = "MIT"
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.require_paths = ["lib"]
17
+ spec.add_development_dependency "bundler", "~> 1.10"
18
+ spec.add_development_dependency "rake", "~> 10.0"
19
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: localtunnel
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Swinburne Software Innovation Lab
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Ruby gem wrapping the localtunnel npm package.
42
+ email:
43
+ - god@ssil.com.au
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/localtunnel.rb
54
+ - lib/localtunnel/client.rb
55
+ - lib/localtunnel/version.rb
56
+ - localtunnel.gemspec
57
+ homepage: https://github.com/ssilab/localtunnel
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.4.5.1
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Ruby gem wrapping the localtunnel npm package.
81
+ test_files: []