sipgate_io 0.1.6 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b17a778854facd17224ca88b612bae3fef9a52c
4
- data.tar.gz: 355292121b876c9892579d2966f89debe73abaf4
3
+ metadata.gz: b13b762011c328c801c9a905c793b6eaea62c4cc
4
+ data.tar.gz: b3bc9206cacb88eeed3064a00b547fad894cd61e
5
5
  SHA512:
6
- metadata.gz: f8788976a23b97d954d8ecf49635f583f8a842e8f5763ca44538eceb5078bca7e6b2c9491510296d8ace41153e7ab29d6888d80cb0cd544dc29031c8e257f2c9
7
- data.tar.gz: ff2504faac215e638e8869dd87ef399328229b9d0d57b1cb5f681529d55459e49a198a305286dd5c002280e9b1e4b99e7c70b8f0b26a7027d9b1eb2b6aacaa7f
6
+ metadata.gz: fecd57fcc0d9a2e27bbc258befdc98ee974f39420d2061786b412db19179c333d3ed6cbeeddd723ed19cd1509e56db5b16c2a6cf91038ab1612f71c6895e70b3
7
+ data.tar.gz: 9db396cfca44e8710670c2024ff91c9ab2c84664d1f44b3f3479a6d1daf68c21b43fd34fe6e64b9f5cfd1b747c17b619ad01ca68cacbce77afbe336125402809
@@ -1,3 +1,3 @@
1
1
  module SipgateIo
2
- VERSION = "0.1.6"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -3,65 +3,63 @@ require 'builder'
3
3
  module SipgateIo
4
4
  class XmlResponse
5
5
 
6
- def self.dial(target, options = nil)
7
- self.builder.Response do |b|
8
- if target == :voicemail
9
- b.Dial { |b| b.Voicemail }
10
- elsif options.nil?
11
- b.Dial { |b| b.Number(target) }
12
- elsif !options[:anonymous].nil?
13
- b.Dial(anonymous: true) { |b| b.Number(target) }
14
- elsif !options[:caller_id].nil?
15
- b.Dial(callerId: options[:caller_id]) { |b| b.Number(target) }
6
+ def self.dial(options = {})
7
+ anonymous = options[:clip] == :anonymous ? Hash[ anonymous: true ] : nil
8
+ caller_id = !!/\d+/.match(options[:clip]) ? Hash[ callerId: options[:clip] ] : nil
9
+ self.builder.Response(set_callback(options)) do |b|
10
+ b.Dial(anonymous, caller_id) do |b|
11
+ options[:target] == :voicemail ? b.Voicemail : b.Number(options[:target])
16
12
  end
17
13
  end
18
14
  end
19
15
 
20
- def self.play(url)
21
- self.builder.Response { |b| b.Play { |b| b.Url(url) } }
16
+ def self.play(options = {})
17
+ url = options[:soundfile_url]
18
+ self.builder.Response(set_callback(options)) { |b| b.Play { |b| b.Url(url) } }
22
19
  end
23
20
 
24
- def self.gather(options = nil)
25
- options ||= {}
26
- options[:type] ||= :dtmf
27
- options[:callback_url] ||= SipgateIo.configuration.callback_url
28
- options[:max_digits] ||= 1
29
- options[:timeout] ||= 1000
30
- self.builder.Response do |b|
31
- b.Gather(onData: options[:callback_url],
32
- maxDigits: options[:max_digits],
33
- timeout: options[:timeout]) do |b|
34
- unless options[:play_url].nil?
35
- b.Play { |b| b.Url(options[:play_url]) }
21
+ def self.gather(options = {})
22
+ on_data = Hash[ onData: SipgateIo.configuration.callback_url ]
23
+ max_digits = options.key?(:max_digits) ? Hash[ maxDigits: options[:max_digits] ] : nil
24
+ timeout = options.key?(:timeout) ? Hash[ timeout: options[:timeout] ] : nil
25
+ play_url = options.key?(:soundfile_url) ? options[:soundfile_url] : nil
26
+
27
+ self.builder.Response(set_callback(options)) do |b|
28
+ b.Gather(on_data,
29
+ max_digits,
30
+ timeout) do |b|
31
+ unless play_url.nil?
32
+ b.Play { |b| b.Url(play_url) }
36
33
  end
37
34
  end
38
35
  end
39
36
  end
40
37
 
41
- def self.reject(reason = nil)
42
- self.builder.Response do |b|
43
- if reason.nil?
44
- b.Reject
45
- else
46
- b.Reject(reason: reason)
47
- end
48
- end
38
+ def self.reject(options = {})
39
+ reason = options.key?(:reason) ? Hash[ reason: options[:reason] ] : nil
40
+ self.builder.Response(set_callback(options)) { |b| b.Reject(reason) }
49
41
  end
50
42
 
51
- def self.hangup
52
- self.builder.Response { |b| b.Hangup }
43
+ def self.hangup(options = {})
44
+ self.builder.Response(set_callback(options)){ |b| b.Hangup }
53
45
  end
54
46
 
55
47
  def self.on_answer
56
- self.builder.Response(onAnswer: SipgateIo.configuration.callback_url)
48
+ self.builder.Response(set_callback(Hash[ callback: :on_answer ]) )
57
49
  end
58
50
 
59
51
  def self.on_hangup
60
- self.builder.Response(onHangup: SipgateIo.configuration.callback_url)
52
+ self.builder.Response(set_callback(Hash[ callback: :on_hangup ]) )
61
53
  end
62
54
 
63
55
  private
64
56
 
57
+ def self.set_callback(options)
58
+ return nil unless options.key?(:callback)
59
+ type = (options[:callback] == :on_answer) ? :onAnswer : :onHangup
60
+ Hash[ type => SipgateIo.configuration.callback_url ]
61
+ end
62
+
65
63
  def self.builder
66
64
  b = Builder::XmlMarkup.new(indent: 2)
67
65
  b.instruct!
@@ -70,17 +68,3 @@ module SipgateIo
70
68
 
71
69
  end
72
70
  end
73
-
74
- # puts SipgateIo::XmlResponse.gather()
75
- # puts SipgateIo::XmlResponse.gather(play_url: "http://google.de")
76
-
77
- # puts SipgateIo::XmlResponse.play("http://google.de")
78
- # puts SipgateIo::XmlResponse.dial(:voicemail)
79
- # puts SipgateIo::XmlResponse.dial("491234567")
80
- # puts SipgateIo::XmlResponse.dial("491234567", anonymous: true)
81
- # puts SipgateIo::XmlResponse.dial("491234567", caller_id: "555")
82
-
83
- # puts SipgateIo::XmlResponse.reject
84
- # puts SipgateIo::XmlResponse.reject(:busy)
85
- # puts SipgateIo::XmlResponse.reject(:rejected)
86
- # puts SipgateIo::XmlResponse.hangup
@@ -4,10 +4,6 @@ class EventProcessor
4
4
  end
5
5
 
6
6
  def process
7
- puts "#" * 40
8
- puts "EventProcessor"
9
- puts @event.inspect
10
- puts "#" * 40
11
7
  return SipgateIo::XmlResponse.reject
12
8
  end
13
9
  end
File without changes