11# ruby-bandwidth
22
3- [ ![ Build] ( https://travis-ci.org/Bandwidth/ruby-bandwidth.png )] ( https://travis-ci.org/Bandwidth/ruby-bandwidth )
4-
5- Bandwidth [ Bandwidth's App Platform] ( http://ap.bandwidth.com/?utm_medium=social&utm_source=github&utm_campaign=dtolb&utm_content= ) Ruby SDK
6-
7- With ruby-bandwidth you have access to the entire set of API methods including:
8- * ** Account** - get user's account data and transactions,
9- * ** Application** - manage user's applications,
10- * ** AvailableNumber** - search free local or toll-free phone numbers,
11- * ** Bridge** - control bridges between calls,
12- * ** Call** - get access to user's calls,
13- * ** Conference** - manage user's conferences,
14- * ** ConferenceMember** - make actions with conference members,
15- * ** Domain** - get access to user's domains,
16- * ** EntryPoint** - control of endpoints of domains,
17- * ** Error** - list of errors,
18- * ** Media** - list, upload and download files to Bandwidth API server,
19- * ** Message** - send SMS/MMS, list messages,
20- * ** NumberInfo** - receive CNUM info by phone number,
21- * ** PhoneNumber** - get access to user's phone numbers,
22- * ** Recording** - mamange user's recordings.
23-
24- Also you can work with Bandwidth XML using special types (in namespace ` Bandwidth::Xml ` ).
3+ [ ![ Build] ( https://travis-ci.org/OldBandwidth/ruby-bandwidth.png )] ( https://travis-ci.org/OldBandwidth/ruby-bandwidth )
4+
5+ OldBandwidth [ OldBandwidth's App Platform] ( http://ap.bandwidth.com/?utm_medium=social&utm_source=github&utm_campaign=dtolb&utm_content= ) Ruby SDK
6+
7+ With ruby-bandwidth you have access to the entire set of API methods including:
8+
9+ - ** Account** - get user's account data and transactions,
10+ - ** Application** - manage user's applications,
11+ - ** AvailableNumber** - search free local or toll-free phone numbers,
12+ - ** Bridge** - control bridges between calls,
13+ - ** Call** - get access to user's calls,
14+ - ** Conference** - manage user's conferences,
15+ - ** ConferenceMember** - make actions with conference members,
16+ - ** Domain** - get access to user's domains,
17+ - ** EntryPoint** - control of endpoints of domains,
18+ - ** Error** - list of errors,
19+ - ** Media** - list, upload and download files to OldBandwidth API server,
20+ - ** Message** - send SMS/MMS, list messages,
21+ - ** NumberInfo** - receive CNUM info by phone number,
22+ - ** PhoneNumber** - get access to user's phone numbers,
23+ - ** Recording** - mamange user's recordings.
24+
25+ Also you can work with OldBandwidth XML using special types (in namespace ` OldBandwidth::Xml ` ).
26+
2527## Install
2628
2729Via rubygems:
@@ -32,93 +34,91 @@ or add to your Gemfile:
3234
3335 gem "ruby-bandwidth"
3436
35-
3637## Getting Started
3738
38- * Install ` ruby-bandwidth ` ,
39- * ** Get user id, api token and secret** - to use the Catapult API you need these data. You can get them [ here] ( https://catapult.inetwork.com/pages/catapult.jsf ) on the tab "Account",
40- * ** Set user id, api token and secret** - you can do that with 2 ways:
39+ - Install ` ruby-bandwidth ` ,
40+ - ** Get user id, api token and secret** - to use the Catapult API you need these data. You can get them [ here] ( https://catapult.inetwork.com/pages/catapult.jsf ) on the tab "Account",
41+ - ** Set user id, api token and secret** - you can do that with 2 ways:
4142
4243``` ruby
43- client = Bandwidth ::Client .new (:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
44-
44+ client = OldBandwidth ::Client .new (:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
45+
4546# Or you can use default client instance
4647# Do that only once
4748 Client .global_options = {:user_id => " userId" , :api_token => " token" , :api_secret => " secret" }
4849```
4950
50-
51-
5251## Usage
5352
5453All "static" (classs) functions support 2 ways to be called: with client instance as first arg or without client instance (default client instance will be used then)
5554
5655``` ruby
57- client = Bandwidth ::Client .new (:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
58- calls = Bandwidth ::Call .list(client, {:page => 1 })
56+ client = OldBandwidth ::Client .new (:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
57+ calls = OldBandwidth ::Call .list(client, {:page => 1 })
5958
6059# Or you can use default client instance
6160# You should set up its global options before using of api functions
62- calls = Bandwidth ::Call .list(:page =>1 )
61+ calls = OldBandwidth ::Call .list(:page =>1 )
6362```
6463
6564Read [ Catapult Api documentation] ( https://catapult.inetwork.com/docs/api-docs/ ) for more details
6665
6766## Examples
68- * All examples assume you have already setup your auth data!*
67+
68+ _ All examples assume you have already setup your auth data!_
6969
7070List all calls from special number
7171
7272``` ruby
73- calls = Bandwidth ::Call .list({:from => " +19195551212" })
73+ calls = OldBandwidth ::Call .list({:from => " +19195551212" })
7474 # or
75- client = Bandwidth ::Client .new (:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
76- calls = Bandwidth ::Call .list(client, {:from => " +19195551212" })
75+ client = OldBandwidth ::Client .new (:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
76+ calls = OldBandwidth ::Call .list(client, {:from => " +19195551212" })
7777```
7878
7979List all received messages
8080
8181``` ruby
82- messages = Bandwidth ::Message .list({:state => " received" })
82+ messages = OldBandwidth ::Message .list({:state => " received" })
8383 # or
84- client = Bandwidth ::Client .new (:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
85- messages = Bandwidth ::Message .list(client, {:state => " received" })
84+ client = OldBandwidth ::Client .new (:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
85+ messages = OldBandwidth ::Message .list(client, {:state => " received" })
8686```
8787
8888Send SMS
8989
9090``` ruby
91- message = Bandwidth ::Message .create({:from => " +19195551212" , :to => " +191955512142" , :text => " Test" })
91+ message = OldBandwidth ::Message .create({:from => " +19195551212" , :to => " +191955512142" , :text => " Test" })
9292 # or
93- client = Bandwidth ::Client .new (:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
94- message = Bandwidth ::Message .create(client, {:from => " +19195551212" , :to => " +191955512142" , :text => " Test" })
93+ client = OldBandwidth ::Client .new (:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
94+ message = OldBandwidth ::Message .create(client, {:from => " +19195551212" , :to => " +191955512142" , :text => " Test" })
9595```
9696
9797Send some SMSes
9898
9999``` ruby
100- statuses = Bandwidth ::Message .create([{:from => " +19195551212" , :to => " +191955512142" , :text => " Test" }, {:from => " +19195551212" , :to => " +191955512143" , :text => " Test2" }])
100+ statuses = OldBandwidth ::Message .create([{:from => " +19195551212" , :to => " +191955512142" , :text => " Test" }, {:from => " +19195551212" , :to => " +191955512143" , :text => " Test2" }])
101101 # or
102- client = Bandwidth ::Client .new (:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
103- statuses = Bandwidth ::Message .create(client, [{:from => " +19195551212" , :to => " +191955512142" , :text => " Test" }, {:from => " +19195551212" , :to => " +191955512143" , :text => " Test2" }])
102+ client = OldBandwidth ::Client .new (:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
103+ statuses = OldBandwidth ::Message .create(client, [{:from => " +19195551212" , :to => " +191955512142" , :text => " Test" }, {:from => " +19195551212" , :to => " +191955512143" , :text => " Test2" }])
104104```
105105
106- Upload file
106+ Upload file
107107
108108``` ruby
109- Bandwidth ::Media .upload(" avatar.png" , File .open (" /local/path/to/file.png" , " r" ), " image/png" )
109+ OldBandwidth ::Media .upload(" avatar.png" , File .open (" /local/path/to/file.png" , " r" ), " image/png" )
110110 # or
111- client = Bandwidth ::Client .new (:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
112- Bandwidth ::Media .upload(client, " avatar.png" , File .open (" /local/path/to/file.png" , " r" ), " image/png" )
111+ client = OldBandwidth ::Client .new (:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
112+ OldBandwidth ::Media .upload(client, " avatar.png" , File .open (" /local/path/to/file.png" , " r" ), " image/png" )
113113```
114114
115115Make a call
116116
117117``` ruby
118- call = Bandwidth ::Call .create({:from => " +19195551212" , :to => " " + 191955512142 " })
118+ call = OldBandwidth ::Call .create({:from => " +19195551212" , :to => " " + 191955512142 " })
119119 #or
120- client = Bandwidth ::Client.new(:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
121- call = Bandwidth ::Call.create(client, {:from => " + 19195551212 " , :to => " " +191955512142" })
120+ client = OldBandwidth ::Client.new(:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
121+ call = OldBandwidth ::Call.create(client, {:from => " + 19195551212 " , :to => " " +191955512142" })
122122```
123123
124124Reject incoming call
@@ -128,68 +128,71 @@ Reject incoming call
128128```
129129
130130Create a gather
131+
131132``` ruby
132133 gather = call.create_gather({:max_digits => 3 , :inter_digit_timeout => 5 , :prompt => {:sentence => " Please enter 3 digits" }})
133134```
134135
135136Start a conference
137+
136138``` ruby
137- conference = Bandwidth ::Conference .create({:from => " +19195551212" })
139+ conference = OldBandwidth ::Conference .create({:from => " +19195551212" })
138140 # or
139- client = Bandwidth ::Client .new (:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
140- conference = Bandwidth ::Conference .create(client, {:from => " +19195551212" })
141+ client = OldBandwidth ::Client .new (:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
142+ conference = OldBandwidth ::Conference .create(client, {:from => " +19195551212" })
141143```
142144
143145Connect 2 calls to a bridge
144146
145147``` ruby
146- bridge = Bandwidth ::Bridge .create({:call_ids => [call_id1, call_id2]})
148+ bridge = OldBandwidth ::Bridge .create({:call_ids => [call_id1, call_id2]})
147149 # or
148- client = Bandwidth ::Client .new (:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
149- bridge = Bandwidth ::Bridge .create(client, {:call_ids => [call_id1, call_id2]})
150+ client = OldBandwidth ::Client .new (:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
151+ bridge = OldBandwidth ::Bridge .create(client, {:call_ids => [call_id1, call_id2]})
150152```
151153
152154Search available local numbers to buy
153155
154156``` ruby
155- numbers = Bandwidth ::AvailableNumber .search_local({:state =>" NC" , :city => " Cary" })
157+ numbers = OldBandwidth ::AvailableNumber .search_local({:state =>" NC" , :city => " Cary" })
156158 # or
157- client = Bandwidth ::Client .new (:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
158- numbers = Bandwidth ::AvailableNumber .search_local(client, {:state =>" NC" , :city => " Cary" })
159+ client = OldBandwidth ::Client .new (:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
160+ numbers = OldBandwidth ::AvailableNumber .search_local(client, {:state =>" NC" , :city => " Cary" })
159161```
162+
160163Get CNAM info for a number
161164
162165``` ruby
163- info = Bandwidth ::NumberInfo .get(" +19195551212" )
166+ info = OldBandwidth ::NumberInfo .get(" +19195551212" )
164167 # or
165- client = Bandwidth ::Client .new (:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
166- info = Bandwidth ::NumberInfo .get(client, " +19195551212" )
168+ client = OldBandwidth ::Client .new (:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
169+ info = OldBandwidth ::NumberInfo .get(client, " +19195551212" )
167170```
168171
169172Buy a phone number
170173
171174``` ruby
172- number = Bandwidth ::PhoneNumber .create({:number => " +19195551212" })
175+ number = OldBandwidth ::PhoneNumber .create({:number => " +19195551212" })
173176 # or
174- client = Bandwidth ::Client .new (:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
175- number = Bandwidth ::PhoneNumber .create(client, {:number => " +19195551212" })
177+ client = OldBandwidth ::Client .new (:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
178+ number = OldBandwidth ::PhoneNumber .create(client, {:number => " +19195551212" })
176179```
177180
178181List recordings
179182
180183``` ruby
181- list = Bandwidth ::Recording .list()
184+ list = OldBandwidth ::Recording .list()
182185 # or
183- client = Bandwidth ::Client .new (:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
184- list = Bandwidth ::Recording .list(client)
186+ client = OldBandwidth ::Client .new (:user_id => " userId" , :api_token => " token" , :api_secret => " secret" )
187+ list = OldBandwidth ::Recording .list(client)
185188```
186189
187- Generate Bandwidth XML
190+ Generate OldBandwidth XML
188191
189192``` ruby
190- response = Bandwidth ::Xml ::Response .new ()
191- speak_sentence = Bandwidth ::Xml ::Verbs ::SpeakSentence .new ({:sentence => " Transferring your call, please wait." , :voice => " paul" , :gender => " male" , :locale => " en_US" })
192- transfer = Bandwidth ::Xml ::Verbs ::Transfer .new ({
193+ response = OldBandwidth ::Xml ::Response .new ()
194+ speak_sentence = OldBandwidth ::Xml ::Verbs ::SpeakSentence .new ({:sentence => " Transferring your call, please wait." , :voice => " paul" , :gender => " male" , :locale => " en_US" })
195+ transfer = OldBandwidth ::Xml ::Verbs ::Transfer .new ({
193196 :transfer_to => " +13032288849" ,
194197 :transfer_caller_id => " private" ,
195198 :speak_sentence => {
@@ -200,27 +203,27 @@ Generate Bandwidth XML
200203 }
201204 })
202205
203- hangup = Bandwidth ::Xml ::Verbs ::Hangup .new ()
204- response << speak_sentence << transfer << hangup
206+ hangup = OldBandwidth ::Xml ::Verbs ::Hangup .new ()
207+ response << speak_sentence << transfer << hangup
205208
206209 # as alternative way we can pass list of verbs to constructor of Response
207- # response = Bandwidth ::Xml::Response.new([speak_sentence, transfer, hangup])
210+ # response = OldBandwidth ::Xml::Response.new([speak_sentence, transfer, hangup])
208211
209212 puts response.to_xml()
210213```
211214
212-
213215See directory ` samples ` for more examples.
214216See [ ruby-bandwidth-example] ( https://github.com/bandwidthcom/ruby-bandwidth-example ) for more complex examples of using this module.
215217
216218### Messaging 2.0
219+
217220Send SMS (v2)
218221
219222``` ruby
220223 auth_data = {user_name: ' user' , password: ' password' , account_id: ' accountId' , subaccount_id: ' subaccountId' }
221224
222- # Before sending sms you should have nessagin application on Bandwidth dashboard. You should create it by next call
223- application = Bandwidth ::V2 ::Message .create_messaging_application(auth_data, {
225+ # Before sending sms you should have nessagin application on OldBandwidth dashboard. You should create it by next call
226+ application = OldBandwidth ::V2 ::Message .create_messaging_application(auth_data, {
224227 :name => ' My messaging application' ,
225228 :callback_url => ' http://server/to/handle/messages/events' ,
226229 :location_name => ' current' ,
@@ -229,7 +232,7 @@ Send SMS (v2)
229232 :mms_options => {:enabled => true }
230233 })
231234
232- # After that you should reserve 1 or some phone nubmers on Bandwidth Dashboard
235+ # After that you should reserve 1 or some phone nubmers on OldBandwidth Dashboard
233236 numbers = Message .search_and_order_numbers(auth_data, application) do |query |
234237 query.AreaCodeSearchAndOrderType do |b |
235238 b.AreaCode (" 910" )
@@ -238,7 +241,7 @@ Send SMS (v2)
238241 end
239242
240243 # Now you can send messages from reserved numbers. Don't forget to pass :application_id
241- message = Bandwidth ::V2 ::Message .create({:from => numbers[0 ], :to => [" +191955512142" ], :text => " Test" , :application_id => application[:application_id ]})
244+ message = OldBandwidth ::V2 ::Message .create({:from => numbers[0 ], :to => [" +191955512142" ], :text => " Test" , :application_id => application[:application_id ]})
242245```
243246
244247# Documentation generation
@@ -248,4 +251,5 @@ Generates documentation:
248251 yard doc
249252
250253# Samples
254+
251255[ More sample applications] ( https://github.com/bandwidthcom/ruby-bandwidth-example )
0 commit comments