Skip to content

Commit

Permalink
feat: add oauth support for ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
manisha1997 committed Dec 9, 2024
1 parent 7894b81 commit ae94805
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 54 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/test-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ jobs:
TWILIO_API_SECRET: ${{ secrets.TWILIO_CLUSTER_TEST_API_KEY_SECRET }}
TWILIO_FROM_NUMBER: ${{ secrets.TWILIO_FROM_NUMBER }}
TWILIO_TO_NUMBER: ${{ secrets.TWILIO_TO_NUMBER }}
TWILIO_ORGS_CLIENT_SECRET: ${{ secrets.TWILIO_ORGS_CLIENT_SECRET }}
TWILIO_ORGS_CLIENT_ID: ${{ secrets.TWILIO_ORGS_CLIENT_ID }}
TWILIO_ORG_SID: ${{ secrets.TWILIO_ORG_SID }}
TWILIO_USER_SID: ${{ secrets.TWILIO_USER_SID }}
TWILIO_OAUTH_CLIENT_SECRET: ${{ secrets.TWILIO_OAUTH_CLIENT_SECRET }}
TWILIO_OAUTH_CLIENT_ID: ${{ secrets.TWILIO_OAUTH_CLIENT_ID }}
TWILIO_MESSAGE_SID: ${{ secrets.TWILIO_MESSAGE_SID }}
run: make cluster-test

- name: Fix code coverage paths
Expand Down
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Metrics/BlockLength:
Exclude:
- 'spec/**/*'
- twilio-ruby.gemspec
- 'cluster_orgs_spec.rb'
- 'cluster_oauth_spec.rb'

Layout/HeredocIndentation:
Expand Down
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ docker-push:

cluster-test:
bundle exec rspec ./cluster_spec.rb

cluster-oauth-test:
bundle exec rpec ./cluster_oauth_spec.rb
bundle exec rspec ./cluster_oauth_spec.rb
bundle exec rspec ./cluster_orgs_spec.rb

prettier:
bundle exec rubocop -A -d --cache true --parallel
57 changes: 6 additions & 51 deletions cluster_oauth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,16 @@

describe 'Cluster Test' do
before(:each) do
@account_sid = ENV['TWILIO_ACCOUNT_OAUTH_SID']
@client_secret = ENV['TWILIO_CLIENT_OAUTH_SECRET']
@client_id = ENV['TWILIO_CLIENT_OAUTH_ID']
@org_sid = ENV['TWILIO_ORG_SID']
@user_sid = ENV['TWILIO_USER_SID']
@account_sid = ENV['TWILIO_ACCOUNT_SID']
@client_secret = ENV['TWILIO_OAUTH_CLIENT_SECRET']
@client_id = ENV['TWILIO_OAUTH_CLIENT_ID']
@message_sid = ENV['TWILIO_MESSAGE_SID']
@credential = Twilio::REST::ClientCredentialProvider.new(@client_id, @client_secret)
@client = Twilio::REST::Client.new(@account_sid).credential_provider(@credential)
end

it 'can send a text' do
response = @client.preview_iam.organizations(@org_sid).accounts.list
it 'can fetch a message' do
response = @client.messages(@message_sid).fetch
expect(response).to_not be_nil
response.each do |element|
expect(element.account_sid).to_not be_nil
expect(element.friendly_name).to_not be_nil
expect(element.status).to_not be_nil
expect(element.owner_sid).to_not be_nil
expect(element.date_created).to_not be_nil
end
end

it 'can fetch specific account' do
response = @client.preview_iam.organizations(@org_sid).accounts(@account_sid).fetch
expect(response).to_not be_nil
expect(response.account_sid).to eq(@account_sid)
expect(response.friendly_name).to_not be_nil
expect(response.status).to_not be_nil
expect(response.owner_sid).to_not be_nil
expect(response.date_created).to_not be_nil
end

it 'can access role assignments list' do
response = @client.preview_iam.organizations(@org_sid).role_assignments.list(scope: @account_sid)
expect(response).to_not be_nil
response.each do |element|
expect(element.sid).to_not be_nil
expect(element.role_sid).to_not be_nil
expect(element.scope).to_not be_nil
expect(element.identity).to_not be_nil
end
end

it 'can get user list' do
response = @client.preview_iam.organizations(@org_sid).users.list
expect(response).to_not be_nil
response.each do |element|
expect(element.id).to_not be_nil
end
end

it 'can get single user' do
response = @client.preview_iam.organizations(@org_sid).users(@user_sid).fetch
expect(response).to_not be_nil
expect(response.id).to eq(@user_sid)
expect(response.emails[0]['value']).to_not be_nil
expect(response.emails[0]['type']).to_not be_nil
end
end
63 changes: 63 additions & 0 deletions cluster_orgs_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
require 'rspec/matchers'
require 'twilio-ruby'
require './lib/twilio-ruby/credential/client_credential_provider'

describe 'Cluster Test' do
before(:each) do
@client_secret = ENV['TWILIO_ORGS_CLIENT_SECRET']
@client_id = ENV['TWILIO_ORGS_CLIENT_ID']
@org_sid = ENV['TWILIO_ORG_SID']
@user_sid = ENV['TWILIO_USER_SID']
@credential = Twilio::REST::ClientCredentialProvider.new(@client_id, @client_secret)
@client = Twilio::REST::Client.new.credential_provider(@credential)
end

it 'can send a text' do
response = @client.preview_iam.organizations(@org_sid).accounts.list
expect(response).to_not be_nil
response.each do |element|
expect(element.account_sid).to_not be_nil
expect(element.friendly_name).to_not be_nil
expect(element.status).to_not be_nil
expect(element.owner_sid).to_not be_nil
expect(element.date_created).to_not be_nil
end
end

it 'can fetch specific account' do
response = @client.preview_iam.organizations(@org_sid).accounts(@account_sid).fetch
expect(response).to_not be_nil
expect(response.account_sid).to eq(@account_sid)
expect(response.friendly_name).to_not be_nil
expect(response.status).to_not be_nil
expect(response.owner_sid).to_not be_nil
expect(response.date_created).to_not be_nil
end

it 'can access role assignments list' do
response = @client.preview_iam.organizations(@org_sid).role_assignments.list(scope: @account_sid)
expect(response).to_not be_nil
response.each do |element|
expect(element.sid).to_not be_nil
expect(element.role_sid).to_not be_nil
expect(element.scope).to_not be_nil
expect(element.identity).to_not be_nil
end
end

it 'can get user list' do
response = @client.preview_iam.organizations(@org_sid).users.list
expect(response).to_not be_nil
response.each do |element|
expect(element.id).to_not be_nil
end
end

it 'can get single user' do
response = @client.preview_iam.organizations(@org_sid).users(@user_sid).fetch
expect(response).to_not be_nil
expect(response.id).to eq(@user_sid)
expect(response.emails[0]['value']).to_not be_nil
expect(response.emails[0]['type']).to_not be_nil
end
end

0 comments on commit ae94805

Please sign in to comment.