Giter VIP home page Giter VIP logo

plivo-ruby's Introduction

plivo-ruby

UnitTest Gem Version

The Plivo Ruby SDK makes it simpler to integrate communications into your Ruby applications using the Plivo REST API. Using the SDK, you will be able to make voice calls, send SMS and generate Plivo XML to control your call flows.

Installation

Add this line to your application's Gemfile:

gem 'plivo', '>= 4.60.0'

And then execute:

$ bundle

Or install it yourself as:

$ gem install plivo

For features in beta, use the beta branch:

$ gem install plivo --pre

If you have the 0.3.19 version (a.k.a legacy) already installed, you may have to first uninstall it before installing the new version.

Getting started

Authentication

To make the API requests, you need to create a RestClient and provide it with authentication credentials (which can be found at https://console.plivo.com/dashboard/).

We recommend that you store your credentials in the PLIVO_AUTH_ID and the PLIVO_AUTH_TOKEN environment variables, so as to avoid the possibility of accidentally committing them to source control. If you do this, you can initialise the client with no arguments and it will automatically fetch them from the environment variables:

client = RestClient.new;

Alternatively, you can specifiy the authentication credentials while initializing the RestClient.

client = RestClient.new('<auth_id>', '<auth_token>');

The basics

The SDK uses consistent interfaces to create, retrieve, update, delete and list resources. The pattern followed is as follows:

client.resources.create(params); # Create
client.resources.get(resource_identifier); # Get
client.resources.update(resource_identifier, params); # Update
client.resources.delete(resource_identifier); # Delete
client.resources.list; # List all resources, max 20 at a time

You can also use the resource directly to update and delete it. For example,

resource = client.resources.get(resource_identifier);
resource.update(params); # update the resource
resource.delete(); # Delete the resource

Also, using client.resources.list would list the first 20 resources by default (which is the first page, with limit as 20, and offset as 0). To get more, you will have to use limit and offset to get the second page of resources.

To list all resources, you can simply use the following pattern that will handle the pagination for you automatically, so you won't have to worry about passing the right limit and offset values.

client.resources.each do |resource|
  puts resource.id
end

Examples

Send a message

require "plivo"
include Plivo

client = RestClient.new
response = client.messages.create(
  src: '+14156667778',
  dst: '+14156667777',
  text: 'Hello, this is a sample text'
  )

Make a call

require 'rubygems'
require 'plivo'

include Plivo

client = RestClient.new
call_made = client.calls.create(
  '+14156667778',
  ['+14156667777'],
  'https://answer.url'
)

Lookup a number

require 'rubygems'
require 'plivo'

include Plivo

client = RestClient.new
resp = client.lookup.get('<number-here>')

Generate Plivo XML

require 'rubygems'
require 'plivo'

include Plivo::XML

response = Response.new
response.addSpeak('Hello, world!')
puts response.to_xml # Prints the XML string

xml_response = PlivoXML.new(response)
puts xml_response.to_xml # Prints XML along with XML version & encoding details

This generates the following XML:

<?xml version="1.0" encoding="utf-8" ?>
<Response>
  <Speak>Hello, world!</Speak>
</Response>

Run a PHLO

require 'rubygems'
require 'plivo'

include Plivo

client = Phlo.new('<auth_id>', '<auth_token>')

# if credentials are stored in the PLIVO_AUTH_ID and the PLIVO_AUTH_TOKEN environment variables
# then initialize client as:
# client = Phlo.new

# run a phlo:
begin
    #parameters set in PHLO - params
    params = {
       from: '+14156667778',
       to: '+14156667777'
    }
    response = phlo.run(params)
    puts response
  rescue PlivoRESTError => e
    puts 'Exception: ' + e.message
  end

WhatsApp Messaging

Plivo's WhatsApp API allows you to send different types of messages over WhatsApp, including templated messages, free form messages and interactive messages. Below are some examples on how to use the Plivo Go SDK to send these types of messages.

Templated Messages

Templated messages are a crucial to your WhatsApp messaging experience, as businesses can only initiate WhatsApp conversation with their customers using templated messages.

WhatsApp templates support 4 components: header , body, footer and button. At the point of sending messages, the template object you see in the code acts as a way to pass the dynamic values within these components. header can accomodate text or media (images, video, documents) content. body can accomodate text content. button can support dynamic values in a url button or to specify a developer-defined payload which will be returned when the WhatsApp user clicks on the quick_reply button. footer cannot have any dynamic variables.

Example 1:

require "plivo"
include Plivo

api = RestClient.new("<auth_id>","<auth_token>")

template={ 
            "name": "template_name",
            "language": "en_US",
            "components": [
                {
                    "type": "header",
                    "parameters": [
                        {
                            "type": "media",
                            "media": "https://xyz.com/s3/img.jpg"
                        }
                    ]
                },
                {
                    "type": "body",
                    "parameters": [
                        {
                            "type": "text",
                            "text": "WA-Text"
                        }
                    ]
                }
            ]
          }

response = api.messages.create(
        src: "+14156667778",
        dst:"+14156667777",
        type:"whatsapp",
        template:template,
        url: "https://<yourdomain>.com/whatsapp_status/",
)
puts response

Example 2:

require "plivo"
require "plivo/template"
include Plivo

api = RestClient.new("<auth_id>","<auth_token>")

header_media_param = Parameter.new(type: "media", media: "https://xyz.com/s3/img.jpg")
body_text_params = [ Parameter.new(type: "text", text: "WA-Text") ]

header_component = Component.new(type: "header", parameters: [header_media_param])
body_component = Component.new(type: "body", parameters: body_text_params)

template = Template.new(name: "template_name", language: "en_US", components: [header_component, body_component])

response = api.messages.create(
    src: "+14156667778",
    dst:"+14156667777",
    type:"whatsapp",
    template:template,
    url: "https://<yourdomain>.com/whatsapp_status/",
)
puts response

Note: It is also possible to create and manage objects directly within the SDK for whatsapp, providing a structured approach to message creation.

Free Form Messages

Non-templated or Free Form WhatsApp messages can be sent as a reply to a user-initiated conversation (Service conversation) or if there is an existing ongoing conversation created previously by sending a templated WhatsApp message.

Free Form Text Message

Example:

require "plivo"
include Plivo

api = RestClient.new("<auth_id>","<auth_token>")
response = api.messages.create(
        src: "+14156667778",
        dst:"+14156667777",
        type:"whatsapp",
        text:"Hello, this is sample text",
        url: "https://<yourdomain>.com/whatsapp_status/",
)
puts response

Free Form Media Message

Example:

require "plivo"
include Plivo

api = RestClient.new("<auth_id>","<auth_token>")
response = api.messages.create(
        src: "+14156667778",
        dst:"+14156667777",
        type:"whatsapp",
        text:"Hello, this is sample text",
        media_urls:["https://sample-videos.com/img/Sample-png-image-1mb.png"],
        url: "https://<yourdomain>.com/wa_status/",
)
puts response

Interactive Messages

This guide shows how to send non-templated interactive messages to recipients using Plivo’s APIs.

Quick Reply Buttons

Quick reply buttons allow customers to quickly respond to your message with predefined options.

Example:

require "rubygems"
require "/usr/src/app/lib/plivo.rb"
include Plivo

api = RestClient.new("<auth_id>","<auth_token>")

interactive= {
        "type": "button",
        "header": {
            "type": "media",
            "media": "https://xyz.com/s3/img.jpg"
        },
        "body": {
            "text": "Make your selection"
        },
        "action": {
            "buttons": [
                {
                    "title": "Click here",
                    "id": "bt1"
                },
                {
                    "title": "Know More",
                    "id": "bt2"
                },
                {
                    "title": "Request Callback",
                    "id": "bt3"
                }
            ]
        }
    }

response = api.messages.create(
        src: "+14156667778",
        dst:"+14156667777",
        type:"whatsapp",
        interactive:interactive
)
puts response

Interactive Lists

Interactive lists allow you to present customers with a list of options.

Example:

require "rubygems"
require "/usr/src/app/lib/plivo.rb"
include Plivo

api = RestClient.new("<auth_id>","<auth_token>")

interactive= {
        "type": "list",
        "header": {
            "type": "text",
            "text": "Welcome to Plivo"
        },
        "body": {
            "text": "You can review the list of rewards we offer"
        },
        "footer": {
            "text": "Yours Truly"
        },
        "action": {
            "buttons": [{
                "title": "Click here"
            }],
            "sections": [
                {
                    "title": "SECTION_1_TITLE",
                    "rows": [
                        {
                            "id": "SECTION_1_ROW_1_ID",
                            "title": "SECTION_1_ROW_1_TITLE",
                            "description": "SECTION_1_ROW_1_DESCRIPTION"
                        },
                        {
                            "id": "SECTION_1_ROW_2_ID",
                            "title": "SECTION_1_ROW_2_TITLE",
                            "description": "SECTION_1_ROW_2_DESCRIPTION"
                        }
                    ]
                },
                {
                    "title": "SECTION_2_TITLE",
                    "rows": [
                        {
                            "id": "SECTION_2_ROW_1_ID",
                            "title": "SECTION_2_ROW_1_TITLE",
                            "description": "SECTION_2_ROW_1_DESCRIPTION"
                        },
                        {
                            "id": "SECTION_2_ROW_2_ID",
                            "title": "SECTION_2_ROW_2_TITLE",
                            "description": "SECTION_2_ROW_2_DESCRIPTION"
                        }
                    ]
                }
            ]
        }
    }

response = api.messages.create(
        src: "+14156667778",
        dst:"+14156667777",
        type:"whatsapp",
        interactive:interactive
)
puts response

Interactive CTA URLs

CTA URL messages allow you to send links and call-to-action buttons.

Example:

require "rubygems"
require "/usr/src/app/lib/plivo.rb"
include Plivo

api = RestClient.new("<auth_id>","<auth_token>")

interactive= {
        "type": "cta_url",
        "header": {
            "type": "media",
            "media": "https://xyz.com/s3/img.jpg"
        },
        "body": {
            "text": "Know More"
        },
        "footer": {
            "text": "Plivo"
        },
        "action": {
            "buttons": [
                {
                    "title": "Click here",
                    "cta_url": "https:plivo.com"
                }
            ]
        }
    }

response = api.messages.create(
        src: "+14156667778",
        dst:"+14156667777",
        type:"whatsapp",
        interactive:interactive
)
puts response

Location Messages

This guide shows how to send templated and non-templated location messages to recipients using Plivo’s APIs.

Templated Location Messages

Example:

require "rubygems"
require "/usr/src/app/lib/plivo.rb"
require "/usr/src/app/lib/plivo/template.rb"
include Plivo

api = RestClient.new("<auth_id>","<auth_token>")

template= {
        "name": "plivo_order_pickup",
        "language": "en_US",
        "components": [
            {
                "type": "header",
                "parameters": [
                    {
                        "type": "location",
                        "location": {
                            "longitude": "122.148981",
                            "latitude": "37.483307",
                            "name": "Pablo Morales",
                            "address": "1 Hacker Way, Menlo Park, CA 94025"
                        }
                    }
                ]
            }
        ]
    }

response = api.messages.create(
        src: "+14156667778",
        dst:"+14156667777",
        type:"whatsapp",
        template:template
)
puts response

Non-Templated Location Messages

Example:

require "rubygems"
require "/usr/src/app/lib/plivo.rb"
require "/usr/src/app/lib/plivo/location.rb"
include Plivo

api = RestClient.new("<auth_id>","<auth_token>")

location= {
        "longitude": "122.148981",
        "latitude": "37.483307",
        "name": "Pablo Morales",
        "address": "1 Hacker Way, Menlo Park, CA 94025"
    }

response = api.messages.create(
        src: "+14156667778",
        dst:"+14156667777",
        type:"whatsapp",
        location:location
)
puts response

More examples

More examples are available here. Also refer to the guides for configuring the Rails server to run various scenarios & use it to test out your integration in under 5 minutes.

Reporting issues

Report any feedback or problems with this version by opening an issue on Github.

Local Development

Note: Requires latest versions of Docker & Docker-Compose. If you're on MacOS, ensure Docker Desktop is running.

  1. Export the following environment variables in your host machine:
export PLIVO_AUTH_ID=<your_auth_id>
export PLIVO_AUTH_TOKEN=<your_auth_token>
export PLIVO_API_DEV_HOST=<plivoapi_dev_endpoint>
export PLIVO_API_PROD_HOST=<plivoapi_public_endpoint>
  1. Run make build. This will create a docker container in which the sdk will be setup and dependencies will be installed.

The entrypoint of the docker container will be the setup_sdk.sh script. The script will handle all the necessary changes required for local development.

  1. The above command will print the docker container id (and instructions to connect to it) to stdout.
  2. The testing code can be added to <sdk_dir_path>/ruby-sdk-test/test.rb in host
    (or /usr/src/app/ruby-sdk-test/test.rb in container)
  3. The sdk directory will be mounted as a volume in the container. So any changes in the sdk code will also be reflected inside the container.

To use the local code in the test file, import the sdk in test file using:
require "/usr/src/app/lib/plivo.rb"

  1. To run test code, run make run CONTAINER=<cont_id> in host.
  2. To run unit tests, run make test CONTAINER=<cont_id> in host.

<cont_id> is the docker container id created in 2. (The docker container should be running)

Test code and unit tests can also be run within the container using make run and make test respectively. (CONTAINER argument should be omitted when running from the container)

plivo-ruby's People

Contributors

abhishekgupta-plivo avatar abrolnalin avatar ajay-plivo avatar anindya-plivo avatar ashutoshkumar-plivo avatar bhuvanvenkat-plivo avatar eniyavan-muruganantham-plivo avatar huzaif-plivo avatar kapilp93 avatar koushik-ayila avatar kowshik-plivo avatar kowshiksiva5 avatar kritarth-plivo avatar kunal-plivo avatar lsaitharun avatar manas-plivo avatar mohsin-plivo avatar narayana-plivo avatar nirmitijain avatar nixonsam avatar plivo-sdks avatar prashantp-plivo avatar rajneeshkatkam-plivo avatar ramey-plivo avatar renoldthomas-plivo avatar saksham-plivo avatar saurabhnewatiya-plivo avatar shubham-plivo avatar sreyantha-plivo avatar varshit97plivo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

plivo-ruby's Issues

NameError: uninitialized constant Plivo::Utils::Base64 while validating v2 signature

Seems like Base64 has some namespacing issues and instead of takingBase64 from require 'base64', it is being searched in Plivo::Utils. Including the require statement while running the validation is working fine.

Need to check the tests too - all of them are passing, so there is something more to this.

Ruby version: 2.4.0p0
SDK version: 4.0.0.beta.2

More robust handling of unexpected responses

On occasion, when the Plivo backend returns a response that doesn't quite conform to the expected successful response, it will raise errors in our code originating from the Plivo gem. One specific example of this happened on February 10 in which we got a bunch of these errors:

JSON::ParserError: A JSON text must at least contain two octets! originating from line 63 of plivo.rb.

An improvement would be to wrap it in some kind of Plivo-namespaced error so that our code can specifically look for this class of errors. For now we have to catch that specific type of error in our code, which feels hacky.

Depends on rest-client 2.0

Is there any chance you could either:

  1. Drop the dependency on rest-client 1.x.
  2. Update rest-client to 2.0.
  3. Use the standard library http client
  4. Use a recent stable version of faraday.

The use of the gem dependency on rest-client 1.x means, e.g., you cannot use this gem in the same process that you use any version of mailgun since 2015 began—2.5 years of not updating rest-client is way too long.

Better Error Handling for Empty Responses

We got the following error in production today because the Plivo API returned an empty string as a response for some reason (first time we've ever seen this):

JSON::ParserError: A JSON text must at least contain two octets!
/app/vendor/bundle/ruby/2.2.0/gems/json-1.8.3/lib/json/common.rb:155:in `initialize'
-------------------------------
Backtrace:

/app/vendor/bundle/ruby/2.2.0/gems/json-1.8.3/lib/json/common.rb:155:in `initialize'
/app/vendor/bundle/ruby/2.2.0/gems/json-1.8.3/lib/json/common.rb:155:in `new'
/app/vendor/bundle/ruby/2.2.0/gems/json-1.8.3/lib/json/common.rb:155:in `parse'
/app/vendor/bundle/ruby/2.2.0/gems/plivo-0.3.16/lib/plivo.rb:82:in `request'
/app/vendor/bundle/ruby/2.2.0/gems/plivo-0.3.16/lib/plivo.rb:515:in `get_message'
JSON.parse('') # => JSON::ParserError

This should instead raise a Plivo specific error (e.g. Plivo::NoResponseError).

Some API functions can not set all possible parameters

Some of the newly added parameters can not be set on API functions.

An example would be the mute_member function, callback_url can not be set on this function

  def mute_member(params={})
      conference_name = params.delete('conference_name')
      member_id = params.delete('member_id')
      return request('POST', "/Conference/#{conference_name}/Member/#{member_id}/Mute/")
  end

This issue is also present on the deaf and kick functions.

git://gist.github.com/3317025.git

Sending SMS messages result in the error "invalid json data sent in raw POST"

I recently started getting this error:

"invalid json data sent in raw POST"

The problem is that SOME of my messages SOMETIME get this error. Then when I try sending again, it works.

And if I Google it I only get Plivo results, so I guess it's related to the library?

Here is the error in the PHP library: plivo/plivo-php#20

https://www.google.com/search?q=%22invalid+json+data+sent+in+raw+POST%22&oq=%22invalid+json+data+sent+in+raw+POST%22&aqs=chrome.0.69i59l2j0i546l3j69i61j69i60.5442j0j7&sourceid=chrome&ie=UTF-8

Can you help me debug this issue?

Action element improperly replaces special characters

If I supply a valid url including query string key value pairs which are properly separated by ampersands, those ampersands should not be replaced with HTML entities when the response is exported as xml.

include Plivo::XML
r = Response.new
gd = r.GetDigits(action: "http://example.com/path?var1=a&var2=b&var3=c")
r.to_xml

# output: 
"<Response><GetDigits action='https://example.com/path?var1=a&amp;var2=b&amp;var3=c'/></Response>"

# expected (desired) output:
"<Response><GetDigits action='https://example.com/path?var1=a&var2=b&var3=c'/></Response>"

Please note that your current output seems inconsistent to me in that the question mark is not substituted but the ampersands are.

I would like to see the xml output simply select the string itself without substitution. If special characters exist in the url either before or after the query string, it should be on the developer utilizing the SDK to properly encode the strings.

If you are going to continue making the substitutions, perhaps consider altering the action element to allow a hash as an argument that would then get added to the url as the query string.

Double country code in SMS ID

Hi,

When sending an SMS using the following code, the src number that the device has the country code repeated, meaning the SMS cannot be replied to. I have recreated this on Android, non-feature phone and iOS, so it must be a country code getting added twice in the header.

Here is the ruby code:

[code]def mobile_check_prime
# Send confirmation to mobile to check the number
# and prime it for use. Starts false, send confirm
# request, then flag true for ready to use.

self.mobile.to_s.sub! /\A0+/, ''
self.mobile = "44#{self.mobile}" # This works, I am receiving the SMS
p = Plivo::RestAPI.new(AUTH_ID, AUTH_TOKEN)

# Send the SMS
params = {'src'   => '441617680044',
          'dst'   => self.mobile.to_s,
          'text'  => 'Plivo confirm message',
          'type'  => 'sms' }

p.send_message(params)

end[/code]

The message recieved shows a sender ID of: +44441617680044
I would expect to see +441617680044

I am unsure where the fault lies, if it is this Ruby module or not, so have also lodged a support request. They cannot fix it though and it seems to be going round the houses with a different person picking up the support request every time. I hope to god you haven't farmed this out to other side of the world tech support :(

License missing from gemspec

Some companies will only use gems with a certain license.
The canonical and easy way to check is via the gemspec
via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

There is even a License Finder to help companies ensure all gems they use
meet their licensing needs. This tool depends on license information being available in the gemspec.
Including a license in your gemspec is a good practice, in any case.

How did I find you?

I'm using a script to collect stats on gems, originally looking for download data, but decided to collect licenses too,
and make issues for missing ones as a public service :)
https://gist.github.com/bf4/5952053#file-license_issue-rb-L13 So far it's going pretty well

Memory bloat

Hi there! I've been tuning my apps memory usage on boot using the handy derailed gem. Running bundle exec derailed bundle:mem gives me a list of how much memory it takes to require gems individually. Plivo is coming in really high at 9mb (rails itself is only 12mb). Any idea how I can cut this down? I only use Plivo for SMS notifications, so I don't need most of the library for calling, routing, etc.

Screenshot of the output from derailed:

image

implementation issues

I am trying to implement send SMS api

api = RestAPI.new("","")
api.send_message(params)
NoMethodError - undefined method `http_code' for #<KeyError: key not found: :ciphers>:

2nd version :
api = RestClient.new("","")
method 'new' is not defined for RestClient

Syntax error on line 167

/opt/local/lib/ruby/gems/1.8/gems/plivo-0.2.10/lib/plivo.rb:167: Can't change the value of self
def get_number_group(self, params={})

Move XML builder classes under a different namespace

Some of the class names have name collisions with the rest API resource classes. So, instead of being able to create a resource class called Plivo::Number, I've needed to create classes called Plivo::RentedNumber.

Is there support for moving all of the Plivo::Element sub-classes under something like Plivo::Builder or Plivo::XML? So, the full class names would be Plivo::XML::Element?

Obviously, this would be a breaking change, so a major version bump would be in order if we're following semantic versioning.

Deprecation warnings reminder

.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/plivo-4.1.0/lib/plivo/utils.rb:70: warning: constant ::Fixnum is deprecated

.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/plivo-4.1.0/lib/plivo/utils.rb:70: warning: constant ::Bignum is deprecated

Faraday dependency is outdated. v1.x locked

Re-opening #179

@narayana-plivo

Hi,

I am not sure what there is to check:

https://github.com/plivo/plivo-ruby/blob/5212898a17211b9631f41c7c2ecbb998618b024e/plivo.gemspec

  spec.add_dependency 'faraday', '~> 1.0'

Version is still lock to v1.0 thus blocking us from using v2.x.

Here is bundle outdated from my project

Gem                          Current  Latest   Requested  Groups
faraday                      1.10.3   2.7.4
faraday-excon                1.1.0    2.1.0
faraday-httpclient           1.0.1    2.0.1
faraday-net_http             1.0.1    3.0.2
faraday-net_http_persistent  1.2.0    2.1.0
faraday-patron               1.0.0    2.0.1
faraday-rack                 1.0.0    2.0.0
faraday-retry                1.0.3    2.0.0
rack                         2.2.6.2  3.0.4.1

Can you reopen the issue ?

Impossible to validate XPlivoSignature in a Rails controller

This seems pretty straightforward so I am not sure what is causing the problem. I am trying to authorize messages coming from Plivo in a Rails controller but the following is not working:

signature    = request.headers["HTTP_X_PLIVO_SIGNATURE"]
auth_token = PLIVO_CONFIG[:auth_token] # let's assume this is set up correctly; works for outbound messages
uri = request.original_url
post_params = request.request_parameters

XPlivoSignature.new(signature, uri, post_params, auth_token).is_valid? # => false

Is there some gotcha to making this work as expected?

Request: Add callback URL to the Send Message Example

It would be really helpful if the Send Message Example in README.md would include info on how to supply the Callback URL.

The original documentation also does not show example how to do it. Here is their example:

response = api.messages.create(
    '14153336666',
    ['14156667777', 123_123_123_123],
    'Test Message'
  )

How would one supply the Callback url? Would it be something like this?

response = api.messages.create(
    '14153336666',
    ['14156667777', 123_123_123_123],
    'Test Message',
    { 'url' => 'http://example.com/api/confirmsms/' }

  )

Security update for POODLE vulnerability

Hello, yesterday I got next email from Plivo support-
"Hi,
We wanted to let you know that we will be disabling support for SSL 3.0 on December 30th in light of the latest security vulnerability discovered by Google. This vulnerability, nicknamed POODLE (Padding Oracle On Downgraded Legacy Encryption), allows attackers to decrypt encrypted website connections and steal sensitive information.
Fortunately, TLS (transport layer security) has been the industry standard for the last 15 years and SSL 3.0 is hardly used. Though to ease this transition, we will give our customers time to make changes to their app so that all of your HTTPS requests use TLS. You most likely will not be affected, but please double check that:
HTTPS Client code supports making API requests with TLS - as Plivo servers will reject SSLv3 connection attempts.
Customer web servers serving Plivo Application URLs (e.g. answer_url) over HTTPS will have to support TLS - requests from Plivo will not be made over SSLv3.
WebRTC clients will have to support TLS - this is usually the case when the WebRTC client is a recent browser and using Plivo’s WebSDK.
Please make these updates asap as we will disable support for SSL 3.0. on Tuesday December 30th, 2014, at 9am PST. "

So, now I see that can't set specific ssl_version for Plivo::RestAPI.new()
what your mind about it?

I spent a quick analysis -
I saw that now my "rest-client" gem have old version and using SSLv3 as default(and in this version I can't change :ssl_version even).
but and in a new version using SSLv23 (treeder/rest_client@ae72fa7).
even if I'll switch to this version, we can't set :ssl_version as TSL, because call rest-request is hardcoded in "plivo-gem".

Could you please release patch for this?

User collision

I'm having to use ApplicationRecord::User to avoid a collision with my model. This seems wrong to me. Am I doing something wrong?

Implicit Rake dependency?

The gem failed to install until I put its Rake dependency into my own Gemfile, see Bundler error message below:

Installing plivo 0.3.19 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /usr/local/bundle/gems/plivo-0.3.19/ext
/usr/local/bin/ruby mkrf_conf.rb

current directory: /usr/local/bundle/gems/plivo-0.3.19/ext
rake RUBYARCHDIR=/usr/local/bundle/extensions/x86_64-linux/2.3.0-static/plivo-0.3.19 RUBYLIBDIR=/usr/local/bundle/extensions/x86_64-linux/2.3.0-static/plivo-0.3.19
/usr/local/lib/ruby/2.3.0/rubygems/dependency.rb:319:in `to_specs': Could not find 'rake' (>= 0.a) among 24 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/usr/local/bundle', execute `gem env` for more information
    from /usr/local/lib/ruby/2.3.0/rubygems/dependency.rb:328:in `to_spec'
    from /usr/local/lib/ruby/2.3.0/rubygems/core_ext/kernel_gem.rb:65:in `gem'
    from /usr/local/bin/rake:22:in `<main>'

rake failed, exit code 1

Gem files will remain installed in /usr/local/bundle/gems/plivo-0.3.19 for inspection.
Results logged to /usr/local/bundle/extensions/x86_64-linux/2.3.0-static/plivo-0.3.19/gem_make.out
An error occurred while installing plivo (0.3.19), and Bundler cannot continue.
Make sure that `gem install plivo -v '0.3.19'` succeeds before bundling.
The command '/bin/sh -c bundle install' returned a non-zero code: 5

Documentation error

I see in the ruby doc, in the Run PHLO section that the phlo variable is not defined.
You guys initialize a client variable but is never used. Also the phlo variable tries to execute the run method which raises an exception due that variable is not initialized.

silent failures when phone number format isn't exactly as expected

if the country code isn't specified or if the phone number contains dashes or periods, the call silently fails (this was with client.messages.create https://github.com/plivo/plivo-ruby/#send-a-message)

I have this simple code to format as expected, but it'd be great if the API provided this flexibility by default (especially given the fact that no errors are reported)

def format_number(number)
  # strip out any non-numeric characters
  num = number.gsub(/[^0-9]/, '')
  # prepend country code
  num.prepend(COUNTRY_CODE) if num.length < PHONE_DIGITS
  num
end

Thanks!

Builder dependency incompatible with Rails 4

The builder dependency in v0.3.12 was changed from >= 2.1.2 to ~> 2.1, >= 2.1.2 to remove the open-ended version. That's probably best practice, but now it conflicts with Rails 4.x since either actionpack (4.0) or actionview (4.1, 4.2) depends on builder ~> 3.1.

Most other gems seem to have left the open-ended dependency. Was there a specific issue that necessitated this change, or could we consider relaxing it back to >= 2.1.2?

Not able to rent a number

Request:

params = {
number: '1XXXXXXXXXX'
}

puts params.inspect
response = api.rent_number(params)

Response:

[nil, 404 Resource Not Found: {
"error": "not found"
}]

Plivo having trouble building on Travis CI

Output from Travis as follows:

Installing plivo 0.3.19 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
    can't modify frozen String
Gem files will remain installed in
/home/travis/build/our-app/vendor/bundle/ruby/2.3.0/gems/plivo-0.3.19
for inspection.
Results logged to
/home/travis/build/our-app/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/plivo-0.3.19/gem_make.out
An error occurred while installing plivo (0.3.19), and Bundler cannot
continue.
Make sure that `gem install plivo -v '0.3.19'` succeeds before bundling.
The command "eval bundle install --without production development --path=${BUNDLE_PATH:-vendor/bundle} " failed.

Fix issue with html entity conversion in API request

API parameter values containing symbols, like, ampersand are being converted to HTML decimal entities.

e.g.

"answer_url" => "http://myserver.com/action/?to=12345678901&Digits=123"

gets modified to,

"answer_url" => "http://myserver.com/action/?to=12345678901&#38;Digits=123"

Raise Error for Missing Parameter in REST API Wrapper

It would be awesome if an ArgumentError were raised when the proper parameter isn't provided to the REST API wrapper:

def get_number(params = {})
  number = extract_param('number', params)
  request('GET', "/Number/#{number}/", params)
end

def extract_param(param_key, params)
  if params.has_key?(param_key)
    params[param_key]
  else
    raise ArgumentError, "Required param #{param_key} not provided in params: #{params}"
  end
end

Could not validate the Signature caused by missed slash

I'm trying to validate the signature as explained at the documentation: Generating and Validating the Signature

After a lot of trials and failures. I've downloaded the gem to understand what I'm missing.

Imagine my surprise when I get that the gem is the one who is missing something. A slash to be more specific :)

At the documentation, you should validate the response with:

Base64.encode64(OpenSSL::HMAC.digest("SHA256", "AUTH_TOKEN", "YOUR_CALLBACK_URL/REQUEST_HEADER_X-Plivo-Signature-V2-Nonce"))

But, this never works. You never get a match the hash with the x-plivo-signature-v2, right? I've also tried to use the Auth Key, instead of Auth Token. And every combination of those fields.

To make it work you must change your code to this version:

Base64.encode64(OpenSSL::HMAC.digest("SHA256", "AUTH_TOKEN", "YOUR_CALLBACK_URLREQUEST_HEADER_X-Plivo-Signature-V2-Nonce"))

Have you noticed the difference? Yep! Drop the slash between your callback URL and X-Plivo-Signature-V2-Nonce.

I verified it at the current implementation of Plivo SDK(4.3.2).

Of course, since it's working if you use the gem, the server must be generating the hash with this missing slash.

Tags are out of sync with rubygems.org releases

It seems like the tags following 4.18.0 have not been pushed. I'd like to be able to compare code changes to this library so that I can more easily identify the changes that I'll have to make in my own application when updating the plivo gem.

Upgrade Faraday to v 1.0

Faraday is used in this gem and locked to 0.x - other gems use Faraday as well and start requiring 1.x

Doesn't seem like there are many breaking changes in this release, see https://github.com/lostisland/faraday/blob/master/CHANGELOG.md#v10
However, I don't know much about Faraday so not sure what is required to upgrade plivo - or if it maybe could work with 0.x and 1.x of faraday.

Going forward this will cause more and more conflicts with other gems, i.e. preventing Plivo users from upgrading those other gems. This will get even worse if an update is required for a new feature or security fixes in those gems.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.