Sha256: eff885b960fc3aff99acd5f62793738d5095add6c5ba98d3dbff14cddb92186c

Contents?: true

Size: 1.97 KB

Versions: 22

Compression:

Stored size: 1.97 KB

Contents

# Bandwidth Ruby SDK
  
Bandwidth's API docs can be found at https://dev.bandwidth.com

Ruby specific docs can be found at https://dev.bandwidth.com/sdks/ruby.html

## Download & Install

```
gem install bandwidth-sdk
```

## Initialize Bandwidth Client

```ruby
require 'bandwidth'

include Bandwidth
include Bandwidth::Voice
include Bandwidth::Messaging

bandwidth_client = Bandwidth::Client.new(
    voice_basic_auth_user_name: 'username',
    voice_basic_auth_password: 'password',
    messaging_basic_auth_user_name: 'token',
    messaging_basic_auth_password: 'secret',
)
```

## Create Phone Call

```ruby
voice_client = bandwidth_client.voice_client.client

account_id = '1'
body = ApiCreateCallRequest.new
body.from = '+16666666666'
body.to = '+17777777777'
body.answer_url = 'https://test.com'
body.application_id = '3-d-4-b-5'

begin
    response = voice_client.create_call(account_id,:body => body)
    puts response.data.call_id #c-d45a41e5-bcb12581-b18e-4bdc-9874-6r3235dfweao
    puts response.status_code #201
rescue Bandwidth::ErrorResponseException => e
    puts e.description #Invalid to: must be an E164 telephone number
    puts e.response_code #400
end
```

## Generate BXML

```ruby
response = Bandwidth::Voice::Response.new()
hangup = Bandwidth::Voice::Hangup.new()

response.push(hangup)
puts response.to_bxml()
```

## Send Text Message

```ruby
messaging_client = bandwidth_client.messaging_client.client

account_id = '1'
body = MessageRequest.new
body.application_id = '1-2-3'
body.to = ['+17777777777']
body.from = '+18888888888'
body.text = 'Hello from Bandwidth'

begin
    response = messaging_client.create_message(account_id, :body => body)
    puts response.data.id #1570740275373xbn7mbhsfewasdr
    puts response.status_code #202
rescue Bandwidth::GenericClientException => e
    puts e.description #Access is denied
    puts e.response_code #403
rescue Bandwidth::PathClientException => e
    puts e.message #Your request could not be accepted.
    puts e.response_code #400
end
```

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
bandwidth-sdk-6.0.0 README.md
bandwidth-sdk-5.0.0 README.md
bandwidth-sdk-4.0.0 README.md
bandwidth-sdk-3.13.2 README.md
bandwidth-sdk-3.13.1 README.md
bandwidth-sdk-3.13.0 README.md
bandwidth-sdk-3.12.1 README.md
bandwidth-sdk-3.12.0 README.md
bandwidth-sdk-3.11.0 README.md
bandwidth-sdk-3.10.0 README.md
bandwidth-sdk-3.9.0 README.md
bandwidth-sdk-3.8.0 README.md
bandwidth-sdk-3.7.0 README.md
bandwidth-sdk-3.6.0 README.md
bandwidth-sdk-3.5.0 README.md
bandwidth-sdk-3.4.0 README.md
bandwidth-sdk-3.3.0 README.md
bandwidth-sdk-3.2.0 README.md
bandwidth-sdk-3.1.0 README.md
bandwidth-sdk-3.0.0 README.md