aastra_xml_api 1.0.0 → 1.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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -0
  3. data/README.md +10 -2
  4. data/aastra_xml_api.gemspec +1 -1
  5. data/lib/aastra_xml_api.rb +1 -1
  6. data/lib/aastra_xml_api/array_extensions.rb +61 -0
  7. data/lib/aastra_xml_api/phone.rb +205 -0
  8. data/lib/aastra_xml_api/phone_configuration.rb +56 -0
  9. data/lib/aastra_xml_api/phone_configuration_entry.rb +43 -0
  10. data/lib/aastra_xml_api/phone_directory.rb +122 -0
  11. data/lib/aastra_xml_api/phone_directory_entry.rb +34 -0
  12. data/lib/aastra_xml_api/phone_execute.rb +60 -0
  13. data/lib/aastra_xml_api/phone_execute_entry.rb +32 -0
  14. data/lib/aastra_xml_api/phone_formatted_text_screen.rb +119 -0
  15. data/lib/aastra_xml_api/phone_formatted_text_screen_entry.rb +50 -0
  16. data/lib/aastra_xml_api/phone_gd_image.rb +187 -0
  17. data/lib/aastra_xml_api/phone_icon_entry.rb +29 -0
  18. data/lib/aastra_xml_api/phone_image_menu.rb +145 -0
  19. data/lib/aastra_xml_api/phone_image_menu_entry.rb +27 -0
  20. data/lib/aastra_xml_api/phone_image_screen.rb +141 -0
  21. data/lib/aastra_xml_api/phone_input_screen.rb +251 -0
  22. data/lib/aastra_xml_api/phone_input_screen_entry.rb +86 -0
  23. data/lib/aastra_xml_api/phone_softkey_entry.rb +39 -0
  24. data/lib/aastra_xml_api/phone_status.rb +68 -0
  25. data/lib/aastra_xml_api/phone_status_entry.rb +58 -0
  26. data/lib/aastra_xml_api/phone_text_menu.rb +148 -0
  27. data/lib/aastra_xml_api/phone_text_menu_entry.rb +54 -0
  28. data/lib/aastra_xml_api/phone_text_screen.rb +95 -0
  29. data/lib/aastra_xml_api/version.rb +1 -1
  30. metadata +28 -27
  31. data/lib/aastra_xml_api/AastraIPPhone.rb +0 -203
  32. data/lib/aastra_xml_api/AastraIPPhoneConfiguration.rb +0 -55
  33. data/lib/aastra_xml_api/AastraIPPhoneConfigurationEntry.rb +0 -41
  34. data/lib/aastra_xml_api/AastraIPPhoneDirectory.rb +0 -119
  35. data/lib/aastra_xml_api/AastraIPPhoneDirectoryEntry.rb +0 -32
  36. data/lib/aastra_xml_api/AastraIPPhoneExecute.rb +0 -58
  37. data/lib/aastra_xml_api/AastraIPPhoneExecuteEntry.rb +0 -30
  38. data/lib/aastra_xml_api/AastraIPPhoneFormattedTextScreen.rb +0 -117
  39. data/lib/aastra_xml_api/AastraIPPhoneFormattedTextScreenEntry.rb +0 -48
  40. data/lib/aastra_xml_api/AastraIPPhoneGDImage.rb +0 -185
  41. data/lib/aastra_xml_api/AastraIPPhoneIconEntry.rb +0 -27
  42. data/lib/aastra_xml_api/AastraIPPhoneImageMenu.rb +0 -143
  43. data/lib/aastra_xml_api/AastraIPPhoneImageMenuEntry.rb +0 -25
  44. data/lib/aastra_xml_api/AastraIPPhoneImageScreen.rb +0 -139
  45. data/lib/aastra_xml_api/AastraIPPhoneInputScreen.rb +0 -249
  46. data/lib/aastra_xml_api/AastraIPPhoneInputScreenEntry.rb +0 -84
  47. data/lib/aastra_xml_api/AastraIPPhoneSoftkeyEntry.rb +0 -37
  48. data/lib/aastra_xml_api/AastraIPPhoneStatus.rb +0 -66
  49. data/lib/aastra_xml_api/AastraIPPhoneStatusEntry.rb +0 -56
  50. data/lib/aastra_xml_api/AastraIPPhoneTextMenu.rb +0 -145
  51. data/lib/aastra_xml_api/AastraIPPhoneTextMenuEntry.rb +0 -52
  52. data/lib/aastra_xml_api/AastraIPPhoneTextScreen.rb +0 -93
  53. data/lib/aastra_xml_api/arraynatsort.rb +0 -63
