hoiio 1.0.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.
@@ -0,0 +1,84 @@
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 Number < Request
26
+ # Manage Number API Request
27
+ # Hoiio provides dedicated virtual phone numbers to developers for your IVR applications.
28
+ # This service enables your IVR application to receive incoming calls and allows you to create customer hotlines,
29
+ # call filtering services etc using our IVR API.
30
+ #
31
+ # The Number API will allow developers to have full control over how they assign their Hoiio Numbers to their IVR applications.
32
+
33
+ # Creates a new instance of Number
34
+ # @param client a shared object used to cache authentication data
35
+ def initialize(client)
36
+ super client
37
+ end
38
+
39
+ # Call Get Countries API
40
+ # URL: http://developer.hoiio.com/docs/number_countries.html
41
+ # Return a list of countries for which there are Hoiio Numbers available for subscription.
42
+ def get_countries(params={})
43
+ api_post '/number/get_countries', params
44
+ end
45
+
46
+ # Call Get Choices API
47
+ # URL: http://developer.hoiio.com/docs/number_select.html
48
+ # Return a list of available Hoiio Numbers for subscription in a given country.
49
+ def get_choices(params={})
50
+ api_post '/number/get_choices', params, [:country]
51
+ end
52
+
53
+ # Call Get Rates API
54
+ # URL: http://developer.hoiio.com/docs/number_rates.html
55
+ # Retrieve the billable rate that will be charged for subscribing to a Hoiio Number via the number/subscribe API.
56
+ def get_rates(params={})
57
+ api_post '/number/get_rates', params, [:country]
58
+ end
59
+
60
+ # Call Subscribe API
61
+ # URL: http://developer.hoiio.com/docs/number_subscribe.html
62
+ # Subscribe for a new Hoiio Number or extend an existing subscription of a Hoiio Number.
63
+ # Hoiio Numbers can be used in IVR apps to receive incoming calls from your users.
64
+ def subscribe(params={})
65
+ api_post '/number/subscribe', params, [:number, :duration]
66
+ end
67
+
68
+ # Call Update Forwarding API
69
+ # URL: http://developer.hoiio.com/docs/number_configure.html
70
+ # Configure the URL that the incoming call notification and incoming SMS notification
71
+ # for your Hoiio Number will be sent to.
72
+ def update_forwarding(params={})
73
+ api_post '/number/update_forwarding', params, [:number]
74
+ end
75
+
76
+ # Call Get Active API
77
+ # URL: http://developer.hoiio.com/docs/number_status.html
78
+ # Retrieve the list of Hoiio Numbers that is assigned to your application and their current configuration
79
+ def get_active(params={})
80
+ api_post '/number/get_active', params
81
+ end
82
+
83
+ end
84
+ end
@@ -0,0 +1,81 @@
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 SMS < Request
26
+ # Manage SMS API Request
27
+ # SMS is one of the most popular forms of mobile communications. Chatting between friends,
28
+ # 2-factor authentication by your bank's online portal, receiving alerts from your stock market applications
29
+ # and SMS marketing are just some of the more popular uses of SMS.
30
+ #
31
+ # The SMS API component of Hoiio API allows developers to send/receive SMS to/from more than 200 countries
32
+ # around the world at a very competitive rate.
33
+
34
+ # Creates a new instance of SMS
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/sms_send.html
42
+ # Send SMS to mobile numbers in over 200 countries
43
+ def send(params={}, bulk_send = false)
44
+ if bulk_send
45
+ api_post '/sms/bulk_send', params, [:dest, :msg]
46
+ else
47
+ api_post '/sms/send', params, [:dest, :msg]
48
+ end
49
+ end
50
+
51
+ # Call Bulk_Send API
52
+ # URL: http://developer.hoiio.com/docs/sms_bulk_send.html
53
+ # Send SMS in bulk (up to 1000 messages) to any mobile numbers in more than 200 countries
54
+ def bulk_send(params={})
55
+ self.send params, true
56
+ end
57
+
58
+ # Call Get History API
59
+ # URL: http://developer.hoiio.com/docs/sms_history.html
60
+ # Retrieve the history of SMS sent or received by this application.
61
+ def get_history(params={})
62
+ api_post '/sms/get_history', params
63
+ end
64
+
65
+ # Call Get Rate API
66
+ # URL: http://developer.hoiio.com/docs/sms_rate.html
67
+ # Retrieve the billable rate that will be charged for each multipart SMS message made or
68
+ # receive via the sms/send API and sms/receive API respectively.
69
+ def get_rate(params={})
70
+ api_post '/sms/get_rate', params, [:dest, :incoming], true
71
+ end
72
+
73
+ # Call Query Status API
74
+ # URL: http://developer.hoiio.com/docs/sms_status.html
75
+ # Query the current status of a SMS sent previously via sms/send API.
76
+ def query_status(params={})
77
+ api_post '/sms/query_status', params, [:txn_ref]
78
+ end
79
+
80
+ end
81
+ end
@@ -0,0 +1,50 @@
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 User < Request
26
+ # Manage User API Request
27
+ # The User API will allow developers to check their credit balances and other account information.
28
+
29
+ # Creates a new instance of User
30
+ # @param client a shared object used to cache authentication data
31
+ def initialize(client)
32
+ super client
33
+ end
34
+
35
+ # Call Get Balance API
36
+ # URL: http://developer.hoiio.com/docs/account_credit.html
37
+ # Retrieve the current credit balance of an account.
38
+ def get_balance
39
+ api_post '/user/get_balance'
40
+ end
41
+
42
+ # Call Get Info API
43
+ # URL: http://developer.hoiio.com/docs/account_info.html
44
+ # Retrieve the general information of your account.
45
+ def get_info
46
+ api_post '/user/get_info'
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,82 @@
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 Voice < Request
26
+ # Manage Voice API Request
27
+ # The Voice API component of Hoiio API provides developers access to telephony services in
28
+ # more than 200 countries around the world. You will be able to initiate phone calls to any mobile phones,
29
+ # land lines or create call conferences just by making an API request to our servers.
30
+ # You can connect 2 phones using the Call API, or connect multiple phones using the Conference API.
31
+
32
+ # Creates a new instance of Voice
33
+ # @param client a shared object used to cache authentication data
34
+ def initialize(client)
35
+ super client
36
+ end
37
+
38
+ # Call Voice/Call API
39
+ # URL: http://developer.hoiio.com/docs/voice_call.html
40
+ # Dial out to 2 destination number and connect them together in a phone conversation
41
+ def call(params={})
42
+ api_post '/voice/call', params, [:dest2]
43
+ end
44
+
45
+ # Call Conference API
46
+ # URL: http://developer.hoiio.com/docs/voice_conference.html
47
+ # Call a list of destination numbers and place them in a conference call
48
+ def conference(params={})
49
+ api_post '/voice/conference', params, [:dest]
50
+ end
51
+
52
+ # Call Hangup API
53
+ # URL: http://developer.hoiio.com/docs/voice_hangup.html
54
+ # Hangup a call that is currently in progress.
55
+ # You can call this API at any point in time when a call is in progress to hang up the call.
56
+ def hangup(params={})
57
+ api_post '/voice/hangup', params, [:txn_ref]
58
+ end
59
+
60
+ # Call Get History API
61
+ # URL: http://developer.hoiio.com/docs/voice_callhistory.html
62
+ # Retrieve the history of calls, including current ongoing calls.
63
+ def get_history(params={})
64
+ api_post '/voice/get_history', params
65
+ end
66
+
67
+ # Call Get Rate API
68
+ # URL: http://developer.hoiio.com/docs/voice_rate.html
69
+ # Retrieve the billable rate that will be charged for calls made via the voice/call API.
70
+ def get_rate(params={})
71
+ api_post '/voice/get_rate', params, [:dest1, :dest2]
72
+ end
73
+
74
+ # Call Query Status API
75
+ # URL: http://developer.hoiio.com/docs/voice_status.html
76
+ # Query the current status of a call.
77
+ def query_status(params={})
78
+ api_post '/voice/query_status', params, [:txn_ref]
79
+ end
80
+
81
+ end
82
+ end
@@ -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
+ module Hoiio
25
+
26
+ #
27
+ # Hoiio::Client class caches basic authentication parameters
28
+ # After being instantiated, a Hoiio::Client object's data will be shared among
29
+ # all request object, which is subclass of Hoiio::Request
30
+ #
31
+ # #How to instantiated a client object:
32
+ #
33
+ # @client = Hoiio::Client.new app_id, access_token
34
+ #
35
+
36
+ class Client
37
+
38
+ # @attr_reader app_id your Hoiio application's app_id. Please keep this securely
39
+ attr_reader :app_id
40
+
41
+ # @attr_reader all api request objects
42
+ attr_reader :user, :sms, :fax, :number, :ivr, :voice
43
+
44
+ # @attr_accessor access_token used to stored access_token of a user.
45
+ # At any point in time, you can reset the access_token by calling @client.access_token = "new token"
46
+ # and it will be available to all subsequent calls to Hoiio API
47
+ attr_accessor :access_token
48
+
49
+ # Create an instance of Hoiio:Client
50
+ # @param app_id application id of your Hoiio application
51
+ # @param access_token access_token of your Hoiio application
52
+ def initialize(app_id, access_token)
53
+ @app_id, @access_token = app_id.strip, access_token.strip
54
+ set_up_resources
55
+ end
56
+
57
+ private
58
+
59
+ # Set up sub resources to be used to call Hoiio API
60
+ # This method passes the @client object to the initialize block of all API request.
61
+ def set_up_resources
62
+ @user = Hoiio::User.new self
63
+ @sms = Hoiio::SMS.new self
64
+ @voice = Hoiio::Voice.new self
65
+ @fax = Hoiio::Fax.new self
66
+ @number = Hoiio::Number.new self
67
+ @ivr = Hoiio::IVR.new self
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,47 @@
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
+
26
+ class ServerError < StandardError
27
+ end
28
+
29
+ class RequestError < StandardError
30
+ attr_reader :code
31
+
32
+ def initialize(message, code=nil)
33
+ super message
34
+ @code = code
35
+ end
36
+ end
37
+
38
+ class ResponseError < StandardError
39
+ attr_reader :code
40
+
41
+ def initialize(message, code=nil)
42
+ super message
43
+ @code = code
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,79 @@
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 Request
26
+
27
+ # A wrapper class to all API request object
28
+ # This class uses HTTParty to initiate requests to Hoiio API
29
+ # and process the response before passing to its subclass
30
+
31
+ # HTTParty is used to fire requests
32
+ include HTTParty
33
+ base_uri "https://secure.hoiio.com/open"
34
+
35
+ include RequestUtil
36
+ include ResponseUtil
37
+
38
+ # Create an instance of Request object using Hoiio::Client object
39
+ # Inside @client object, app_id and access_token are stored to make API request
40
+ def initialize(client)
41
+ @client = client
42
+ end
43
+
44
+ # Send a request to Hoiio API
45
+ # @param path path of the request
46
+ # @param params all params (required and optional) to pass along the request
47
+ # @param required_param_names array of names of all the required params that need to be passed along the request
48
+ # @param mutually_exclusive mark whether to check for mutual exclusivity of required params
49
+ # (meaning only 1 required param can be present)
50
+ #
51
+ # @return response from Hoiio API after being processed
52
+ # @raise ServerError if response's HTTP status is not 200 OK.
53
+ def api_post(path, params={}, required_param_names=[], mutually_exclusive=false)
54
+
55
+ if mutually_exclusive
56
+ check_for_mutual_exclusivity(required_param_names, params)
57
+ elsif !required_param_names.nil? && !required_param_names.empty?
58
+ check_nil_or_empty(required_param_names, params)
59
+ end
60
+
61
+ options = Hash.new()
62
+ options[:body] = params
63
+
64
+ options.merge!({:body => {:app_id => @client.app_id, :access_token => @client.access_token}}){
65
+ |key, oldval, newval| oldval.merge!(newval)
66
+ }
67
+
68
+ response = self.class.post path, options
69
+ case response.code
70
+ when 200
71
+ process_response response
72
+ else
73
+ raise Hoiio::ServerError
74
+ end
75
+ end
76
+
77
+ end
78
+
79
+ end