-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #185 from plivo/kowshik_tokencreation
Kowshik tokencreation
- Loading branch information
Showing
8 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
module Plivo | ||
module Resources | ||
include Plivo | ||
include Plivo::Utils | ||
class Token < Base::Resource | ||
def initialize(client, options = nil) | ||
@_name = 'JWT/Token' | ||
super | ||
@_is_voice_request = true | ||
end | ||
def to_s | ||
{ | ||
api_id: @api_id, | ||
token: @token | ||
}.to_s | ||
end | ||
end | ||
|
||
class TokenInterface < Base::ResourceInterface | ||
def initialize(client, resource_list_json = nil) | ||
@_name = 'JWT/Token' | ||
@_resource_type = Token | ||
super | ||
@_is_voice_request = true | ||
end | ||
|
||
|
||
def create(iss , options = nil) | ||
valid_param?(:iss, iss, [String, Symbol, Hash], true) | ||
params = {} | ||
params[:iss] = iss | ||
|
||
return perform_create(params, false) if options.nil? | ||
# return perform_action('Record', 'POST', nil, true) if options.nil? | ||
valid_param?(:options, options, [Hash], false) | ||
|
||
|
||
if options.key?("sub") && valid_param?("sub", options["sub"], [String, Symbol], false ) | ||
params[:sub] = options["sub"] | ||
end | ||
if options.key("nbf") && valid_param?("nbf", options["nbf"], [Integer, Symbol], false ) | ||
params[:nbf] = options["nbf"] | ||
end | ||
if options.key("exp") && valid_param?("exp", options["exp"], [Integer, Symbol], false ) | ||
params[:exp] = options["exp"] | ||
end | ||
if options.key?("incoming_allow") || options.key?("outgoing_allow") | ||
params[:per] = {} | ||
params[:per][:voice] = {} | ||
if options.key?("incoming_allow") && valid_param?("incoming_allow", options["incoming_allow"], [TrueClass, FalseClass, String,Symbol], false) | ||
params[:per][:voice][:incoming_allow] = options["incoming_allow"] | ||
end | ||
if options.key?("outgoing_allow") && valid_param?("outgoing_allow", options["outgoing_allow"], [TrueClass, FalseClass, String, Symbol], false) | ||
params[:per][:voice][:outgoing_allow] = options["outgoing_allow"] | ||
end | ||
end | ||
if options.key?("app") && valid_param?("app", options["app"], [String, Symbol], false) | ||
params[:app] = options["app"] | ||
end | ||
|
||
perform_create(params.merge(options), false) | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Plivo | ||
VERSION = "4.28.0".freeze | ||
VERSION = "4.29.0".freeze | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"api_id": "c3a4d6c0-0b9a-11ed-9fa2-0242ac110004", | ||
"token": "eyJhbGciOiJIUzI1NiIsImN0eSI6InBsaXZvO3Y9MSIsInR5cCI6IkpXVCJ9.eyJhcHAiOiIiLCJleHAiOjE2NTg3ODU4ODUsImlzcyI6Ik1BTURWTFpKWTJaR1k1TVdVMVpKIiwibmJmIjoxNjU4Njk5NDg1LCJwZXIiOnsidm9pY2UiOnsiaW5jb21pbmdfYWxsb3ciOmZhbHNlLCJvdXRnb2luZ19hbGxvdyI6ZmFsc2V9fSwic3ViIjoiS293c2hpayJ9.iWwtfH9QNO7nIE_HK0GSJ3U81oRQR9gcUScrPixBK_s" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'rspec' | ||
|
||
describe 'Token test' do | ||
def to_json(token) | ||
{ | ||
iss:token.iss | ||
}.reject { |_, v| v.nil? }.to_json | ||
end | ||
def to_json_create(token) | ||
{ | ||
api_id: token.api_id, | ||
token: token.token | ||
|
||
}.reject { |_, v| v.nil? }.to_json | ||
end | ||
|
||
|
||
it 'creates a token' do | ||
contents = File.read(Dir.pwd + '/spec/mocks/tokenCreateResponse.json') | ||
mock(200, JSON.parse(contents)) | ||
expect(JSON.parse(to_json_create(@api.token | ||
.create('MAXXXXXXXXXXXXXXXXXX')))) | ||
.to eql(JSON.parse(contents).reject { |_, v| v.nil? }) | ||
compare_requests(uri: '/v1/Account/MAXXXXXXXXXXXXXXXXXX/JWT/Token/', | ||
method: 'POST', | ||
data: { | ||
iss:'MAXXXXXXXXXXXXXXXXXX', | ||
}) | ||
end | ||
end |