@@ -0,0 +1,34 @@
1
+ ########################################################################################################
2
+ # Aastra XML API Classes - PhoneDirectoryEntry
3
+ # Copyright Aastra Telecom 2008
4
+ #
5
+ # Ruby adaptation by Carlton O'Riley
6
+ #
7
+ # Internal class for PhoneDirectory object.
8
+ ########################################################################################################
9
+
10
+ module AastraXmlApi
11
+ class PhoneDirectoryEntry < Phone
12
+ @name
13
+ @telephone
14
+
15
+ # Create new name and number entry. Overrides the initialize method
16
+ # of Phone.
17
+ def initialize(name, telephone)
18
+ @name = name
19
+ @telephone = telephone
20
+ end
21
+
22
+ # Get the name associated with this entry.
23
+ def getName
24
+ @name
25
+ end
26
+
27
+ # Create XML text output for this entry.
28
+ def render
29
+ name = escape(@name)
30
+ telephone = escape(@telephone)
31
+ return "<MenuItem>\n<Prompt>#{name}</Prompt>\n<URI>#{telephone}</URI>\n</MenuItem>\n"
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,60 @@
1
+ ################################################################################
2
+ # Aastra XML API Classes - PhoneExecute
3
+ # Copyright Aastra Telecom 2008
4
+ #
5
+ # Ruby adaptation by Carlton O'Riley
6
+ #
7
+ # PhoneExecute object.
8
+ #
9
+ # Public methods
10
+ #
11
+ # Inherited from Phone
12
+ # setBeep to enable a notification beep with the object (optional)
13
+ #
14
+ # Specific to the object
15
+ # setTriggerDestroyOnExit to set the triggerDestroyOnExit tag to "yes" (optional)
16
+ # addEntry(url,interruptCall) to add an action to be executed.
17
+ #
18
+ # Example
19
+ # require 'PhoneExecute.class.php'
20
+ # execute = PhoneExecute.new
21
+ # execute.addEntry('http://myserver.com/script.php?choice=2')
22
+ # execute.addEntry('Command: Reset')
23
+ # aastra_output execute
24
+ #
25
+ ################################################################################
26
+
27
+ module AastraXmlApi
28
+ class PhoneExecute < Phone
29
+ @defaultIndex
30
+ @triggerDestroyOnExit
31
+
32
+ # Add a url (action to be performed). If interruptCall is not nil, then
33
+ # then if a dial action is given, the current call will be put on hold.
34
+ # Default behavior is to not allow a current active call to be
35
+ # interrupted.
36
+ def addEntry(url, interruptCall=nil)
37
+ @entries += [PhoneExecuteEntry.new(url, interruptCall)]
38
+ end
39
+
40
+ # When set, the previous user interface XML object is destroyed
41
+ # if its destroyOnExit tag is also set to yes.
42
+ def setTriggerDestroyOnExit
43
+ @triggerDestroyOnExit = "yes"
44
+ end
45
+
46
+ # Create XML text output.
47
+ def render
48
+ title = escape(@title)
49
+ out = "<PhoneExecute"
50
+ out += " Beep=\"yes\"" if @beep == "yes"
51
+ out += " triggerDestroyOnExit=\"yes\"" if @triggerDestroyOnExit == "yes"
52
+ out += ">\n"
53
+ @entries.each do |entry|
54
+ out += entry.render
55
+ end
56
+ out += "</PhoneExecute>\n"
57
+ return out
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,32 @@
1
+ ################################################################################
2
+ # Aastra XML API Classes - PhoneExecuteEntry
3
+ # Firmware 1.4.1 or better
4
+ # Copyright Aastra Telecom 2008
5
+ #
6
+ # Ruby adaptation by Carlton O'Riley
7
+ #
8
+ # Internal class for PhoneExecute object.
9
+ ################################################################################
10
+
11
+ module AastraXmlApi
12
+ class PhoneExecuteEntry < Phone
13
+ @url
14
+ @interruptCall
15
+
16
+ # Create a new action to be performed. if interruptCall is not nil then
17
+ # a currently active call can be interrupted by this action.
18
+ def initialize(url, interruptCall)
19
+ @url = url
20
+ @interruptCall = interruptCall
21
+ end
22
+
23
+ # Create XML text output for this entry.
24
+ def render
25
+ url = escape(@url)
26
+ xml = "<ExecuteItem URI=\"#{url}\""
27
+ xml += " interruptCall=\"no\"" if @interruptCall == "no"
28
+ xml += "/>\n"
29
+ return xml
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,119 @@
1
+ ################################################################################
2
+ # Aastra XML API Classes - FormattedPhoneTextScreen
3
+ # Copyright Aastra Telecom 2008
4
+ #
5
+ # PhoneFormattedTextScreen object.
6
+ #
7
+ # Public methods
8
+ #
9
+ # Inherited from Phone
10
+ # setDestroyOnExit to set DestroyonExit parameter to 'yes', 'no' by default (optional)
11
+ # setCancelAction(uri) to set the cancel parameter with the URI to be called on Cancel (optional)
12
+ # setBeep to enable a notification beep with the object (optional)
13
+ # setLockIn to set the Lock-in tag to 'yes' (optional)
14
+ # setAllowAnswer to set the allowAnswer tag to 'yes' (optional)
15
+ # setTimeout(timeout) to define a specific timeout for the XML object (optional)
16
+ # addSoftkey(index, label, uri) to add custom softkeys to the object (optional)
17
+ # addIcon(index,icon) to add custom icons to the object (optional)
18
+ # setRefresh(timeout,URL) to add Refresh parameters to the object (optional)
19
+ #
20
+ # Specific to the object
21
+ # addLine(text,size,align) to add a formatted line
22
+ # setScrollStart(height) to define the beginning of the scrolling section and its height
23
+ # setScrollEnd to define the end of the scrolling section
24
+ # setAllowDTMF to allow DTMF passthrough on the object
25
+ # setDoneAction(uri) to set the URI to be called when the user selects the default "Done" key (optional)
26
+ #
27
+ # Example
28
+ # require 'PhoneFormattedTextScreen.rb'
29
+ # ftext = PhoneFormattedTextScreen.new
30
+ # ftext.setDestroyOnExit
31
+ # ftext.addLine('Formatted Screen', 'double', 'center')
32
+ # ftext.setScrollStart('2')
33
+ # ftext.addLine('Scrolled text1')
34
+ # ftext.addLine('Scrolled text2')
35
+ # ftext.addLine('Scrolled text3')
36
+ # ftext.addLine('Scrolled text4')
37
+ # ftext.addLine('Scrolled text5')
38
+ # ftext.setScrollEnd
39
+ # ftext.addLine('Footer',NULL,'center')
40
+ # ftext.addSoftkey('1', 'Label', 'http://myserver.com/script.php?action=1','1')
41
+ # ftext.addSoftkey('6', 'Exit', 'SoftKey:Exit')
42
+ # ftext.addIcon('1', 'Icon:Envelope')
43
+ # aastra_output ftext
44
+ #
45
+ ################################################################################
46
+
47
+ module AastraXmlApi
48
+ class PhoneFormattedTextScreen < Phone
49
+ @doneAction
50
+ @allowDTMF
51
+
52
+ # Add a line of formatted text. size can only be 'normal' (default)
53
+ # or 'double'. align can be one of 'left' (default), 'center',
54
+ # or 'right'.
55
+ def addLine(text, size=nil, align=nil)
56
+ @entries += [PhoneFormattedTextScreenEntry.new(text, size, align, 'normal')]
57
+ end
58
+
59
+ # Starts the beginning of a scrolling section on the display. If height
60
+ # is not given, then all available space is used to display the scrolling
61
+ # section. Otherwise, height cannot be bigger than 2.
62
+ def setScrollStart(height=nil)
63
+ @entries += [PhoneFormattedTextScreenEntry.new(nil, height, nil, 'scrollstart')]
64
+ end
65
+
66
+ # Sets the end of a scrolling section on the display.
67
+ def setScrollEnd
68
+ @entries += [PhoneFormattedTextScreenEntry.new(nil, nil, nil, 'scrollend')]
69
+ end
70
+
71
+ # Defines URI to call when the user selects the 'Done' softkey.
72
+ def setDoneAction(uri)
73
+ @doneAction = uri
74
+ end
75
+
76
+ # Allows keypad strokes to generate DTMF when a call is in progress
77
+ # while this object is displayed.
78
+ def setAllowDTMF
79
+ @allowDTMF = "yes"
80
+ end
81
+
82
+ # Create XML text output.
83
+ def render
84
+ out = "<PhoneFormattedTextScreen"
85
+ out += " destroyOnExit=\"yes\"" if @destroyOnExit == "yes"
86
+ if not @cancelAction.nil? then
87
+ cancelAction = escape(@cancelAction)
88
+ out += " cancelAction=\"#{cancelAction}\""
89
+ end
90
+ if not @doneAction.nil? then
91
+ doneAction = escape(@doneAction)
92
+ out += " doneAction=\"#{doneAction}\""
93
+ end
94
+ out += " Beep=\"yes\"" if @beep == "yes"
95
+ out += " LockIn=\"yes\"" if @lockin == "yes"
96
+ out += " allowAnswer=\"yes\"" if @allowAnswer == "yes"
97
+ out += " Timeout=\"#{@timeout}\"" if @timeout != 0
98
+ out += " allowDTMF=\"#{yes}\"" if @allowDTMF == "yes"
99
+ out += ">\n"
100
+ @entries.each do |entry|
101
+ out += entry.render
102
+ end
103
+ @softkeys.each do |softkey|
104
+ out += softkey.render
105
+ end
106
+ iconList = 0
107
+ @icons.each do |icon|
108
+ if iconList == 0 then
109
+ out += "<IconList>\n"
110
+ iconList = 1
111
+ end
112
+ out += icon.render
113
+ end
114
+ out += "</IconList>\n" if iconList != 0
115
+ out += "</PhoneFormattedTextScreen>\n"
116
+ return out
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,50 @@
1
+ ################################################################################
2
+ # Aastra XML API Classes - PhoneFormattedTextScreenEntry
3
+ # Firmware 2.0 or better
4
+ # Copyright Aastra Telecom 2008
5
+ #
6
+ # Ruby adaptation by Carlton O'Riley
7
+ #
8
+ # Internal class for PhoneFormattedTextScreen object.
9
+ ################################################################################
10
+
11
+ module AastraXmlApi
12
+ class PhoneFormattedTextScreenEntry < Phone
13
+ @text
14
+ @size
15
+ @align
16
+ @type
17
+
18
+ # Creates new formatted text entry. size is one of 'normal' (default)
19
+ # or 'double'. align is one of 'left' (default), 'center', or 'right'.
20
+ # type must be one of 'normal', 'scrollstart', or 'scrollend'.
21
+ def initialize(text, size, align, type)
22
+ if size == 'double' then
23
+ @text = convert_high_ascii(text)
24
+ else
25
+ @text = text
26
+ end
27
+ @size = size
28
+ @align = align
29
+ @type = type
30
+ end
31
+
32
+ # Create XML text output for this entry.
33
+ def render
34
+ case @type
35
+ when "normal"
36
+ xml = "<Line"
37
+ xml += " Size=\"#{@size}\"" if not @size.nil?
38
+ xml += " Align=\"#{@align}\"" if not @align.nil?
39
+ xml += ">"
40
+ xml += "#{escape(@text)}</Line>\n"
41
+ when "scrollstart"
42
+ xml = "<Scroll"
43
+ xml += " Height=\"#{@size}\"" if not @size.nil?
44
+ xml += ">\n"
45
+ when "scrollend" then xml = "</Scroll>\n"
46
+ end
47
+ return xml
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,187 @@
1
+ require 'GD'
2
+
3
+ ################################################################################
4
+ # Aastra XML API Classes - Aastra XML API Classes - PhoneGDImage
5
+ # Copyright Aastra Telecom 2008
6
+ #
7
+ # Ruby adaptation by Carlton O'Riley
8
+ #
9
+ # Firmware 2.2.0 or better
10
+ #
11
+ # PhoneGDImage for PhoneImageScreen and PhoneImageScreen.
12
+ #
13
+ # ruby needs ruby-gd gem installed
14
+ # ------------------------------
15
+ #
16
+ # Public methods
17
+ #
18
+ # drawttftext(fontsize,angle,x,y,text,colorIndex,fontfile)
19
+ # Writes text to the image using TrueType fonts
20
+ # fontsize The font size. Depending on your version of GD, this should be specified as the pixel
21
+ # size (GD1) or point size (GD2)
22
+ # angle The angle in degrees, with 0 degrees being left-to-right reading text. Higher values
23
+ # represent a counter-clockwise rotation. For example, a value of 90 would result in
24
+ # bottom-to-top reading text.
25
+ # x,y The coordinates given by x and y will define the basepoint of the first character
26
+ # (roughly the lower-left corner of the character).
27
+ # colorIndex 0=White 1=Black
28
+ # fontfile Location and name of the ttf file to use
29
+ #
30
+ # drawtext(fontsize,x,y,text,colorIndex)
31
+ # Writes text to the image using built-in font
32
+ # fontsize The font size. From 1 to 5
33
+ # x,y The coordinates given by x and y will define the basepoint of the first character
34
+ # (roughly the lower-left corner of the character).
35
+ # colorIndex 0=White 1=Black
36
+ #
37
+ # rectangle(x1,y1,x2,y2,colorIndex,filled)
38
+ # Creates a rectangle starting at the specified coordinates.
39
+ # x1,y1 Upper left x,y coordinate. 0,0 is the top left corner of the image.
40
+ # x2,y2 Bottom right x,y coordinate
41
+ # colorIndex 0=White 1=Black
42
+ # filled Boolean, optional (default if False)
43
+ #
44
+ # ellipse(cx,cy,width,height,colorIndex,filled)
45
+ # Draws an ellipse centered at the specified coordinates.
46
+ # cx,cy x-coordinate and y-coordinate of the center
47
+ # width the ellipse width
48
+ # height the ellipse height
49
+ # colorIndex 0=White 1=Black
50
+ # filled Boolean, optional (default if False)
51
+ #
52
+ # line(x1,y1,x2,y2,colorIndex)
53
+ # Draws a line
54
+ # x1,y1 x,y coordinates for the first point
55
+ # x2,y2 x,y coordinates for the second point
56
+ # colorIndex 0=White 1=Black
57
+ #
58
+ # setGDImage(image)
59
+ # Imports an externally generated GD image
60
+ # image GD image to import
61
+ #
62
+ # getGDImage()
63
+ # Exports the current GD image
64
+ #
65
+ # setFontPath(fontpath)
66
+ # Set directory path for the fonts to use
67
+ # fontpath Directory for the ttf fonts
68
+ # Default value
69
+ # Windows based platform C:\Windows\Fonts
70
+ # Linux based platform ../fonts
71
+ # Mac OS X based platform ../fonts
72
+ # Rails based platform RAILS_ROOT/fonts
73
+ #
74
+ # Example 1
75
+ # require 'PhoneGDImage.rb'
76
+ # phoneImageGD = PhoneGDImage.new
77
+ # time = Time.now.strftime("%H:%M")
78
+ # phoneImageGD.drawttftext(30, 0, 10, 39, time, 1,'Ni7seg.ttf')
79
+ #
80
+ # Example 2
81
+ # require 'PhoneGDImage.rb'
82
+ # phoneImageGD = PhoneGDImage.new
83
+ # utf8text = "&#19996;&#19997;&#19998;&#19999;&#20024;"
84
+ # phoneImageGD.drawttftext(20, 0, 5, 35, utf8text, 1, 'arialuni.ttf')
85
+ #
86
+ ################################################################################
87
+
88
+ module AastraXmlApi
89
+ class PhoneGDImage
90
+ @img
91
+ @white
92
+ @black
93
+ @blackNoAntiAliasing
94
+ @font
95
+ @fontpath
96
+
97
+ # Creates a new GD image of size 144x40 (maximum allowed on phone). Also
98
+ # creates black and white colors to be used and sets default font path
99
+ # based on whether this is running under rails or a specific
100
+ # operating system.
101
+ def initialize
102
+ # create image
103
+ @img = GD::Image.new(144, 40)
104
+
105
+ # define black and white
106
+ @white = @img.colorAllocate(255, 255, 255)
107
+ @black = @img.colorAllocate(0, 0, 0)
108
+
109
+ # black and white only so disable anti-aliasing
110
+ @black *= -1
111
+ @white *= -1
112
+
113
+ # define a default font path
114
+ if defined?(RAILS_ROOT) then
115
+ @fontpath = "#{RAILS_ROOT}/fonts"
116
+ else
117
+ os = RUBY_PLATFORM.downcase
118
+ @fontpath = "C:\\Windows\\Fonts" if not os.scan(/win/).nil?
119
+ @fontpath = "../fonts" if not os.scan(/linux$/).nil?
120
+ @fontpath = "../fonts" if not os.scan(/darwin\d+\.\d+$/).nil?
121
+ end
122
+ ENV['GDFONTPATH'] = @fontpath
123
+ end
124
+
125
+ # Set font path for GD.
126
+ def setFontPath(fontpath)
127
+ @fontpath = fontpath
128
+ ENV['GDFONTPATH'] = @fontpath
129
+ end
130
+
131
+ # Draw text on the image using a specific true type font.
132
+ # See GD documentation for parameters.
133
+ def drawttftext(size, angle, x, y, text, colorIndex, font)
134
+ @img.stringTTF(getColor(colorIndex), font, size, angle, x, y, text)
135
+ end
136
+
137
+ # Draw text on the image.
138
+ def drawtext(size, x, y, text, colorIndex)
139
+ @img.string(size, x, y, text, getColor(colorIndex))
140
+ end
141
+
142
+ # Set the image from an externally created GD image.
143
+ def setGDImage(image)
144
+ @img = image
145
+ end
146
+
147
+ # Get the GD image created.
148
+ def getGDImage
149
+ return @img
150
+ end
151
+
152
+ # Draw a rectangle on the image. Rectangle will be unfilled by default.
153
+ def rectangle(x1, y1, x2, y2, colorIndex, filled=false)
154
+ if filled then
155
+ @img.filledRectangle(x1, y1, x2, y2, getColor(colorIndex))
156
+ else
157
+ @img.rectangle(x1, y1, x2, y2, getColor(colorIndex))
158
+ end
159
+ end
160
+
161
+ # Draw an ellipse on the image. Ellipse will be unfilled by default.
162
+ def ellipse(cx, cy, width, height, colorIndex, filled=false)
163
+ if filled then
164
+ @img.filledEllipse(cx, cy, width, height, 0, 360, getColor(colorIndex))
165
+ else
166
+ @img.ellipse(cx, cy, width, height, 0, 360, getColor(colorIndex))
167
+ end
168
+ end
169
+
170
+ # Draw a line on the image. Line will be solid by default.
171
+ def line(x1, y1, x2, y2, colorIndex, dashed=false)
172
+ if dashed then
173
+ @img.dashedLine(x1, y2, x2, y2, getColor(colorIndex))
174
+ else
175
+ @img.line(x1, y2, x2, y2, getColor(colorIndex))
176
+ end
177
+ end
178
+
179
+ # Get the GD color element based on an index.
180
+ # 0:: white
181
+ # 1:: black
182
+ def getColor(index)
183
+ return @white if index == 0
184
+ return @black
185
+ end
186
+ end
187
+ end