hoiio 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Steve Van
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,78 @@
1
+ # Hoiio
2
+
3
+ This is Ruby SDK for [Hoiio API][homepage]
4
+
5
+ Hoiio API is set of telephony API that integrate telephony services - phone calls, conference, IVR (Interactive Voice Responses), Fax and SMS - into your services and website easily.
6
+
7
+ Read the documentation at http://hoiio.readthedocs.org/
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'hoiio'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install hoiio
22
+
23
+ ## Getting Started With Hoiio Ruby Gem
24
+
25
+
26
+ ### Setup
27
+
28
+ ``` ruby
29
+ require 'hoiio'
30
+
31
+ # Hoiio Application Credentials
32
+ app_id = ''
33
+ access_token = ''
34
+
35
+ # set up a client to talk to the Twilio REST API
36
+ @client = Hoiio::Client.new app_id, access_token
37
+ ```
38
+
39
+ ### Usage
40
+
41
+ After a @client object has been created, app_id and access_token are cached and used for subsequent API calls.
42
+ Normally, app_id won't change, but you can modify the client's access_token by reassigning it to a new one.
43
+
44
+ All API's URI specified in [Hoiio Developer's website][documentation] are included in this SDK and can be accessed
45
+ conveniently.
46
+
47
+ For example, @client.sms will make all SMS APIs with the same name available, i.e: @client.sms.send will call /sms/send,
48
+ @client.sms.query_status will fire a request to /sms/query_status (as specified [here][sms_query_status]).
49
+
50
+ ### Send an SMS
51
+
52
+ ``` ruby
53
+ # send an SMS using Hoiio
54
+ @client.sms.send(
55
+ :dest => '+6591234567',
56
+ :msg => 'Hello Steve',
57
+ :notify_url => 'http://dev.example.com/sms/notify'
58
+ )
59
+ ```
60
+
61
+ ### Make a call
62
+
63
+ ``` ruby
64
+ # call a destination number using Hoiio
65
+ @client.voice.call(
66
+ :dest2 => '+6591234567',
67
+ :caller_id => 'private'
68
+ )
69
+ ```
70
+
71
+ ## API References
72
+
73
+ Visit [our API site][documentation] to learn more about our powerful communication API.
74
+
75
+
76
+ [homepage]:http://developer.hoiio.com/
77
+ [documentation]:http://developer.hoiio.com/docs/index.html
78
+ [sms_query_status]:http://developer.hoiio.com/docs/sms_status.html
@@ -0,0 +1,44 @@
1
+ #Copyright (C) 2012 Hoiio Pte Ltd (http://www.hoiio.com)
2
+ #
3
+ #Permission is hereby granted, free of charge, to any person
4
+ #obtaining a copy of this software and associated documentation
5
+ #files (the "Software"), to deal in the Software without
6
+ #restriction, including without limitation the rights to use,
7
+ # copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ #copies of the Software, and to permit persons to whom the
9
+ #Software is furnished to do so, subject to the following
10
+ #conditions:
11
+ #
12
+ #The above copyright notice and this permission notice shall be
13
+ #included in all copies or substantial portions of the Software.
14
+ #
15
+ #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ #EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ #OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ #NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ #HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ #WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ #FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ #OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ require 'httparty'
25
+ require 'json'
26
+ require 'cgi'
27
+
28
+ require 'hoiio-ruby/version/version' unless defined?(Hoiio::VERSION)
29
+ require 'hoiio-ruby/errors'
30
+ require 'hoiio-ruby/util/request_util'
31
+ require 'hoiio-ruby/util/response_util'
32
+ require 'hoiio-ruby/request'
33
+ require 'hoiio-ruby/client'
34
+ require 'hoiio-ruby/api/user'
35
+ require 'hoiio-ruby/api/sms'
36
+ require 'hoiio-ruby/api/voice'
37
+ require 'hoiio-ruby/api/fax'
38
+ require 'hoiio-ruby/api/ivr'
39
+ require 'hoiio-ruby/api/ivr/start'
40
+ require 'hoiio-ruby/api/ivr/middle'
41
+ require 'hoiio-ruby/api/ivr/end'
42
+ require 'hoiio-ruby/api/number'
43
+
44
+ STATUS_SUCCESS = "success_ok"
@@ -0,0 +1,71 @@
1
+ #Copyright (C) 2012 Hoiio Pte Ltd (http://www.hoiio.com)
2
+ #
3
+ #Permission is hereby granted, free of charge, to any person
4
+ #obtaining a copy of this software and associated documentation
5
+ #files (the "Software"), to deal in the Software without
6
+ #restriction, including without limitation the rights to use,
7
+ # copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ #copies of the Software, and to permit persons to whom the
9
+ #Software is furnished to do so, subject to the following
10
+ #conditions:
11
+ #
12
+ #The above copyright notice and this permission notice shall be
13
+ #included in all copies or substantial portions of the Software.
14
+ #
15
+ #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ #EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ #OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ #NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ #HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ #WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ #FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ #OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+
25
+ module Hoiio
26
+ class Fax < Request
27
+ # Manage the Fax API Request
28
+ # Fax API provides developers access to faxing capabilities by using our simple API.
29
+ # Developers can use the Fax API to send, and also to receive fax via Hoiio virtual numbers.
30
+ # Charges for fax is similar to our Voice API - by per minute usage.
31
+ # This should not come as a surprise since fax is delivered over phone lines.
32
+ # Note that Fax is only supported in Singapore
33
+
34
+ # Creates a new instance of Fax
35
+ # @param client a shared object used to cache authentication data
36
+ def initialize(client)
37
+ super client
38
+ end
39
+
40
+ # Call Send API
41
+ # URL: http://developer.hoiio.com/docs/fax_send.html
42
+ # Send a fax file to a fax number
43
+ # Fax is only supported in Singapore at the moment
44
+ def send(params={})
45
+ api_post '/fax/send', params, [:dest, :file]
46
+ end
47
+
48
+ # Call Get History API
49
+ # URL: http://developer.hoiio.com/docs/fax_history.html
50
+ # Retrieve the history of faxes sent by this application, including current ongoing faxes
51
+ def get_history(params={})
52
+ api_post '/fax/get_history', params
53
+ end
54
+
55
+ # Call Get Rate API
56
+ # URL: http://developer.hoiio.com/docs/fax_rate.html
57
+ # Retrieves the billable rate that will be charged for fax sent or received via the fax/send API
58
+ # and fax/receive API respectively
59
+ def get_rate(params={})
60
+ api_post '/fax/get_rate', params, [:dest, :incoming], true
61
+ end
62
+
63
+ # Call Query Status API
64
+ # URL: http://developer.hoiio.com/docs/fax_status.html
65
+ # Query the current status of a fax made previously via fax/send API
66
+ def query_status(params={})
67
+ api_post '/fax/query_status', params, [:txn_ref]
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,52 @@
1
+ #Copyright (C) 2012 Hoiio Pte Ltd (http://www.hoiio.com)
2
+ #
3
+ #Permission is hereby granted, free of charge, to any person
4
+ #obtaining a copy of this software and associated documentation
5
+ #files (the "Software"), to deal in the Software without
6
+ #restriction, including without limitation the rights to use,
7
+ # copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ #copies of the Software, and to permit persons to whom the
9
+ #Software is furnished to do so, subject to the following
10
+ #conditions:
11
+ #
12
+ #The above copyright notice and this permission notice shall be
13
+ #included in all copies or substantial portions of the Software.
14
+ #
15
+ #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ #EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ #OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ #NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ #HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ #WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ #FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ #OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ module Hoiio
25
+ class IVR < Request
26
+
27
+ # Hoiio's IVR API allows developers to easily create IVR menus like the above using RESTful APIs.
28
+ # This can be achieved without the need for technical telecommunication knowledge.
29
+ # Coupled with our Hoiio Numbers and Text-to-Speech (TTS) technology, you can get started instantly without hassle.
30
+
31
+ # @attr_reader 3 blocks of Hoiio IVR
32
+ attr_reader :start, :middle, :end
33
+
34
+ # Creates a new instance of Fax
35
+ # @param client a shared object used to cache authentication data
36
+ def initialize(client)
37
+ super client
38
+ @client = client
39
+ set_up
40
+ end
41
+
42
+ private
43
+
44
+ # Set up the sub resources using shared @client object
45
+ def set_up
46
+ @start = Hoiio::IVRBlock::Start.new @client
47
+ @middle = Hoiio::IVRBlock::Middle.new @client
48
+ @end = Hoiio::IVRBlock::End.new @client
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,55 @@
1
+ #Copyright (C) 2012 Hoiio Pte Ltd (http://www.hoiio.com)
2
+ #
3
+ #Permission is hereby granted, free of charge, to any person
4
+ #obtaining a copy of this software and associated documentation
5
+ #files (the "Software"), to deal in the Software without
6
+ #restriction, including without limitation the rights to use,
7
+ # copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ #copies of the Software, and to permit persons to whom the
9
+ #Software is furnished to do so, subject to the following
10
+ #conditions:
11
+ #
12
+ #The above copyright notice and this permission notice shall be
13
+ #included in all copies or substantial portions of the Software.
14
+ #
15
+ #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ #EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ #OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ #NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ #HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ #WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ #FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ #OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ module Hoiio
25
+ module IVRBlock
26
+ class End < Request
27
+
28
+ # Manage the End block of Hoiio IVR Blocks
29
+ # See here for details: http://developer.hoiio.com/docs/ivr.html
30
+
31
+ # Creates a new instance of End IVR Block.
32
+ # @param client a shared object used to cache authentication data
33
+ def initialize(client)
34
+ super client
35
+ end
36
+
37
+ # Call the Transfer API
38
+ # URL: http://developer.hoiio.com/docs/ivr_transfer.html
39
+ # Transfer a call to another destination number anywhere in the world or a voice conference room The Transfer block will first play the message then transfer the call. If the transfer failed, you can follow up with one of the Middle or End blocks. If the transfer succeeds, you will get a notification after the transferred call has ended.
40
+ def transfer(params={})
41
+ api_post '/ivr/end/transfer', params, [:session, :dest]
42
+ end
43
+
44
+ # Call the Hangup API
45
+ # URL: http://developer.hoiio.com/docs/ivr_hangup.html
46
+ # To hang up the current call, you can use the Hangup block. Upon receiving this action, the current call will be hang up.
47
+ # The Hangup block will first play the message, hang up the call then send a notification to your notify_url.
48
+ # You cannot use any other block after using the Hangup block.
49
+ def hangup(params={})
50
+ api_post '/ivr/end/hangup', params, [:session]
51
+ end
52
+
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,70 @@
1
+ #Copyright (C) 2012 Hoiio Pte Ltd (http://www.hoiio.com)
2
+ #
3
+ #Permission is hereby granted, free of charge, to any person
4
+ #obtaining a copy of this software and associated documentation
5
+ #files (the "Software"), to deal in the Software without
6
+ #restriction, including without limitation the rights to use,
7
+ # copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ #copies of the Software, and to permit persons to whom the
9
+ #Software is furnished to do so, subject to the following
10
+ #conditions:
11
+ #
12
+ #The above copyright notice and this permission notice shall be
13
+ #included in all copies or substantial portions of the Software.
14
+ #
15
+ #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ #EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ #OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ #NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ #HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ #WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ #FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ #OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ module Hoiio
25
+ module IVRBlock
26
+ class Middle < Request
27
+
28
+ # Manage the End block of Hoiio IVR Blocks
29
+ # See here for details: http://developer.hoiio.com/docs/ivr.html
30
+
31
+ # Creates a new instance of Middle IVR Block.
32
+ # @param client a shared object used to cache authentication data
33
+ def initialize(client)
34
+ super client
35
+ end
36
+
37
+ # Call the Play API
38
+ # URL: http://developer.hoiio.com/docs/ivr_play.html
39
+ # You can use the Play block if you want to play a voice message. Our Text-to-Speech service will
40
+ # automatically generate the voice recording for the message you indicated in your API request.
41
+ # The Play block will first play the message then send a notification to your notify_url.
42
+ # You cannot use this block after you have used any of the End blocks (Transfer, Hangup).
43
+ def play(params={})
44
+ api_post '/ivr/middle/play', params, [:session]
45
+ end
46
+
47
+ # Call the Gather API
48
+ # URL: http://developer.hoiio.com/docs/ivr_gather.html
49
+ # Get user input via the telephone's keypad in IVR calls
50
+ def gather(params={})
51
+ api_post '/ivr/middle/gather', params, [:session, :notify_url]
52
+ end
53
+
54
+ # Call the Record API
55
+ # URL: http://developer.hoiio.com/docs/ivr_record.html
56
+ # Record voice messages from the user over the phone
57
+ def record(params={})
58
+ api_post '/ivr/middle/record', params, [:session, :notify_url]
59
+ end
60
+
61
+ # Call the Monitor API
62
+ # URL: http://developer.hoiio.com/docs/ivr_monitor.html
63
+ # Record the call conversation, including any voice messages
64
+ def monitor(params={})
65
+ api_post '/ivr/middle/monitor', params, [:session, :notify_url]
66
+ end
67
+
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,46 @@
1
+ #Copyright (C) 2012 Hoiio Pte Ltd (http://www.hoiio.com)
2
+ #
3
+ #Permission is hereby granted, free of charge, to any person
4
+ #obtaining a copy of this software and associated documentation
5
+ #files (the "Software"), to deal in the Software without
6
+ #restriction, including without limitation the rights to use,
7
+ # copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ #copies of the Software, and to permit persons to whom the
9
+ #Software is furnished to do so, subject to the following
10
+ #conditions:
11
+ #
12
+ #The above copyright notice and this permission notice shall be
13
+ #included in all copies or substantial portions of the Software.
14
+ #
15
+ #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ #EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ #OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ #NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ #HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ #WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ #FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ #OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ module Hoiio
25
+ module IVRBlock
26
+ class Start < Request
27
+
28
+ # Manage the Start block of Hoiio IVR Blocks
29
+ # See here for details: http://developer.hoiio.com/docs/ivr.html
30
+
31
+ # Creates a new instance of Start IVR Block.
32
+ # @param client a shared object used to cache authentication data
33
+ def initialize(client)
34
+ super client
35
+ end
36
+
37
+ # Call the Gather API
38
+ # URL: http://developer.hoiio.com/docs/ivr_dial.html
39
+ # Make a dial-out to a destination number
40
+ def dial(params={})
41
+ api_post '/ivr/start/dial', params, [:dest]
42
+ end
43
+
44
+ end
45
+ end
46
+ end