Skip to content

Commit

Permalink
pushing up
Browse files Browse the repository at this point in the history
  • Loading branch information
hummusonrails committed Jan 18, 2021
0 parents commit 76c34dc
Show file tree
Hide file tree
Showing 18 changed files with 446 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VONAGE_API_KEY =
VONAGE_API_SECRET =
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.env
private.key
.byebug_history
76 changes: 76 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [email protected]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
18 changes: 18 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Contributing

Thanks for considering contributing! From typos, to sample code, tutorials and beyond, we truly appreciate and welcome input from everyone.

## Git process

This project uses [GitHub Flow](https://guides.github.com/introduction/flow/index.html). We are happy to have issues opened for discussion, but we don't require an issue to be created before a pull request is opened. When you have a change you want us to consider:

* Create a new branch on your own fork, from an up-to-date master branch.
* Make the changes on that new branch.
* Open a pull request for us, making sure to tell us what you changed and why in the pull request title and description. Pull requests without a meaningful title and a completed template may be closed.

If you need more information about how to do any of the above, we recommend the [GitHub Help pages](https://help.github.com/), which are indeed very helpful.

Tips:

* Keep it small! Small changes are easy to review and more likely to be accepted. More involved changes probably need discussion first.
* Tell us _what_ changed and _why_. This helps us to understand the change and get the right people to review it.
10 changes: 10 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
source 'https://rubygems.org'

gem 'vonage'
gem 'sinatra'
gem 'sinatra-contrib'
gem 'sinatra-activerecord'
gem 'pg'
gem 'rake'
gem 'json'
gem 'dotenv'
71 changes: 71 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
GEM
remote: https://rubygems.org/
specs:
activemodel (6.1.1)
activesupport (= 6.1.1)
activerecord (6.1.1)
activemodel (= 6.1.1)
activesupport (= 6.1.1)
activesupport (6.1.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
concurrent-ruby (1.1.7)
dotenv (2.7.6)
i18n (1.8.7)
concurrent-ruby (~> 1.0)
json (2.5.1)
jwt (2.2.2)
minitest (5.14.3)
multi_json (1.15.0)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
nexmo-jwt (0.1.2)
jwt (~> 2)
pg (1.2.3)
rack (2.2.3)
rack-protection (2.1.0)
rack
rake (13.0.3)
ruby2_keywords (0.0.2)
sinatra (2.1.0)
mustermann (~> 1.0)
rack (~> 2.2)
rack-protection (= 2.1.0)
tilt (~> 2.0)
sinatra-activerecord (2.0.21)
activerecord (>= 4.1)
sinatra (>= 1.0)
sinatra-contrib (2.1.0)
multi_json
mustermann (~> 1.0)
rack-protection (= 2.1.0)
sinatra (= 2.1.0)
tilt (~> 2.0)
sorbet-runtime (0.5.6212)
tilt (2.0.10)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
vonage (7.2.1)
nexmo-jwt (~> 0.1.2)
sorbet-runtime (~> 0.5)
zeitwerk (~> 2, >= 2.2)
zeitwerk (2.4.2)

PLATFORMS
ruby

DEPENDENCIES
dotenv
json
pg
rake
sinatra
sinatra-activerecord
sinatra-contrib
vonage

BUNDLED WITH
2.1.4
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2021 Vonage

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
89 changes: 89 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Vonage 5 Minute Demo: Verify Users with the Verify API in Ruby

[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg)](CODE_OF_CONDUCT.md)
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE.txt)

<img src="https://developer.nexmo.com/assets/images/Vonage_Nexmo.svg" height="48px" alt="Nexmo is now known as Vonage" />

This is a demo app showcasing how to get up and running with the Vonage Verify API in Ruby.

Users sign up on the website by providing their mobile phone number. The Verify API sends a pin code to the user's phone. The user enters the pin code on the website and confirms their identity. The application also provides a raffle drawing option, wherein a random confirmed user can be selected from the database and they will be notified via a phone call that they won the drawing.

* [Requirements](#requirements)
* [Installation](#installation)
* [Usage](#usage)
* [License](#license)

## Requirements

This app requires Ruby v2.7 or greater and the following gems:

* [Vonage](https://github.com/vonage/vonage-ruby-sdk)
* [Sinatra](https://github.com/sinatra/sinatra)
* [Sinatra-Contrib](https://github.com/sinatra/sinatra/tree/master/sinatra-contrib)
* [Sinatra-Activerecord](https://github.com/sinatra-activerecord/sinatra-activerecord)
* [pg](https://rubygems.org/gems/pg/versions/0.18.4)
* [rake](https://github.com/ruby/rake)
* [json](https://github.com/flori/json)
* [dotenv](https://github.com/bkeepers/dotenv)

These are all included in the project's `Gemfile` and will be installed when you run `bundle install` from the command line.

## Installation

Once you clone the repository, make sure its dependencies are installed on your local machine:

```bash
$ bundle install
```

Then you will want to create the PostgreSQL database by first running `bundle exec rake db:load_config` and then `bundle exec rake db:migrate`.

## Usage

The application to run requires your Vonage API key and secret. Add your Vonage API key and your Vonage API secret to your `.env` file. You can rename the `.env.sample` file provided in this repository to `.env` and fill in the values there.

To start your web server run the following from the command line:

```bash
$ bundle exec ruby app.rb
```

The above command will begin a web server running on port 3000.

The application is now ready to visit.

Users can begin to verify their identity by visiting `https://localhost:3000`. They will enter their phone number in the form and press the Submit button. The application will then render a new view with a form to enter the pin code the Vonage Verify API sent to their phone via SMS.

*The Verify API will wait 300 seconds for the user to enter the pin. If they do not enter the pin, the API tries again with another text message. If another 300 seconds elapse and the user does not enter the pin, the API will try again with a phone call to the user. You can find more information on the various Verify API workflows, and the default workflow behavior on the [Vonage API Developer Portal](https://developer.nexmo.com/verify/guides/workflows-and-events).*

Once the user enters the pin code and presses the Submit button, the application will send a verify request to the Verify API to confirm the pin was correct. If it was correct, the user is saved to the database if they were not previously verified. The final view of the website confirms the verification to the user and lets them know that they have either been entered into the database or not depending on if it was their first confirmed verification.

### Selecting a Winner

To select a random winner from confirmed users in the database, the application requires a Vonage provisioned virtual number that is linked to a Voice Voice application. Both of those items can be created from your [Vonage Dashboard](https://dashboard.nexmo.com). The phone number you create in the Dashboard will be the number that will send the pin code to the user.

You will need to provide an `event URL` for the application you create that corresponds to the event route provided in the `app.rb` file. The event URL needs to be an externally accessible URL that ends with `/webhooks/event`. For example, if your URL was `example.com`, then your answer URL would be `http://example.com/webhooks/event`.

![Voice API URL settings](voice_app_url_settings.png)

Next, open up the `app.rb` file in your preferred code editor and add both your Vonage application ID and your Vonage phone number to the constants defined in the file:

```ruby
VONAGE_APPLICATION_ID = ''
VONAGE_NUMBER = ''
```

Make sure to also add your Vonage API key and your Vonage API secret to your `.env` file. You can rename the `.env.sample` file provided in this repository to `.env` and fill in the values there.

Lastly, make sure to generate a public and private key in your Vonage API Dashboard for your application and save the private key to the root folder of this project. Do not forget to also press the `Save` button in the dashboard to ensure that the key has been stored successfully for your account.

Once that is completed you are ready to select a winner you can visit `http://localhost:3000/winner` and the application will choose one visitor at random and call them to notify them that they won the prize.

If you are running this for a one-time event or do not want to persist the data you can execute `bundle exec rake db:drop` at the conclusion of your use of the application. This will drop the database and delete all of the records.

## License

This library is released under the [MIT License][license]

[license]: LICENSE.txt
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'sinatra/activerecord/rake'

namespace :db do
task :load_config do
require './app'
end
end
Loading

0 comments on commit 76c34dc

Please sign in to comment.