freeswitcher 0.4.6 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
data/MANIFEST CHANGED
@@ -70,7 +70,6 @@ tasks/manifest.rake
70
70
  tasks/release.rake
71
71
  tasks/reversion.rake
72
72
  tasks/setup.rake
73
- tasks/spec.rake
74
73
  tasks/yard.rake
75
74
  spec/helper.rb
76
75
  spec/fsr_listener_helper.rb
data/freeswitcher.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{freeswitcher}
5
- s.version = "0.4.6"
5
+ s.version = "0.4.7"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Jayson Vaughn", "Michael Fellinger", "Kevin Berry", "TJ Vanderpoel"]
9
- s.date = %q{2010-01-15}
9
+ s.date = %q{2010-01-19}
10
10
  s.description = %q{=========================================================
11
11
  FreeSWITCHeR
12
12
  Copyright (c) 2009 The Rubyists (Jayson Vaughn, Tj Vanderpoel, Michael Fellinger, Kevin Berry)
@@ -132,7 +132,7 @@ Home page at http://code.rubyists.com/projects/fs
132
132
  #rubyists on FreeNode
133
133
  }
134
134
  s.email = %q{FreeSWITCHeR@rubyists.com}
135
- s.files = [".gitignore", "AUTHORS", "CHANGELOG", "License.txt", "MANIFEST", "NEWS", "README", "Rakefile", "examples/inbound_event_socket.rb", "examples/inbound_socket_events.rb", "examples/outbound_event_socket.rb", "freeswitcher.gemspec", "lib/fsr.rb", "lib/fsr/app.rb", "lib/fsr/app/answer.rb", "lib/fsr/app/bind_meta_app.rb", "lib/fsr/app/bridge.rb", "lib/fsr/app/conference.rb", "lib/fsr/app/execute_app.rb", "lib/fsr/app/fifo.rb", "lib/fsr/app/fs_break.rb", "lib/fsr/app/fs_sleep.rb", "lib/fsr/app/hangup.rb", "lib/fsr/app/limit.rb", "lib/fsr/app/log.rb", "lib/fsr/app/play_and_get_digits.rb", "lib/fsr/app/playback.rb", "lib/fsr/app/read.rb", "lib/fsr/app/set.rb", "lib/fsr/app/speak.rb", "lib/fsr/app/transfer.rb", "lib/fsr/app/uuid_dump.rb", "lib/fsr/app/uuid_getvar.rb", "lib/fsr/app/uuid_setvar.rb", "lib/fsr/cmd.rb", "lib/fsr/cmd/calls.rb", "lib/fsr/cmd/fsctl.rb", "lib/fsr/cmd/originate.rb", "lib/fsr/cmd/sofia.rb", "lib/fsr/cmd/sofia/profile.rb", "lib/fsr/cmd/sofia/status.rb", "lib/fsr/cmd/sofia_contact.rb", "lib/fsr/cmd/status.rb", "lib/fsr/cmd/uuid_dump.rb", "lib/fsr/command_socket.rb", "lib/fsr/database.rb", "lib/fsr/database/call_limit.rb", "lib/fsr/database/core.rb", "lib/fsr/database/sofia_reg_external.rb", "lib/fsr/database/sofia_reg_internal.rb", "lib/fsr/database/voicemail_default.rb", "lib/fsr/event_socket.rb", "lib/fsr/fake_socket.rb", "lib/fsr/listener.rb", "lib/fsr/listener/header_and_content_response.rb", "lib/fsr/listener/inbound.rb", "lib/fsr/listener/inbound/event.rb", "lib/fsr/listener/mock.rb", "lib/fsr/listener/outbound.rb", "lib/fsr/model/call.rb", "lib/fsr/version.rb", "tasks/authors.rake", "tasks/bacon.rake", "tasks/changelog.rake", "tasks/copyright.rake", "tasks/gem.rake", "tasks/gem_installer.rake", "tasks/install_dependencies.rake", "tasks/manifest.rake", "tasks/release.rake", "tasks/reversion.rake", "tasks/setup.rake", "tasks/spec.rake", "tasks/yard.rake", "spec/helper.rb", "spec/fsr_listener_helper.rb", "spec/fsr/app.rb", "spec/fsr/app/answer.rb", "spec/fsr/app/bind_meta_app.rb", "spec/fsr/app/bridge.rb", "spec/fsr/app/conference.rb", "spec/fsr/app/execute_app.rb", "spec/fsr/app/fifo.rb", "spec/fsr/app/fs_break.rb", "spec/fsr/app/fs_sleep.rb", "spec/fsr/app/hangup.rb", "spec/fsr/app/limit.rb", "spec/fsr/app/log.rb", "spec/fsr/app/play_and_get_digits.rb", "spec/fsr/app/playback.rb", "spec/fsr/app/set.rb", "spec/fsr/app/transfer.rb", "spec/fsr/cmd.rb", "spec/fsr/cmd/calls.rb", "spec/fsr/cmd/originate.rb", "spec/fsr/cmd/sofia.rb", "spec/fsr/cmd/sofia/profile.rb", "spec/fsr/cmd/uuid_dump.rb", "spec/fsr/listener.rb", "spec/fsr/listener/header_and_content_response.rb", "spec/fsr/listener/inbound.rb", "spec/fsr/listener/outbound.rb", "spec/fsr/loading.rb"]
135
+ s.files = [".gitignore", "AUTHORS", "CHANGELOG", "License.txt", "MANIFEST", "NEWS", "README", "Rakefile", "examples/inbound_event_socket.rb", "examples/inbound_socket_events.rb", "examples/outbound_event_socket.rb", "freeswitcher.gemspec", "lib/fsr.rb", "lib/fsr/app.rb", "lib/fsr/app/answer.rb", "lib/fsr/app/bind_meta_app.rb", "lib/fsr/app/bridge.rb", "lib/fsr/app/conference.rb", "lib/fsr/app/execute_app.rb", "lib/fsr/app/fifo.rb", "lib/fsr/app/fs_break.rb", "lib/fsr/app/fs_sleep.rb", "lib/fsr/app/hangup.rb", "lib/fsr/app/limit.rb", "lib/fsr/app/log.rb", "lib/fsr/app/play_and_get_digits.rb", "lib/fsr/app/playback.rb", "lib/fsr/app/read.rb", "lib/fsr/app/set.rb", "lib/fsr/app/speak.rb", "lib/fsr/app/transfer.rb", "lib/fsr/app/uuid_dump.rb", "lib/fsr/app/uuid_getvar.rb", "lib/fsr/app/uuid_setvar.rb", "lib/fsr/cmd.rb", "lib/fsr/cmd/calls.rb", "lib/fsr/cmd/fsctl.rb", "lib/fsr/cmd/originate.rb", "lib/fsr/cmd/sofia.rb", "lib/fsr/cmd/sofia/profile.rb", "lib/fsr/cmd/sofia/status.rb", "lib/fsr/cmd/sofia_contact.rb", "lib/fsr/cmd/status.rb", "lib/fsr/cmd/uuid_dump.rb", "lib/fsr/command_socket.rb", "lib/fsr/database.rb", "lib/fsr/database/call_limit.rb", "lib/fsr/database/core.rb", "lib/fsr/database/sofia_reg_external.rb", "lib/fsr/database/sofia_reg_internal.rb", "lib/fsr/database/voicemail_default.rb", "lib/fsr/event_socket.rb", "lib/fsr/fake_socket.rb", "lib/fsr/listener.rb", "lib/fsr/listener/header_and_content_response.rb", "lib/fsr/listener/inbound.rb", "lib/fsr/listener/inbound/event.rb", "lib/fsr/listener/mock.rb", "lib/fsr/listener/outbound.rb", "lib/fsr/model/call.rb", "lib/fsr/version.rb", "tasks/authors.rake", "tasks/bacon.rake", "tasks/changelog.rake", "tasks/copyright.rake", "tasks/gem.rake", "tasks/gem_installer.rake", "tasks/install_dependencies.rake", "tasks/manifest.rake", "tasks/release.rake", "tasks/reversion.rake", "tasks/setup.rake", "tasks/yard.rake", "spec/helper.rb", "spec/fsr_listener_helper.rb", "spec/fsr/app.rb", "spec/fsr/app/answer.rb", "spec/fsr/app/bind_meta_app.rb", "spec/fsr/app/bridge.rb", "spec/fsr/app/conference.rb", "spec/fsr/app/execute_app.rb", "spec/fsr/app/fifo.rb", "spec/fsr/app/fs_break.rb", "spec/fsr/app/fs_sleep.rb", "spec/fsr/app/hangup.rb", "spec/fsr/app/limit.rb", "spec/fsr/app/log.rb", "spec/fsr/app/play_and_get_digits.rb", "spec/fsr/app/playback.rb", "spec/fsr/app/set.rb", "spec/fsr/app/transfer.rb", "spec/fsr/cmd.rb", "spec/fsr/cmd/calls.rb", "spec/fsr/cmd/originate.rb", "spec/fsr/cmd/sofia.rb", "spec/fsr/cmd/sofia/profile.rb", "spec/fsr/cmd/uuid_dump.rb", "spec/fsr/listener.rb", "spec/fsr/listener/header_and_content_response.rb", "spec/fsr/listener/inbound.rb", "spec/fsr/listener/outbound.rb", "spec/fsr/loading.rb"]
136
136
  s.homepage = %q{http://code.rubyists.com/projects/fs}
137
137
  s.post_install_message = %q{=========================================================
138
138
  FreeSWITCHeR
@@ -6,7 +6,7 @@ require 'fsr/listener/header_and_content_response.rb'
6
6
  module FSR
7
7
  module Listener
8
8
  class Inbound < EventMachine::Protocols::HeaderAndContentProtocol
9
- attr_reader :auth, :hooks, :event, :server, :port
9
+ attr_reader :auth, :hooks, :server, :port
10
10
 
11
11
  HOOKS = {}
12
12
 
@@ -47,12 +47,20 @@ module FSR
47
47
  def authorize_and_register_for_events
48
48
  FSR::Log.info "Connection established. Authorizing..."
49
49
  say("auth #{@auth}")
50
- say('event plain ALL')
50
+ add_class_hooks
51
+ before_session
51
52
  end
52
53
 
53
54
  def before_session
54
55
  end
55
56
 
57
+ def add_class_hooks
58
+ HOOKS.each do |(key, value)|
59
+ add_event(key, &value)
60
+ end
61
+ end
62
+ private :before_session, :add_class_hooks
63
+
56
64
  # receive_request is the callback method when data is recieved from the socket
57
65
  #
58
66
  # param header headers from standard Header and Content protocol
@@ -60,13 +68,19 @@ module FSR
60
68
  def receive_request(header, content)
61
69
  hash_header = headers_2_hash(header)
62
70
  hash_content = headers_2_hash(content)
63
- @event = HeaderAndContentResponse.new({:headers => hash_header, :content => hash_content})
71
+ event = HeaderAndContentResponse.new({:headers => hash_header, :content => hash_content})
64
72
  event_name = event.content[:event_name].to_s.strip
65
73
  unless event_name.empty?
66
- instance_eval &HOOKS[event_name.to_sym] unless HOOKS[event_name.to_sym].nil?
67
- instance_eval &@hooks[event_name.to_sym] unless @hooks[event_name.to_sym].nil?
74
+ if hook = @hooks[event_name.to_sym]
75
+ case hook.arity
76
+ when 1
77
+ @hooks[event_name.to_sym].call(event)
78
+ when 2
79
+ @hooks[event_name.to_sym].call(self, event)
80
+ end
81
+ end
68
82
  end
69
- on_event
83
+ on_event(event)
70
84
  end
71
85
 
72
86
  # say encapsulates #send_data for the user
@@ -87,7 +101,7 @@ module FSR
87
101
  #
88
102
  # param event The triggered event object
89
103
  # return event The triggered event object
90
- def on_event
104
+ def on_event(event)
91
105
  event
92
106
  end
93
107
 
@@ -121,8 +135,6 @@ module FSR
121
135
  @hooks.delete(event)
122
136
  end
123
137
 
124
-
125
-
126
138
  end
127
139
 
128
140
  end
data/lib/fsr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module FSR
2
- VERSION = "0.4.6"
2
+ VERSION = "0.4.7"
3
3
  end
@@ -3,22 +3,27 @@ require 'lib/fsr'
3
3
  require "fsr/listener"
4
4
  require "fsr/listener/inbound"
5
5
  require "em-spec/bacon"
6
+ EM.spec_backend = EventMachine::Spec::Bacon
6
7
 
7
8
  # Bare class to use for testing
8
9
  class InboundListener < FSR::Listener::Inbound
9
- attr_accessor :test_event
10
+ attr_accessor :custom_event
10
11
 
11
12
  # Stub error? out
12
13
  def error?
13
14
  false
14
15
  end
15
16
 
17
+ def before_session
18
+ add_event(:CUSTOM) { |e| @custom_event = e }
19
+ end
20
+
16
21
  def initialize(*args)
17
22
  super(*args)
18
23
  @test_event = nil
19
24
  end
20
25
 
21
- def on_event
26
+ def on_event(event)
22
27
  recvd_event << event
23
28
  end
24
29
 
@@ -28,8 +33,9 @@ class InboundListener < FSR::Listener::Inbound
28
33
  end
29
34
 
30
35
  class InboundListener2 < InboundListener
36
+ attr_accessor :test_event
31
37
  def before_session
32
- add_event(:TEST_EVENT) {recvd_event << event}
38
+ add_event(:TEST_EVENT) { |e| @test_event = e}
33
39
  end
34
40
  end
35
41
 
@@ -59,17 +65,19 @@ EM.describe InboundListener do
59
65
  end
60
66
 
61
67
  should "be able to add custom event hooks in the pre_session" do
68
+ @listener.receive_data("Content-Length: 22\n\nEvent-Name: CUSTOM\n\n")
69
+ @listener.custom_event.should.equal @listener.recvd_event.first
62
70
  @listener2.receive_data("Content-Length: 22\n\nEvent-Name: TEST_EVENT\n\n")
63
- @listener2.recvd_event.first.content[:event_name].should.equal "TEST_EVENT"
71
+ @listener2.test_event.content[:event_name].should.equal "TEST_EVENT"
64
72
  done
65
73
  end
66
74
 
67
75
  should "be able to add custom event hooks" do
68
- listener = @listener
69
- FSL::Inbound.add_event_hook(:HANGUP_EVENT) {listener.test_event = event}
70
- @listener.test_event.should.equal nil
71
- @listener.receive_data("Content-Length: 24\n\nEvent-Name: HANGUP_EVENT\n\n")
72
- @listener.test_event.content[:event_name].should.equal "HANGUP_EVENT"
76
+ FSL::Inbound.add_event_hook(:HANGUP_EVENT) { |instance, event| instance.test_event = event }
77
+ listener = InboundListener2.new(1234, {:auth => 'SecretPassword'})
78
+ listener.test_event.should.equal nil
79
+ listener.receive_data("Content-Length: 24\n\nEvent-Name: HANGUP_EVENT\n\n")
80
+ listener.test_event.content[:event_name].should.equal "HANGUP_EVENT"
73
81
  done
74
82
  end
75
83
 
@@ -4,7 +4,7 @@ require "fsr/listener"
4
4
  require "fsr/listener/inbound"
5
5
  require "fsr/listener/outbound"
6
6
  require "em-spec/bacon"
7
-
7
+ EM.spec_backend = EventMachine::Spec::Bacon
8
8
  # Bare class to use for testing
9
9
  class MyListener < FSR::Listener::Outbound
10
10
  attr_accessor :recvd_reply, :state_machine_test, :state_machine_test2
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freeswitcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jayson Vaughn
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2010-01-15 00:00:00 -06:00
15
+ date: 2010-01-19 00:00:00 -06:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
@@ -230,7 +230,6 @@ files:
230
230
  - tasks/release.rake
231
231
  - tasks/reversion.rake
232
232
  - tasks/setup.rake
233
- - tasks/spec.rake
234
233
  - tasks/yard.rake
235
234
  - spec/helper.rb
236
235
  - spec/fsr_listener_helper.rb
data/tasks/spec.rake DELETED
File without changes