motion-net-service 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ LICENCE
2
+
3
+ MIT: http://mattaimonetti.mit-license.org
4
+
5
+ ------------------------------------------------
6
+
7
+ The MIT License (MIT)
8
+ Copyright © 2012 Matt Aimonetti <matt.aimonetti@gmail.com>
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the “Software”), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in
18
+ all copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26
+ THE SOFTWARE.
@@ -0,0 +1,48 @@
1
+ # NetService
2
+
3
+ NetService is a simple wrapper around NSNetService. It publishes and consumes services over Bonjour.
4
+
5
+ ## Installation
6
+
7
+ Command Line:
8
+
9
+ ```bash
10
+ gem install motion-net-service
11
+ ```
12
+
13
+ Bundler:
14
+
15
+ ```ruby
16
+ gem 'motion-net-service'
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ Publishing a NetService (Bonjour) service:
22
+
23
+ ```ruby
24
+ @service = NetService.new(name: "amazaballs", port: 4321, sear).tap do |ns|
25
+ ns.on_did_publish do
26
+ puts "I published a service"
27
+ end
28
+ ns.on_did_not_resolve do |error|
29
+ puts "Oh crap, I got an error: #{error}"
30
+ end
31
+ end
32
+
33
+ @service.publish
34
+ ```
35
+
36
+ Consuming a service
37
+
38
+ ```ruby
39
+ @n = NetServiceBrowser.search('_ssh._tcp') do |service, more_coming|
40
+ p "name: #{service.name}
41
+ p "service url: #{service.hostName}:#{service.port}"
42
+ p "More coming?: #{more_coming}"
43
+ end
44
+ ```
45
+
46
+ ## License
47
+
48
+ MIT, check the LICENSE file.
@@ -12,9 +12,8 @@ class AppDelegate
12
12
 
13
13
  p "SEARCHING NOW."
14
14
  @n = NetServiceBrowser.search('_ssh._tcp') do |service, more_coming|
15
- s = service.instance_variable_get(:@net_service)
16
- p "name: #{s.name}, addresses: #{s.addresses.first}"
17
- p "SERVICE FOUND: #{s.hostName}"
15
+ p "name: #{service.name}, addresses: #{service.addresses.first}"
16
+ p "SERVICE FOUND: #{service.hostName}"
18
17
  p "MORE COMING: #{more_coming}"
19
18
  end
20
19
  true
@@ -2,7 +2,7 @@ class NetService
2
2
  def initialize(options = {})
3
3
  default_options = {
4
4
  domain: "",
5
- type: "_http._tcp.",
5
+ search_type: "_http._tcp.",
6
6
  }
7
7
  options.merge!(default_options)
8
8
 
@@ -11,9 +11,9 @@ class NetService
11
11
  else
12
12
  @net_service = NSNetService.alloc.initWithDomain(
13
13
  options[:domain],
14
- type:options[:type],
15
- name:options[:name],
16
- port:options[:port]
14
+ type: options[:search_type],
15
+ name: options[:name],
16
+ port: options[:port]
17
17
  )
18
18
  end
19
19
 
@@ -42,6 +42,14 @@ class NetService
42
42
  end
43
43
  end
44
44
 
45
+ def method_missing(method, *args)
46
+ if @net_service.respond_to? method
47
+ @net_service.send(method, *args)
48
+ else
49
+ super
50
+ end
51
+ end
52
+
45
53
  protected
46
54
  def netServiceWillPublish(sender)
47
55
  @on_publish.call if @on_publish
@@ -1,3 +1,3 @@
1
1
  module MotionNetService
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: motion-net-service
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jamie van Dyke
@@ -48,6 +48,8 @@ extra_rdoc_files: []
48
48
  files:
49
49
  - .gitignore
50
50
  - Gemfile
51
+ - LICENSE
52
+ - README.md
51
53
  - Rakefile
52
54
  - app/app_delegate.rb
53
55
  - lib/motion-net-service.rb
@@ -69,7 +71,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
71
  requirements:
70
72
  - - ">="
71
73
  - !ruby/object:Gem::Version
72
- hash: -2733567938995359562
74
+ hash: -4061285287126613500
73
75
  segments:
74
76
  - 0
75
77
  version: "0"
@@ -78,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
80
  requirements:
79
81
  - - ">="
80
82
  - !ruby/object:Gem::Version
81
- hash: -2733567938995359562
83
+ hash: -4061285287126613500
82
84
  segments:
83
85
  - 0
84
86
  version: "0"