Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Verify.{Service, Verification, VerificationCheck} API support #169

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ Twilio Access Token Grants:
- [Voice](https://www.twilio.com/docs/iam/access-tokens)
- [Video](https://www.twilio.com/docs/video/tutorials/user-identity-access-tokens#about-access-tokens)

Twilio Verify API:
- [Services](https://www.twilio.com/docs/verify/api/service)
- [Verifications](https://www.twilio.com/docs/verify/api/verification)
- [Verification Check](https://www.twilio.com/docs/verify/api/verification-check)

### Example

```elixir
Expand Down
2 changes: 2 additions & 0 deletions lib/ex_twilio/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ defmodule ExTwilio.Config do

def studio_url, do: "https://studio.twilio.com/v1"

def verify_url, do: "https://verify.twilio.com/v2"

def video_url, do: "https://video.twilio.com/v1"

@doc """
Expand Down
42 changes: 42 additions & 0 deletions lib/ex_twilio/resources/verify/service.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
defmodule ExTwilio.Verify.Service do
@moduledoc """
Represents a Service resource in the Twilio Verify API.

- [Twilio docs](https://www.twilio.com/docs/verify/api/service)

## Examples

Create a new Verify Service

ExTwilio.Verify.Service.create(friendly_name: "My Verification Service")

"""
defstruct sid: nil,
account_sid: nil,
friendly_name: nil,
code_length: nil,
lookup_enabled: nil,
psd2_enabled: nil,
skip_sms_to_landlines: nil,
dtmf_input_required: nil,
tts_name: nil,
do_not_share_warning_enabled: nil,
custom_code_enabled: nil,
push: nil,
totp: nil,
default_template_sid: nil,
date_created: nil,
date_updated: nil,
url: nil,
links: nil

use ExTwilio.Resource,
import: [
:stream,
:all,
:find,
:create,
:update,
:destroy
]
end
22 changes: 22 additions & 0 deletions lib/ex_twilio/resources/verify/verification_check.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
defmodule ExTwilio.Verify.VerificationCheck do
@moduledoc """
Represents a VerificationCheck resource in the Twilio Verify API.

- [Twilio docs](https://www.twilio.com/docs/verify/api/verification-check)
"""
defstruct sid: nil,
service_sid: nil,
account_sid: nil,
to: nil,
channel: nil,
status: nil,
valid: nil,
amount: nil,
payee: nil,
date_created: nil,
date_updated: nil

use ExTwilio.Resource, import: [:create]
def parents, do: [%ExTwilio.Parent{module: ExTwilio.Verify.Service, key: :service}]
def resource_name, do: "VerificationCheck"
end
44 changes: 44 additions & 0 deletions lib/ex_twilio/resources/verify/verifications.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
defmodule ExTwilio.Verify.Verifications do
@moduledoc """
Represents a Verification resource in the Twilio Verify API.

- [Twilio docs](https://www.twilio.com/docs/verify/api/verification)

## Examples

Start a new verification using the specified service

ExTwilio.Verify.Verifications.create(%{to: "+15017122661", channel: "sms"}, service: "VAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")

Twilio will send the user a token to use in a VerificationCheck. `create/2` will return `{:ok, verification_check}`, but be
sure to check `verification_check.valid` for verification success.

ExTwilio.Verify.VerificationCheck.create(%{to: "+15017122661", code: "1234"}, service: "VAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
"""
defstruct sid: nil,
service_sid: nil,
account_sid: nil,
to: nil,
channel: nil,
status: nil,
valid: nil,
date_created: nil,
date_updated: nil,
lookup: nil,
amount: nil,
payee: nil,
send_code_attempts: nil,
url: nil

use ExTwilio.Resource,
import: [
:find,
:create,
:update
]

def parents,
do: [
%ExTwilio.Parent{module: ExTwilio.Verify.Service, key: :service}
]
end
4 changes: 4 additions & 0 deletions lib/ex_twilio/url_generator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ defmodule ExTwilio.UrlGenerator do
url = add_segments(Config.studio_url(), module, id, options)
{url, options}

["ExTwilio", "Verify" | _] ->
url = add_segments(Config.verify_url(), module, id, options)
{url, options}

["ExTwilio", "Video" | _] ->
url = add_segments(Config.video_url(), module, id, options)
{url, options}
Expand Down