Project

sinch-ruby

0.0
No commit activity in last 3 years
No release in over 3 years
A library for communicating with the Sinch Rest API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.2
~> 0.49.0
~> 0.14.0
~> 4.0
~> 3.3

Runtime

~> 0.15.6
 Project Readme

Sinch Ruby REST API Wrapper

Build Status Gem Version

About

Sinch does a bunch of cool mobile features for native apps.

This gem provides API functionality to access the Sinch REST API with ruby

Currently the only implementation covers the Verification API

Installation

This gem is designed to work with rails. To install it, add the following to your Gemfile

gem 'sinch-ruby', '0.2.2', require: 'sinch'

To install it via gem install:

$ gem install sinch-ruby
$ irb
> require 'sinch'
> # do things with Sinch

In order to make Authenticated requests, you'll need to configure the application_key and secret_key from your Sinch account.

First, create an app in the Sinch portal, and then find your application_key.

Then, in an initializer, or wherever suits you:

Sinch.configure do |config|
  config.application_key = '[your-application-key]'
  config.secret_key = '[your-application-secret]'
end

Usage

To call the api, call .request on the Gateway class, providing the resource as your first argument, and any params for the second

Currently the only resources supported are :verification, :report_verification, and :send_sms

Verification Example

gateway = Sinch::Gateway
params = { phone_number: '+121255535555' }
gateway.request(:verification, params) 

ReportVerification Example

gateway = Sinch::Gateway
params = { phone_number: '+121255535555', code: '1337' }
gateway.request(:report_verification, params) 

SendSms Example

To send SMS to any given number through Sinch, you must be approved for a production app and have Full SMS Access enabled. If you are using a sandbox app, you can only send SMS messages to the Verified Phone Number associated with the account

gateway = Sinch::Gateway

# phone_number: The recipient's phone number
# from (optional): The sender's phone number (Note: this needs to be an authorized number in your Sinch account)
# message: SMS Body
params = { phone_number: '+121255555555', from: '+121255535555', message: 'I have a very specific set of skills.' }
gateway.request(:send_sms, params) 

Stubbing Requests

This gem comes with a Bogus Gateway that can be used when you would like to stub the requests sent to the gateway Below is a sample Rails initializer that will use the BogusGateway if the secrets are not set

# ./config/initializers/sinch.rb

secrets = Rails.application.secrets.sinch

Sinch.configure do |config|
  config.gateway = Sinch::BogusGateway
  if secrets.present?
    config.application_key = secrets[:application_key]
    config.secret_key = '[your-application-secret]'
    config.gateway = Sinch::Gateway
  end
end

Contributing

All contributions should be fully tested with the rspec framework.

Please fork this repository and submit a pull request to the develop branch on github

Testing

Tests are run with the rspec framework.

 # Clone the repository
 git clone git@github.com:davefreiman/sinch-rails.git
 
 # install dependencies
 bundle install
 
 # run tests
 bundle exec rspec

License

Sinch Ruby is released under the MIT License