nexaas_id-client 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.env.test +5 -0
- data/.gitignore +25 -0
- data/.hound.yml +1063 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +130 -0
- data/LICENSE +202 -0
- data/README.md +157 -0
- data/Rakefile +16 -0
- data/lib/nexaas_id/client/application.rb +35 -0
- data/lib/nexaas_id/client/exception.rb +30 -0
- data/lib/nexaas_id/client/exception_wrapper.rb +23 -0
- data/lib/nexaas_id/client/identity.rb +67 -0
- data/lib/nexaas_id/client/oauth.rb +20 -0
- data/lib/nexaas_id/client.rb +2 -0
- data/lib/nexaas_id/configuration.rb +13 -0
- data/lib/nexaas_id/entities/base.rb +5 -0
- data/lib/nexaas_id/entities/collection.rb +53 -0
- data/lib/nexaas_id/entities/profile/contacts.rb +4 -0
- data/lib/nexaas_id/entities/profile/emails.rb +4 -0
- data/lib/nexaas_id/entities/profile/professional_info.rb +6 -0
- data/lib/nexaas_id/entities/profile.rb +14 -0
- data/lib/nexaas_id/entities/sign_up.rb +5 -0
- data/lib/nexaas_id/entities.rb +2 -0
- data/lib/nexaas_id/resources/base.rb +34 -0
- data/lib/nexaas_id/resources/profile.rb +67 -0
- data/lib/nexaas_id/resources/sign_up.rb +30 -0
- data/lib/nexaas_id/resources/widget.rb +28 -0
- data/lib/nexaas_id/resources.rb +2 -0
- data/lib/nexaas_id/version.rb +4 -0
- data/lib/nexaas_id.rb +40 -0
- data/nexaas_id-client.gemspec +43 -0
- data/spec/nexaas_id/client/application_spec.rb +13 -0
- data/spec/nexaas_id/client/exception_spec.rb +15 -0
- data/spec/nexaas_id/client/exception_wrapper_spec.rb +48 -0
- data/spec/nexaas_id/client/identity_spec.rb +29 -0
- data/spec/nexaas_id/configuration_spec.rb +38 -0
- data/spec/nexaas_id/resources/profile_spec.rb +54 -0
- data/spec/nexaas_id/resources/sign_up_spec.rb +33 -0
- data/spec/nexaas_id/resources/widget_spec.rb +18 -0
- data/spec/nexaas_id_spec.rb +30 -0
- data/spec/spec_helper.rb +43 -0
- data/spec/support/authorization.rb +62 -0
- metadata +331 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'oauth2'
|
2
|
+
|
3
|
+
# OAuth2 client used by NexaasID::Client::Application and NexaasID::Client::Identity.
|
4
|
+
# Provides direct access to the underlying OAuth2 API.
|
5
|
+
class NexaasID::Client::OAuth
|
6
|
+
|
7
|
+
def self.build
|
8
|
+
config = NexaasID.configuration
|
9
|
+
OAuth2::Client.new(config.application_token,
|
10
|
+
config.application_secret,
|
11
|
+
site: config.url,
|
12
|
+
connection_opts: { headers: headers })
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def self.headers
|
18
|
+
{ 'Accept': 'application/json', 'Content-type': 'application/json' }
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class NexaasID::Configuration
|
2
|
+
|
3
|
+
attr_accessor :url, :user_agent, :application_token, :application_secret
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@url = 'https://id.nexaas.com'
|
7
|
+
@user_agent = "Nexaas ID Ruby Client v#{NexaasID::VERSION}"
|
8
|
+
end
|
9
|
+
|
10
|
+
def url_for(path)
|
11
|
+
%(#{url.chomp('/')}#{path})
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class NexaasID::Entities::Collection < Base
|
2
|
+
extend Forwardable
|
3
|
+
|
4
|
+
PAGE_REGEX = /page=(\d+)/
|
5
|
+
|
6
|
+
attr_reader :total
|
7
|
+
def_delegators :@collection, :first, :last, :each, :map, :count, :empty?, :any?
|
8
|
+
|
9
|
+
def initialize(response, entity_class)
|
10
|
+
@response = response
|
11
|
+
@entity_class = entity_class
|
12
|
+
@total = parsed_body['count'].to_i
|
13
|
+
@collection = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.build(response, entity_class)
|
17
|
+
self.new(response, entity_class).build
|
18
|
+
end
|
19
|
+
|
20
|
+
def build
|
21
|
+
build_collection
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def next_page
|
26
|
+
page_for('next')
|
27
|
+
end
|
28
|
+
|
29
|
+
def previous_page
|
30
|
+
page_for('previous')
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_a
|
34
|
+
@collection.clone
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def page_for(page_rel)
|
40
|
+
match = parsed_body[page_rel].match(PAGE_REGEX)
|
41
|
+
return match[1].to_i if match
|
42
|
+
end
|
43
|
+
|
44
|
+
def build_collection
|
45
|
+
parsed_body['collection'].each do |attributes|
|
46
|
+
@collection.push(@entity_class.new(attributes))
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def parsed_body
|
51
|
+
@parsed_body ||= @response.parsed
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class NexaasID::Entities::Profile < NexaasID::Entities::Base
|
2
|
+
attribute :id, Integer
|
3
|
+
attribute :name, String
|
4
|
+
attribute :nickname, String
|
5
|
+
attribute :email, String
|
6
|
+
attribute :birth, Date
|
7
|
+
attribute :gender, String
|
8
|
+
attribute :language, String
|
9
|
+
attribute :picture, String
|
10
|
+
attribute :timezone, String
|
11
|
+
attribute :country, String
|
12
|
+
attribute :city, String
|
13
|
+
attribute :bio, String
|
14
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Default root for all resource classes.
|
2
|
+
class NexaasID::Resources::Base
|
3
|
+
# Creates an instance of this class.
|
4
|
+
#
|
5
|
+
# @param [api] api An instance of OAuth2::AccessToken
|
6
|
+
def initialize(api)
|
7
|
+
@api = api
|
8
|
+
end
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
attr_reader :api
|
13
|
+
|
14
|
+
# Builds an entity from the OAuth2 response.
|
15
|
+
#
|
16
|
+
# @param [OAuth2::Response] response The response from any OAuth2::AccessToken method
|
17
|
+
# @param [NexaasID::Entities::Base] naked_klass The class which the response will be
|
18
|
+
# deserialized into (must be a subtype of NexaasID::Entities::Base).
|
19
|
+
# Optional if the entity name is the same as the resource name.
|
20
|
+
#
|
21
|
+
# @return [NexaasID::Entities::Base] an instance of naked_class
|
22
|
+
def respond_with_entity(response, naked_klass = entity_klass)
|
23
|
+
# response.parsed is a Hash
|
24
|
+
naked_klass.new(response.parsed)
|
25
|
+
end
|
26
|
+
|
27
|
+
def base_klass
|
28
|
+
@base_klass ||= self.class.name.split("::").last
|
29
|
+
end
|
30
|
+
|
31
|
+
def entity_klass
|
32
|
+
@entity_klass ||= NexaasID::Entities.const_get(base_klass.to_sym)
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# A wrapper to Nexaas ID's profile API
|
2
|
+
#
|
3
|
+
# [API]
|
4
|
+
# Documentation:
|
5
|
+
#
|
6
|
+
# @example Getting the user's profile:
|
7
|
+
# client = NexaasID::Client::Identity.new(credentials)
|
8
|
+
# client.profile.get
|
9
|
+
#
|
10
|
+
# @example Getting the user's list of emails:
|
11
|
+
# client = NexaasID::Client::Identity.new(credentials)
|
12
|
+
# client.profile.emails
|
13
|
+
#
|
14
|
+
# @see NexaasID::Client::Identity#initialize
|
15
|
+
class NexaasID::Resources::Profile < NexaasID::Resources::Base
|
16
|
+
|
17
|
+
# Retrieves the user's profile
|
18
|
+
#
|
19
|
+
# [API]
|
20
|
+
# Method: <tt>GET /api/v1/profile</tt>
|
21
|
+
#
|
22
|
+
# Documentation:
|
23
|
+
#
|
24
|
+
# @return [NexaasID::Entities::Profile] user's profile
|
25
|
+
def get
|
26
|
+
respond_with_entity(api.get('/api/v1/profile'))
|
27
|
+
end
|
28
|
+
|
29
|
+
# Retrieves the user's professional info
|
30
|
+
#
|
31
|
+
# [API]
|
32
|
+
# Method: <tt>GET /api/v1/profile/professional_info</tt>
|
33
|
+
#
|
34
|
+
# Documentation:
|
35
|
+
#
|
36
|
+
# @return [NexaasID::Entities::Profile::ProfessionalInfo] user's professional info
|
37
|
+
def professional_info
|
38
|
+
respond_with_entity(api.get('/api/v1/profile/professional_info'),
|
39
|
+
NexaasID::Entities::Profile::ProfessionalInfo)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Retrieves the user's contacts
|
43
|
+
#
|
44
|
+
# [API]
|
45
|
+
# Method: <tt>GET /api/v1/profile/contacts</tt>
|
46
|
+
#
|
47
|
+
# Documentation:
|
48
|
+
#
|
49
|
+
# @return [NexaasID::Entities::Profile::Contacts] user's contacts
|
50
|
+
def contacts
|
51
|
+
respond_with_entity(api.get('/api/v1/profile/contacts'),
|
52
|
+
NexaasID::Entities::Profile::Contacts)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Retrieves the user's emails
|
56
|
+
#
|
57
|
+
# [API]
|
58
|
+
# Method: <tt>GET /api/v1/profile/emails</tt>
|
59
|
+
#
|
60
|
+
# Documentation:
|
61
|
+
#
|
62
|
+
# @return [NexaasID::Entities::Profile::Emails] user's emails
|
63
|
+
def emails
|
64
|
+
respond_with_entity(api.get('/api/v1/profile/emails'),
|
65
|
+
NexaasID::Entities::Profile::Emails)
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# A wrapper to Nexaas ID's sign up API
|
2
|
+
#
|
3
|
+
# [API]
|
4
|
+
# Documentation:
|
5
|
+
#
|
6
|
+
# @example Inviting a new user to Nexaas ID (on behalf of an existing user):
|
7
|
+
# client = NexaasID::Client::Identity.new(credentials)
|
8
|
+
# client.sign_up.create('john.doe@gmail.com')
|
9
|
+
#
|
10
|
+
# @example Inviting a new user to Nexaas ID (on behalf of an application):
|
11
|
+
# client = NexaasID::Client::Application.new
|
12
|
+
# client.sign_up.create('john.doe@gmail.com')
|
13
|
+
#
|
14
|
+
# @see NexaasID::Client::Identity#initialize
|
15
|
+
# @see NexaasID::Client::Application#initialize
|
16
|
+
class NexaasID::Resources::SignUp < NexaasID::Resources::Base
|
17
|
+
|
18
|
+
# Invites an user to Nexaas ID, by creating a new sign up.
|
19
|
+
#
|
20
|
+
# [API]
|
21
|
+
# Method: <tt>POST /api/v1/sign_up</tt>
|
22
|
+
#
|
23
|
+
# Documentation:
|
24
|
+
# @param [String] email The new user's email.
|
25
|
+
#
|
26
|
+
# @return [NexaasID::Entities::SignUp] the new sign up; it contains the invited user's id.
|
27
|
+
def create(email)
|
28
|
+
respond_with_entity(api.post('/api/v1/sign_up', body: MultiJson.dump({ invited: email })))
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# A wrapper to Nexaas ID's widget API
|
2
|
+
#
|
3
|
+
# [API]
|
4
|
+
# Documentation:
|
5
|
+
#
|
6
|
+
# @example Obtaining the user's navbar URL:
|
7
|
+
# client = NexaasID::Client::Identity.new(credentials)
|
8
|
+
# client.widget.navbar_url
|
9
|
+
#
|
10
|
+
# @example Inviting a new user to Nexaas ID (on behalf of an application):
|
11
|
+
# client = NexaasID::Client::Application.new
|
12
|
+
# client.sign_up.create('john.doe@gmail.com')
|
13
|
+
#
|
14
|
+
# @see NexaasID::Client::Identity#initialize
|
15
|
+
class NexaasID::Resources::Widget < NexaasID::Resources::Base
|
16
|
+
|
17
|
+
# Retrieves the user's navbar URL
|
18
|
+
#
|
19
|
+
# [API]
|
20
|
+
# Method: <tt>GET /api/v1/widgets/navbar</tt>
|
21
|
+
#
|
22
|
+
# Documentation:
|
23
|
+
#
|
24
|
+
# @return [String] user's navbar URL
|
25
|
+
def navbar_url
|
26
|
+
%(#{NexaasID.configuration.url}/api/v1/widgets/navbar?access_token=#{api.token})
|
27
|
+
end
|
28
|
+
end
|
data/lib/nexaas_id.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'oauth2'
|
4
|
+
require 'multi_json'
|
5
|
+
|
6
|
+
require "nexaas_id/version"
|
7
|
+
require "nexaas_id/configuration"
|
8
|
+
|
9
|
+
require "nexaas_id/client"
|
10
|
+
require "nexaas_id/client/application"
|
11
|
+
require "nexaas_id/client/exception"
|
12
|
+
require "nexaas_id/client/exception_wrapper"
|
13
|
+
require "nexaas_id/client/identity"
|
14
|
+
require "nexaas_id/client/oauth"
|
15
|
+
|
16
|
+
require "nexaas_id/entities"
|
17
|
+
require "nexaas_id/entities/base"
|
18
|
+
|
19
|
+
require "nexaas_id/entities/profile"
|
20
|
+
require "nexaas_id/entities/profile/professional_info"
|
21
|
+
require "nexaas_id/entities/profile/contacts"
|
22
|
+
require "nexaas_id/entities/profile/emails"
|
23
|
+
|
24
|
+
require "nexaas_id/entities/sign_up"
|
25
|
+
|
26
|
+
require "nexaas_id/resources"
|
27
|
+
require "nexaas_id/resources/base"
|
28
|
+
require "nexaas_id/resources/profile"
|
29
|
+
require "nexaas_id/resources/sign_up"
|
30
|
+
require "nexaas_id/resources/widget"
|
31
|
+
|
32
|
+
module NexaasID
|
33
|
+
def self.configuration
|
34
|
+
@configuration ||= Configuration.new
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.configure
|
38
|
+
yield(configuration) if block_given?
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
# Ensure we require the local version and not one we might have installed already
|
6
|
+
require File.join([File.dirname(__FILE__),'lib','nexaas_id','version.rb'])
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = "nexaas_id-client"
|
10
|
+
spec.version = NexaasID::VERSION
|
11
|
+
spec.authors = ["Rodrigo Tassinari de Oliveira", "Eduardo Hertz", "Rafael B. Tauil", "Luiz Carlos Buiatte"]
|
12
|
+
spec.email = ["rodrigo@pittlandia.net", "rodrigo.tassinari@myfreecomm.com.br", "eduardo.hertz@myfreecomm.com.br", "rafael@tauil.com.br", "luiz.buiatte@nexaas.com"]
|
13
|
+
spec.description = %q{A Ruby client for the Nexaas ID REST API}
|
14
|
+
spec.summary = %q{A Ruby client for the Nexaas ID REST API: https://id.nexaas.com/static/docs/}
|
15
|
+
spec.homepage = "https://github.com/myfreecomm/nexaas-id-client-ruby"
|
16
|
+
spec.license = "Apache-2.0"
|
17
|
+
spec.has_rdoc = true
|
18
|
+
|
19
|
+
# VCR cassettes are too long for the gemspec, see http://stackoverflow.com/questions/14371686/building-rails-3-engine-throwing-gempackagetoolongfilename-error
|
20
|
+
# spec.files = `git ls-files`.split($/)
|
21
|
+
spec.files = `git ls-files`.split($/).reject { |f| f =~ %r{(vcr_cassettes)/} }
|
22
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
23
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_dependency "multi_json", "~> 1.11"
|
27
|
+
spec.add_dependency "virtus", "~> 1.0"
|
28
|
+
spec.add_dependency "oauth2", "~> 1.4.0"
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
31
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
32
|
+
spec.add_development_dependency "rdoc", "~> 6.0"
|
33
|
+
spec.add_development_dependency "rspec", "~> 3.6"
|
34
|
+
spec.add_development_dependency "vcr", "~> 2.4"
|
35
|
+
spec.add_development_dependency 'webmock', '~> 3.4'
|
36
|
+
spec.add_development_dependency "pry-byebug", "~> 3.4"
|
37
|
+
spec.add_development_dependency "awesome_print", "~> 1.8"
|
38
|
+
spec.add_development_dependency "simplecov", "~> 0.14"
|
39
|
+
spec.add_development_dependency "coveralls", "~> 0.8"
|
40
|
+
spec.add_development_dependency "json", "~> 2.1"
|
41
|
+
spec.add_development_dependency "faraday-cookie_jar", "~> 0.0.6"
|
42
|
+
spec.add_development_dependency "dotenv", "~> 2.5.0"
|
43
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NexaasID::Client::Application do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
describe '#sign_up' do
|
7
|
+
it 'provides the signup resource' do
|
8
|
+
VCR.use_cassette('application/sign_up/client_credentials') do
|
9
|
+
expect(subject.sign_up).to be_a(NexaasID::Resources::SignUp)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NexaasID::Client::Exception do
|
4
|
+
subject { described_class.new('foobar', response) }
|
5
|
+
|
6
|
+
let(:headers) { { 'Content-Type' => 'application/json' } }
|
7
|
+
let(:body) { { text: 'Coffee brewing failed' }.to_json }
|
8
|
+
let(:response) do
|
9
|
+
OAuth2::Response.new(double('response', status: 418, headers: headers, body: body))
|
10
|
+
end
|
11
|
+
|
12
|
+
it { expect(subject.status).to eq(418) }
|
13
|
+
it { expect(subject.headers).to eq(headers) }
|
14
|
+
it { expect(subject.body).to eq(body) }
|
15
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NexaasID::Client::ExceptionWrapper do
|
4
|
+
let(:token) { instance_double('OAuth::AccessToken') }
|
5
|
+
subject { described_class.new(token) }
|
6
|
+
|
7
|
+
let(:oauth2_error) { OAuth2::Error.new(response) }
|
8
|
+
let(:faraday_error) { Faraday::ClientError.new(Faraday::Error::ConnectionFailed.new('timeout')) }
|
9
|
+
let(:headers) { { 'Content-Type' => 'application/json' } }
|
10
|
+
let(:body) { { text: 'Coffee brewing failed' }.to_json }
|
11
|
+
let(:response) do
|
12
|
+
OAuth2::Response.new(double('response', status: 418, headers: headers, body: body))
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#request' do
|
16
|
+
it 'delegates to token' do
|
17
|
+
expect(token).to receive(:request).with(:get, '/api/v1/profile')
|
18
|
+
subject.request(:get, '/api/v1/profile')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should raise an exception for Faraday::ClientError' do
|
22
|
+
expect(token).to receive(:request).with(:get, '/api/v1/profile').and_raise(faraday_error)
|
23
|
+
expect { subject.request(:get, '/api/v1/profile') }.to raise_error(NexaasID::Client::Exception)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should raise an exception for Faraday::ClientError' do
|
27
|
+
expect(token).to receive(:request).with(:get, '/api/v1/profile').and_raise(oauth2_error)
|
28
|
+
expect { subject.request(:get, '/api/v1/profile') }.to raise_error(NexaasID::Client::Exception)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#refresh' do
|
33
|
+
it 'delegates to token' do
|
34
|
+
expect(token).to receive(:refresh).with(a: :b)
|
35
|
+
subject.refresh(a: :b)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should raise an exception for Faraday::ClientError' do
|
39
|
+
expect(token).to receive(:refresh).with(a: :b).and_raise(faraday_error)
|
40
|
+
expect { subject.refresh(a: :b) }.to raise_error(NexaasID::Client::Exception)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should raise an exception for Faraday::ClientError' do
|
44
|
+
expect(token).to receive(:refresh).with(a: :b).and_raise(oauth2_error)
|
45
|
+
expect { subject.refresh(a: :b) }.to raise_error(NexaasID::Client::Exception)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NexaasID::Client::Identity do
|
4
|
+
subject { described_class.new(user_credentials) }
|
5
|
+
|
6
|
+
describe '#profile' do
|
7
|
+
it 'provides the profile resource' do
|
8
|
+
VCR.use_cassette('identity/refresh_token') do
|
9
|
+
expect(subject.profile).to be_a(NexaasID::Resources::Profile)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#sign_up' do
|
15
|
+
it 'provides the signup resource' do
|
16
|
+
VCR.use_cassette('identity/refresh_token') do
|
17
|
+
expect(subject.sign_up).to be_a(NexaasID::Resources::SignUp)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#sign_up' do
|
23
|
+
it 'provides the widget resource' do
|
24
|
+
VCR.use_cassette('identity/refresh_token') do
|
25
|
+
expect(subject.widget).to be_a(NexaasID::Resources::Widget)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe NexaasID::Configuration do
|
5
|
+
|
6
|
+
it "should use the production Nexaas ID URL by default" do
|
7
|
+
expect(NexaasID::Configuration.new.url).to eq('https://id.nexaas.com')
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should use a default user agent" do
|
11
|
+
expect(NexaasID::Configuration.new.user_agent).to eq("Nexaas ID Ruby Client v#{NexaasID::VERSION}")
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should allow setting the configuration parameters' do
|
15
|
+
config = NexaasID::Configuration.new
|
16
|
+
|
17
|
+
config.url = 'https://sandbox.id.nexaas.com'
|
18
|
+
config.application_token = '58ca7acc-9479-4671-8b7c-745c5a65ce08'
|
19
|
+
config.application_secret = '8da0d1a5-961d-461f-8ae6-1922db172340'
|
20
|
+
|
21
|
+
expect(config.url).to eq('https://sandbox.id.nexaas.com')
|
22
|
+
expect(config.application_token).to eq('58ca7acc-9479-4671-8b7c-745c5a65ce08')
|
23
|
+
expect(config.application_secret).to eq('8da0d1a5-961d-461f-8ae6-1922db172340')
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#url_for' do
|
27
|
+
let(:configuration) { described_class.new }
|
28
|
+
|
29
|
+
it 'generates an URL to a resource' do
|
30
|
+
expect(configuration.url_for('/api/v1/profile')).to eq('https://id.nexaas.com/api/v1/profile')
|
31
|
+
|
32
|
+
configuration.url = 'https://sandbox.id.nexaas.com/'
|
33
|
+
expect(configuration.url_for('/api/v1/profile'))
|
34
|
+
.to eq('https://sandbox.id.nexaas.com/api/v1/profile')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NexaasID::Resources::Profile do
|
4
|
+
let(:client) { NexaasID::Client::Identity.new(user_credentials) }
|
5
|
+
let(:resource) { client.profile }
|
6
|
+
|
7
|
+
describe "#get" do
|
8
|
+
subject { resource.get }
|
9
|
+
|
10
|
+
it 'returns the profile for the user' do
|
11
|
+
VCR.use_cassette('identity/profile/profile/success') do
|
12
|
+
expect(subject).to be_a(NexaasID::Entities::Profile)
|
13
|
+
expect(subject.id).to eq('57bb5938-d0c5-439a-9986-e5c565124beb')
|
14
|
+
expect(subject.email).to eq('luiz.buiatte+pw.api.test@nexaas.com')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#profession_info' do
|
20
|
+
subject { resource.professional_info }
|
21
|
+
|
22
|
+
it 'returns the professional info for the user' do
|
23
|
+
VCR.use_cassette('identity/profile/professional_info/success') do
|
24
|
+
expect(subject).to be_a(NexaasID::Entities::Profile::ProfessionalInfo)
|
25
|
+
expect(subject.id).to eq('57bb5938-d0c5-439a-9986-e5c565124beb')
|
26
|
+
expect(subject.company).to eq('Nexaas')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#contacts' do
|
32
|
+
subject { resource.contacts }
|
33
|
+
|
34
|
+
it 'returns the contacts for the user' do
|
35
|
+
VCR.use_cassette('identity/profile/contacts/success') do
|
36
|
+
expect(subject).to be_a(NexaasID::Entities::Profile::Contacts)
|
37
|
+
expect(subject.id).to eq('57bb5938-d0c5-439a-9986-e5c565124beb')
|
38
|
+
expect(subject.phone_numbers).not_to be_empty
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#contacts' do
|
44
|
+
subject { resource.emails }
|
45
|
+
|
46
|
+
it 'returns the contacts for the user' do
|
47
|
+
VCR.use_cassette('identity/profile/emails/success') do
|
48
|
+
expect(subject).to be_a(NexaasID::Entities::Profile::Emails)
|
49
|
+
expect(subject.id).to eq('57bb5938-d0c5-439a-9986-e5c565124beb')
|
50
|
+
expect(subject.emails).not_to be_empty
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NexaasID::Resources::SignUp do
|
4
|
+
let(:resource) { client.sign_up }
|
5
|
+
|
6
|
+
describe "#create" do
|
7
|
+
describe 'with application client' do
|
8
|
+
let(:client) { NexaasID::Client::Application.new }
|
9
|
+
subject { resource.create('demurtas@mailinator.com') }
|
10
|
+
|
11
|
+
it 'invites an user' do
|
12
|
+
VCR.use_cassette('application/sign_up/create/success') do
|
13
|
+
expect(subject.id).not_to be_nil
|
14
|
+
expect(subject.email).to eq('demurtas@mailinator.com')
|
15
|
+
expect(subject.requester).to be_nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'with identity client' do
|
21
|
+
let(:client) { NexaasID::Client::Identity.new(user_credentials) }
|
22
|
+
subject { resource.create('demurtas@mailinator.com') }
|
23
|
+
|
24
|
+
it 'invites an user' do
|
25
|
+
VCR.use_cassette('identity/sign_up/create/success') do
|
26
|
+
expect(subject.id).not_to be_nil
|
27
|
+
expect(subject.email).to eq('demurtas@mailinator.com')
|
28
|
+
expect(subject.requester).not_to be_nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NexaasID::Resources::Widget do
|
4
|
+
let(:client) { NexaasID::Client::Identity.new(user_credentials) }
|
5
|
+
let(:resource) { client.widget }
|
6
|
+
|
7
|
+
describe "#navbar_url" do
|
8
|
+
subject { resource.navbar_url }
|
9
|
+
let(:regexp) { %r(#{Regexp.quote(NexaasID.configuration.url)}/api/v1/widgets/navbar\?access_token=(.+?)$) }
|
10
|
+
|
11
|
+
it 'returns the navbar url for this user' do
|
12
|
+
VCR.use_cassette('identity/widget/navbar_url/success') do
|
13
|
+
expect(subject).to match(regexp)
|
14
|
+
expect(Faraday.get(subject).status).to eq(200)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|