Skip to content

Repository files navigation

Bandwidth Ruby SDK

Test

OSRuby
Windows 20162.6, 2.7, 3.0
Windows 20192.6, 2.7, 3.0
Ubuntu 18.042.6, 2.7, 3.0
Ubuntu 20.042.6, 2.7, 3.0

Getting Started

Installation

gem install bandwidth-sdk

Initialize

require'bandwidth'includeBandwidthincludeBandwidth::VoiceincludeBandwidth::MessagingincludeBandwidth::WebRtcincludeBandwidth::TwoFactorAuthbandwidth_client=Bandwidth::Client.new(voice_basic_auth_user_name: 'username',voice_basic_auth_password: 'password',messaging_basic_auth_user_name: 'username',messaging_basic_auth_password: 'username',two_factor_auth_basic_auth_user_name: 'username',two_factor_auth_basic_auth_password: 'password',web_rtc_basic_auth_user_name: 'username',web_rtc_basic_auth_password: 'password')account_id="12345"

Create Phone Call

voice_client=bandwidth_client.voice_client.clientbody=ApiCreateCallRequest.newbody.from='+16666666666'body.to='+17777777777'body.answer_url='https://test.com'body.application_id='3-d-4-b-5'beginresponse=voice_client.create_call(account_id,:body=>body)putsresponse.data.call_id#c-d45a41e5-bcb12581-b18e-4bdc-9874-6r3235dfweaoputsresponse.status_code#201rescueBandwidth::ErrorResponseException=>eputse.description#Invalid to: must be an E164 telephone numberputse.response_code#400end

Generate BXML

response=Bandwidth::Voice::Response.new()hangup=Bandwidth::Voice::Hangup.new()response.push(hangup)putsresponse.to_bxml()

Send Text Message

messaging_client=bandwidth_client.messaging_client.clientbody=MessageRequest.newbody.application_id='1-2-3'body.to=['+17777777777']body.from='+18888888888'body.text='Hello from Bandwidth'beginresponse=messaging_client.create_message(account_id,body)putsresponse.data.id#1570740275373xbn7mbhsfewasdrputsresponse.status_code#202rescueBandwidth::GenericClientException=>eputse.description#Access is deniedputse.response_code#403rescueBandwidth::PathClientException=>eputse.message#Your request could not be accepted.putse.response_code#400end

Create A MFA Request

auth_client=bandwidth_client.two_factor_auth_client.mfafrom_phone="+18888888888"to_phone="+17777777777"messaging_application_id="1-d-b"scope="scope"digits=6body=TwoFactorCodeRequestSchema.newbody.from=from_phonebody.to=to_phonebody.application_id=messaging_application_idbody.scope=scopebody.digits=digitsbody.message="Your temporary {NAME} {SCOPE} code is {CODE}"auth_client.create_messaging_two_factor(account_id,body)code="123456"#This is the user input to validatebody=TwoFactorVerifyRequestSchema.newbody.from=from_phonebody.to=to_phonebody.application_id=application_idbody.scope=scopebody.code=codebody.digits=digitsbody.expiration_time_in_minutes=3response=auth_client.create_verify_two_factor(account_id,body)puts"Auth status: " + response.data.valid.to_s

WebRtc Participant & Session Management

web_rtc_client=bandwidth_client.web_rtc_client.clientcreate_session_body=Session.newcreate_session_body.tag='new-session'create_session_response=web_rtc_client.create_session(account_id,:body=>create_session_body)session_id=create_session_response.data.idputssession_idcreate_participant_body=Participant.newcreate_participant_body.publish_permissions=[PublishPermissionEnum::AUDIO,PublishPermissionEnum::VIDEO]create_participant_body.callback_url="https://sample.com"create_participant_response=web_rtc_client.create_participant(account_id,:body=>create_participant_body)participant_id=create_participant_response.data.participant.idputsparticipant_idweb_rtc_client.add_participant_to_session(account_id,session_id,participant_id)

Supported Ruby Versions

This package can be used with Ruby >= 2.0

Documentation

Documentation for this package can be found at https://dev.bandwidth.com/sdks/ruby.html

Credentials

Information for credentials for this package can be found at https://dev.bandwidth.com/guides/accountCredentials.html

About

Ruby SDK for Bandwidth Voice & Messaging

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages