|
| 1 | +MessageBird's REST API for Ruby |
| 2 | +=============================== |
| 3 | +This repository contains the open source Ruby client for MessageBird's REST API. Documentation can be found at: https://www.messagebird.com/developers/ruby. |
| 4 | + |
| 5 | +Requirements |
| 6 | +------------ |
| 7 | +- [Sign up](https://www.messagebird.com/en/signup) for a free MessageBird account |
| 8 | +- Create a new access_key in the developers sections |
| 9 | +- MessageBird's API client for Ruby requires Ruby >= 1.9 |
| 10 | + |
| 11 | +Installation |
| 12 | +------------ |
| 13 | +You can either include the following line in your Gemfile: |
| 14 | + |
| 15 | +```ruby |
| 16 | +gem 'messagebird-rest', :require => 'messagebird' |
| 17 | +``` |
| 18 | + |
| 19 | +Or you can just manually install it from the command line: |
| 20 | +```sh |
| 21 | +$ gem install messagebird-rest |
| 22 | +``` |
| 23 | + |
| 24 | +Examples |
| 25 | +-------- |
| 26 | +We have put some self-explanatory examples in the *examples* directory, but here is a quick breakdown on how it works. First, you need to create an instance of **MessageBird::Client**. Be sure to replace **YOUR_ACCESS_KEY** with something real in the bottom example. |
| 27 | + |
| 28 | +```ruby |
| 29 | +require 'pp' # Only needed for this example |
| 30 | +require 'messagebird' |
| 31 | + |
| 32 | +client = MessageBird::Client.new(YOUR_ACCESS_KEY) |
| 33 | +``` |
| 34 | + |
| 35 | +That's easy enough. Now we can query the server for information. |
| 36 | + |
| 37 | +##### Balance |
| 38 | +Lets start with out with an overview of our balance. |
| 39 | + |
| 40 | +```ruby |
| 41 | +pp client.balance |
| 42 | + |
| 43 | +#<MessageBird::Balance:0x007f8d5c83f478 |
| 44 | + @amount=9, |
| 45 | + @payment="prepaid", |
| 46 | + @type="credits"> |
| 47 | +``` |
| 48 | + |
| 49 | +##### Messages |
| 50 | +Chances are that the most common use you'll have for this API client is the ability to send out text messages. For that purpose we have created the **message_create** method, which takes the required *originator*, one or more *recipients* and a *body* text for parameters. |
| 51 | + |
| 52 | +Optional parameters can be specified as a hash. |
| 53 | + |
| 54 | +```ruby |
| 55 | +pp client.message_create('FromMe', '31612345678', 'Hello World', :reference => 'MyReference') |
| 56 | + |
| 57 | +#<MessageBird::Message:0x007f8d5b883520 |
| 58 | + @body="Hello World", |
| 59 | + @createdDatetime=2014-07-07 12:20:30 +0200, |
| 60 | + @datacoding="plain", |
| 61 | + @direction="mt", |
| 62 | + @gateway=239, |
| 63 | + @href= |
| 64 | + "https://rest.messagebird.com/messages/211e6280453ba746e8eeff7b12582146", |
| 65 | + @id="211e6280453ba746e8eeff7b12582146", |
| 66 | + @mclass=1, |
| 67 | + @originator="FromMe", |
| 68 | + @recipient= |
| 69 | + {"totalCount"=>1, |
| 70 | + "totalSentCount"=>1, |
| 71 | + "totalDeliveredCount"=>0, |
| 72 | + "totalDeliveryFailedCount"=>0, |
| 73 | + "items"=> |
| 74 | + [#<MessageBird::Recipient:0x007f8d5c058c00 |
| 75 | + @recipient=31612345678, |
| 76 | + @status="sent", |
| 77 | + @statusDatetime=2014-07-07 12:20:30 +0200>]}, |
| 78 | + @reference="MyReference", |
| 79 | + @scheduledDatetime=nil, |
| 80 | + @type="sms", |
| 81 | + @typeDetails={}, |
| 82 | + @validity=nil> |
| 83 | +``` |
| 84 | + |
| 85 | +As a possible follow-up, you can use the **message** method with the above mentioned batch-id to query the status of the message that you just created. It will return a similar Message object. |
| 86 | + |
| 87 | +```ruby |
| 88 | +client.message('211e6280453ba746e8eeff7b12582146') |
| 89 | +``` |
| 90 | + |
| 91 | +##### HLR |
| 92 | +To perform HLR lookups we have created the **hlr_create** method, which takes a number and a reference for parameters. |
| 93 | + |
| 94 | +```ruby |
| 95 | +pp client.hlr_create('31612345678', 'MyReference') |
| 96 | + |
| 97 | +#<MessageBird::HLR:0x007f8d5b8dafc8 |
| 98 | + @createdDatetime=2014-07-07 12:20:05 +0200, |
| 99 | + @href="https://rest.messagebird.com/hlr/4933bed0453ba7455031712h16830892", |
| 100 | + @id="4933bed0453ba7455031712h16830892", |
| 101 | + @msisdn=31612345678, |
| 102 | + @network=nil, |
| 103 | + @reference="MyReference", |
| 104 | + @status="sent", |
| 105 | + @statusDatetime=2014-07-07 12:20:05 +0200> |
| 106 | +``` |
| 107 | + |
| 108 | +Similar to the **message_create** and **message** methods, the **hlr_create** method has an accompanying **hlr** method to poll the HLR object. |
| 109 | + |
| 110 | +```ruby |
| 111 | +client.hlr('4933bed0453ba7455031712h16830892') |
| 112 | +``` |
| 113 | + |
| 114 | +##### Voice Message |
| 115 | +MessageBird also offers the ability to send out a text message as a voice message, or text-to-speech. For that purpose we have created the **voice_message_create** method, which takes one or more required *recipients* and a *body* text for parameters. |
| 116 | + |
| 117 | +Optional parameters can be specified as a hash. |
| 118 | + |
| 119 | +```ruby |
| 120 | +pp client.voice_message_create('31612345678', 'Hello World', :reference => 'MyReference') |
| 121 | + |
| 122 | +#<MessageBird::VoiceMessage:0x000001030101b8 |
| 123 | + @body="Hello World", |
| 124 | + @createdDatetime=2014-07-09 12:17:50 +0200, |
| 125 | + @href= |
| 126 | + "https://rest.messagebird.com/voicemessages/a08e51a0353bd16cea7f298a37405850", |
| 127 | + @id="a08e51a0353bd16cea7f298a37405850", |
| 128 | + @ifMachine="continue", |
| 129 | + @language="en-gb", |
| 130 | + @recipients= |
| 131 | + {"totalCount"=>1, |
| 132 | + "totalSentCount"=>1, |
| 133 | + "totalDeliveredCount"=>0, |
| 134 | + "totalDeliveryFailedCount"=>0, |
| 135 | + "items"=> |
| 136 | + [#<MessageBird::Recipient:0x000001011d3178 |
| 137 | + @recipient=31612345678, |
| 138 | + @status="calling", |
| 139 | + @statusDatetime=2014-07-09 12:17:50 +0200>]}, |
| 140 | + @reference="MyReference", |
| 141 | + @repeat=1, |
| 142 | + @scheduledDatetime=nil, |
| 143 | + @voice="female"> |
| 144 | +``` |
| 145 | + |
| 146 | +Similar to regular messaging and HLR lookups, there is a method available to fetch the VoiceMessage object by using an *id*. |
| 147 | + |
| 148 | +```ruby |
| 149 | +client.voice_message('a08e51a0353bd16cea7f298a37405850') |
| 150 | +``` |
| 151 | + |
| 152 | +Documentation |
| 153 | +------------- |
| 154 | +Complete documentation, instructions, and examples are available at: |
| 155 | +[https://www.messagebird.com/developers/ruby](https://www.messagebird.com/developers/ruby). |
| 156 | + |
| 157 | +License |
| 158 | +------- |
| 159 | +The MessageBird REST Client for Ruby is licensed under [The BSD 2-Clause License](http://opensource.org/licenses/BSD-2-Clause). Copyright (c) 2014, MessageBird |
0 commit comments