amidoprofileservice 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/amidoprofileservice.gemspec +29 -0
- data/lib/amidoprofileservice.rb +97 -0
- data/lib/amidoprofileservice/api.rb +47 -0
- data/lib/amidoprofileservice/profile_service_result.rb +27 -0
- data/lib/amidoprofileservice/profile_service_uri.rb +27 -0
- data/lib/amidoprofileservice/version.rb +5 -0
- data/spec/api_spec.rb +76 -0
- data/spec/profile_service_result_spec.rb +47 -0
- data/spec/profile_service_spec.rb +247 -0
- data/spec/profile_service_uri_spec.rb +44 -0
- data/spec/spec_helper.rb +10 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0ee8d9b666713a6c0e848887b7ab508cf4152063
|
4
|
+
data.tar.gz: 22cc7638dffcdd875f6fc72358bd58112e09cb97
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fdf387d158db30ee21ed9f4d95307f520f9eb374c7b83202eb3c18f3c32a07ec3766890fd1919aa130f59af08dd7d3a513c305d69d3f7d16a42b5ca99c91a3e5
|
7
|
+
data.tar.gz: b62733d49ed41ec9857a242a90f8d37fcf2e4566c008a1384a5e105db04cbc5a62f438325db20cd200acce8467def1889eb2fab21f6cb90bf72776d78ae26c59
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
.idea/
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Antony Koch
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# AmidoProfileService
|
2
|
+
|
3
|
+
This gem is used in conjunction with the Amido profile service to persist and retrieve profiles.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'amidoprofileservice'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install amidoprofileservice
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Create a new instance
|
22
|
+
```ruby
|
23
|
+
require 'amidoprofileservice'
|
24
|
+
|
25
|
+
service = AmidoProfileService.new('subscription_key_here')
|
26
|
+
```
|
27
|
+
|
28
|
+
Then call the API via the following methods
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
service.create_profile('realm_here', 'user_id_here', 'delegate_access_token_here', { :name => 'Peter' })
|
32
|
+
```
|
33
|
+
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
1. Fork it ( https://github.com/amido/amido-profile-service-rubygem/fork )
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'amidoprofileservice/version'
|
5
|
+
require 'amidoprofileservice'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'amidoprofileservice'
|
9
|
+
spec.version = Amido::ProfileService::VERSION
|
10
|
+
spec.authors = ['Antony Koch']
|
11
|
+
spec.email = ['ant@iamkoch.com']
|
12
|
+
spec.summary = %q{Ruby Gem to access the Amido profile service}
|
13
|
+
spec.description = %q{This gem allows subscribers to the amido profile service to consume the service in Ruby}
|
14
|
+
spec.homepage = 'http://amido.com'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
23
|
+
spec.add_development_dependency 'rake', '10.4.0'
|
24
|
+
spec.add_development_dependency 'rspec', '3.1.0'
|
25
|
+
spec.add_development_dependency 'capybara', '2.4.4'
|
26
|
+
spec.add_development_dependency 'simplecov', '0.9.1'
|
27
|
+
|
28
|
+
spec.add_dependency 'httparty', '0.11.0'
|
29
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'amidoprofileservice/version'
|
2
|
+
require 'amidoprofileservice/api'
|
3
|
+
require 'amidoprofileservice/profile_service_uri'
|
4
|
+
require 'amidoprofileservice/profile_service_result'
|
5
|
+
|
6
|
+
class AmidoProfileService
|
7
|
+
attr_accessor :api
|
8
|
+
|
9
|
+
def initialize(subscription_key)
|
10
|
+
throw :no_subscription_key if subscription_key.nil?
|
11
|
+
@subscription_key = subscription_key
|
12
|
+
|
13
|
+
@api = Api.new(subscription_key)
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_profile(realm, user_id, delegate_token, profile = {})
|
17
|
+
throw :no_realm_passed if realm.nil?
|
18
|
+
throw :no_user_id_passed if user_id.nil?
|
19
|
+
throw :no_delegate_token_passed if delegate_token.nil?
|
20
|
+
|
21
|
+
uri = ProfileServiceUri.profile realm, user_id
|
22
|
+
|
23
|
+
result = @api.post(uri, profile, delegate_token)
|
24
|
+
|
25
|
+
ProfileServiceResult.new(result)
|
26
|
+
end
|
27
|
+
|
28
|
+
def update_profile(realm, user_id, delegate_token, profile = {})
|
29
|
+
throw :no_realm_passed if realm.nil?
|
30
|
+
throw :no_user_id_passed if user_id.nil?
|
31
|
+
throw :no_delegate_token_passed if delegate_token.nil?
|
32
|
+
|
33
|
+
uri = ProfileServiceUri.profile realm, user_id
|
34
|
+
|
35
|
+
result = @api.put(uri, profile, delegate_token)
|
36
|
+
|
37
|
+
ProfileServiceResult.new(result)
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_profile(realm, user_id, delegate_token)
|
41
|
+
throw :no_realm_passed if realm.nil?
|
42
|
+
throw :no_user_id_passed if user_id.nil?
|
43
|
+
throw :no_delegate_token_passed if delegate_token.nil?
|
44
|
+
|
45
|
+
uri = ProfileServiceUri.profile realm, user_id
|
46
|
+
|
47
|
+
result = @api.get(uri, delegate_token)
|
48
|
+
|
49
|
+
ProfileServiceResult.new(result)
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_nested_profile(realm, user_id, delegate_token)
|
53
|
+
throw :no_realm_passed if realm.nil?
|
54
|
+
throw :no_user_id_passed if user_id.nil?
|
55
|
+
throw :no_delegate_token_passed if delegate_token.nil?
|
56
|
+
|
57
|
+
uri = ProfileServiceUri.nested_profile realm, user_id
|
58
|
+
|
59
|
+
result = @api.get(uri, delegate_token)
|
60
|
+
|
61
|
+
ProfileServiceResult.new(result)
|
62
|
+
end
|
63
|
+
|
64
|
+
def is_profile_complete(realm, user_id, delegate_token)
|
65
|
+
throw :no_realm_passed if realm.nil?
|
66
|
+
throw :no_user_id_passed if user_id.nil?
|
67
|
+
throw :no_delegate_token_passed if delegate_token.nil?
|
68
|
+
|
69
|
+
uri = ProfileServiceUri.is_profile_complete realm, user_id
|
70
|
+
|
71
|
+
result = @api.get(uri, delegate_token)
|
72
|
+
|
73
|
+
ProfileServiceResult.new(result)
|
74
|
+
end
|
75
|
+
|
76
|
+
def get_nested_fieldset(realm, fieldset_name)
|
77
|
+
throw :no_realm_passed if realm.nil?
|
78
|
+
throw :no_fieldsetname_passed if fieldset_name.nil?
|
79
|
+
|
80
|
+
uri = ProfileServiceUri.nested_fieldset realm, fieldset_name
|
81
|
+
|
82
|
+
result = @api.get(uri)
|
83
|
+
|
84
|
+
ProfileServiceResult.new(result)
|
85
|
+
end
|
86
|
+
|
87
|
+
def get_fieldset(realm, fieldset_name)
|
88
|
+
throw :no_realm_passed if realm.nil?
|
89
|
+
throw :no_fieldsetname_passed if fieldset_name.nil?
|
90
|
+
|
91
|
+
uri = ProfileServiceUri.fieldset realm, fieldset_name
|
92
|
+
|
93
|
+
result = @api.get(uri)
|
94
|
+
|
95
|
+
ProfileServiceResult.new(result)
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
class Api
|
5
|
+
include HTTParty
|
6
|
+
|
7
|
+
def initialize(subscription_key)
|
8
|
+
throw :no_subscription_key_provided if subscription_key.nil?
|
9
|
+
|
10
|
+
@subscription_key = subscription_key
|
11
|
+
end
|
12
|
+
|
13
|
+
def post(uri, profile, delegate_token = nil)
|
14
|
+
self.class.post uri, :body => safe_convert_body_to_json(profile), :headers => create_headers(delegate_token)
|
15
|
+
end
|
16
|
+
|
17
|
+
def put(uri, profile, delegate_token = nil)
|
18
|
+
self.class.put uri, :body => safe_convert_body_to_json(profile), :headers => create_headers(delegate_token)
|
19
|
+
end
|
20
|
+
|
21
|
+
def get(uri, delegate_token = nil)
|
22
|
+
self.class.get uri, :headers => create_headers(delegate_token)
|
23
|
+
end
|
24
|
+
|
25
|
+
def delete(uri, delegate_token = nil)
|
26
|
+
self.class.delete uri, :headers => create_headers(delegate_token)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def create_headers(delegate_token)
|
32
|
+
headers = {
|
33
|
+
'content-type' => 'application/json',
|
34
|
+
'ocp-apim-subscription-key' => @subscription_key
|
35
|
+
}
|
36
|
+
|
37
|
+
headers['x-zumo-auth'] = delegate_token unless delegate_token.nil?
|
38
|
+
|
39
|
+
headers
|
40
|
+
end
|
41
|
+
|
42
|
+
def safe_convert_body_to_json(profile)
|
43
|
+
converted_profile = {}.to_json
|
44
|
+
converted_profile = profile.to_json unless profile.nil?
|
45
|
+
converted_profile
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'httparty/response'
|
2
|
+
class ProfileServiceResult
|
3
|
+
attr_reader :body, :status_code, :code
|
4
|
+
|
5
|
+
def initialize(httparty_response)
|
6
|
+
set_code httparty_response
|
7
|
+
set_body httparty_response
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def set_body(res)
|
13
|
+
@body = res.parsed_response
|
14
|
+
end
|
15
|
+
|
16
|
+
def set_code(res)
|
17
|
+
@status_code = res.code
|
18
|
+
|
19
|
+
case res.code
|
20
|
+
when 200..299 then @code = :OK
|
21
|
+
when 300..399 then @code = :REDIRECT
|
22
|
+
when 400..499 then @code = :CLIENT_ERROR
|
23
|
+
when 500..599 then @code = :SERVER_ERROR
|
24
|
+
else @code = :UNKNOWN_ERROR
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
|
3
|
+
class ProfileServiceUri
|
4
|
+
def self.base_url
|
5
|
+
'https://amidouserprofile.azure-api.net/client/api'
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.profile(realm, user_id)
|
9
|
+
"#{base_url}/profiles/#{URI::encode(realm)}/#{URI::encode(user_id)}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.is_profile_complete(realm, user_id)
|
13
|
+
"#{base_url}/profile/#{URI::encode(realm)}/#{URI::encode(user_id)}/status"
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.nested_profile(realm, user_id)
|
17
|
+
"#{base_url}/nestedprofiles/#{URI::encode(realm)}/#{URI::encode(user_id)}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.nested_fieldset(realm, fieldset_name)
|
21
|
+
"#{base_url}/nestedfieldsets/#{URI::encode(realm)}/#{URI::encode(fieldset_name)}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.fieldset(realm, fieldset_name)
|
25
|
+
"#{base_url}/fieldsets/#{URI::encode(realm)}/#{URI::encode(fieldset_name)}"
|
26
|
+
end
|
27
|
+
end
|
data/spec/api_spec.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
describe Api do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
@api_key = 'subscription_key'
|
8
|
+
@api = Api.new(@api_key)
|
9
|
+
@profile = { 'name' => 'michael' }
|
10
|
+
@delegate_token = '8975465d465sf6s5d65d4f6sfs6d5f4s6d54f6s5d4fs5d46'
|
11
|
+
@profile_as_json = @profile.to_json
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#constructor' do
|
15
|
+
it 'should take a subscription key as a parameter' do
|
16
|
+
expect(Api.new(@api_key)).to be_instance_of Api
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should throw an error if no key is passed' do
|
20
|
+
expect { Api.new(nil) }.to throw_symbol :no_subscription_key_provided
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#post' do
|
25
|
+
it 'should call post on HTTParty with the correct converted parameters' do
|
26
|
+
allow(Api).to receive(:post)
|
27
|
+
|
28
|
+
expect(Api).to receive(:post).with('uri', hash_including(:body => @profile_as_json, :headers => { 'content-type' => 'application/json', 'ocp-apim-subscription-key' => @api_key, 'x-zumo-auth' => @delegate_token }))
|
29
|
+
|
30
|
+
@api.post('uri', @profile, @delegate_token)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#put' do
|
35
|
+
it 'should call put on HTTParty with the correct converted parameters' do
|
36
|
+
allow(Api).to receive(:put)
|
37
|
+
|
38
|
+
expect(Api).to receive(:put).with('uri', hash_including(:body => @profile_as_json, :headers => { 'content-type' => 'application/json', 'ocp-apim-subscription-key' => @api_key, 'x-zumo-auth' => @delegate_token }))
|
39
|
+
|
40
|
+
@api.put('uri', @profile, @delegate_token)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#get' do
|
45
|
+
describe 'when called with delegate token' do
|
46
|
+
it 'should call get on HTTParty with the correct converted parameters' do
|
47
|
+
allow(Api).to receive(:get)
|
48
|
+
|
49
|
+
expect(Api).to receive(:get).with('uri', hash_including(:headers => { 'content-type' => 'application/json', 'ocp-apim-subscription-key' => @api_key, 'x-zumo-auth' => @delegate_token }))
|
50
|
+
|
51
|
+
@api.get('uri', @delegate_token)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe 'when called without a delegate token' do
|
56
|
+
it 'should call get on HTTParty with the correct converted parameters without the auth header ' do
|
57
|
+
allow(Api).to receive(:get)
|
58
|
+
|
59
|
+
expect(Api).to receive(:get).with('uri', hash_excluding(:headers => { 'x-zumo-auth' => @delegate_token }))
|
60
|
+
|
61
|
+
@api.get('uri', @delegate_token)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#delete' do
|
68
|
+
it 'should call delete on HTTParty with the correct converted parameters' do
|
69
|
+
allow(Api).to receive(:delete)
|
70
|
+
|
71
|
+
expect(Api).to receive(:delete).with('uri', hash_including(:headers => { 'content-type' => 'application/json', 'ocp-apim-subscription-key' => @api_key, 'x-zumo-auth' => @delegate_token }))
|
72
|
+
|
73
|
+
@api.delete('uri', @delegate_token)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
def expect_code(status_code, expected_result)
|
4
|
+
success_result = double('response')
|
5
|
+
allow(success_result).to receive(:code).and_return(status_code)
|
6
|
+
allow(success_result).to receive(:parsed_response).and_return({ :body => true })
|
7
|
+
|
8
|
+
res = ProfileServiceResult.new(success_result)
|
9
|
+
|
10
|
+
expect(res.code).to eq expected_result
|
11
|
+
expect(res.status_code).to eq(status_code)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe ProfileServiceResult do
|
15
|
+
describe '#constructor' do
|
16
|
+
it 'should set the OK code based on the response supplied' do
|
17
|
+
expect_code 201, :OK
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should set the REDIRECT code based on the response supplied' do
|
21
|
+
expect_code 301, :REDIRECT
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should set the CLIENT_ERROR code based on the response supplied' do
|
25
|
+
expect_code 401, :CLIENT_ERROR
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should set the SERVER_ERROR code based on the response supplied' do
|
29
|
+
expect_code 501, :SERVER_ERROR
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should set the SERVER_ERROR code based on the response supplied' do
|
33
|
+
expect_code 600, :UNKNOWN_ERROR
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should set the body based on the response supplied' do
|
37
|
+
success_result = double('response')
|
38
|
+
allow(success_result).to receive(:code).and_return(201)
|
39
|
+
body_hash = {:body => true}
|
40
|
+
allow(success_result).to receive(:parsed_response).and_return(body_hash)
|
41
|
+
|
42
|
+
res = ProfileServiceResult.new(success_result)
|
43
|
+
|
44
|
+
expect(res.body).to eq(body_hash)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,247 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AmidoProfileService do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@service = AmidoProfileService.new('subscription_key')
|
7
|
+
@valid_realm = 'my.realm.com'
|
8
|
+
@valid_user_id = 'facebook|r098098fk3r'
|
9
|
+
@valid_fieldset_name = 'register'
|
10
|
+
@valid_delegate_token = 'fljhdsf87s89d7f98s7df98s7df987f'
|
11
|
+
@profile = { :name => 'dave' }
|
12
|
+
@resulting_url = 'https://amidouserprofile.azure-api.net/client/api/some_uri'
|
13
|
+
end
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
@success_result = double('response')
|
17
|
+
allow(@success_result).to receive(:code).and_return(201)
|
18
|
+
allow(@success_result).to receive(:parsed_response).and_return(@profile)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#constructor' do
|
22
|
+
|
23
|
+
it 'should throw an error when no parameter is passed' do
|
24
|
+
expect { AmidoProfileService.new(nil) }.to throw_symbol(:no_subscription_key)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should create an instance of the API' do
|
28
|
+
expect(@service.api).to be_instance_of Api
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#create_profile' do
|
34
|
+
|
35
|
+
it 'should throw an error when no realm is passed' do
|
36
|
+
expect { @service.create_profile(nil, nil, nil) }.to throw_symbol(:no_realm_passed)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should throw an error when no user id is passed' do
|
40
|
+
expect { @service.create_profile(@valid_realm, nil, nil) }.to throw_symbol(:no_user_id_passed)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should throw an error when no delegate token is passed' do
|
44
|
+
expect { @service.create_profile(@valid_realm, @valid_user_id, nil) }.to throw_symbol(:no_delegate_token_passed)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should call post on the api with the correct parameters and return an OK result' do
|
48
|
+
|
49
|
+
allow(ProfileServiceUri).to receive(:profile).with(@valid_realm, @valid_user_id).and_return(@resulting_url)
|
50
|
+
|
51
|
+
expect(ProfileServiceUri).to receive(:profile).with(@valid_realm, @valid_user_id)
|
52
|
+
|
53
|
+
api = double('api')
|
54
|
+
allow(api).to receive(:post).with(@resulting_url, @profile, @valid_delegate_token).and_return @success_result
|
55
|
+
@service.api = api
|
56
|
+
result = @service.create_profile @valid_realm, @valid_user_id, @valid_delegate_token, @profile
|
57
|
+
|
58
|
+
expect(result).to be_instance_of(ProfileServiceResult)
|
59
|
+
expect(result.code).to eq(:OK)
|
60
|
+
expect(result.body).to eq(@profile)
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#update_profile' do
|
66
|
+
|
67
|
+
it 'should throw an error when no realm is passed' do
|
68
|
+
expect { @service.update_profile(nil, nil, nil) }.to throw_symbol(:no_realm_passed)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should throw an error when no user id is passed' do
|
72
|
+
expect { @service.update_profile(@valid_realm, nil, nil) }.to throw_symbol(:no_user_id_passed)
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should throw an error when no delegate token is passed' do
|
76
|
+
expect { @service.update_profile(@valid_realm, @valid_user_id, nil) }.to throw_symbol(:no_delegate_token_passed)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should call put on the api with the correct parameters and return an OK result' do
|
80
|
+
|
81
|
+
allow(ProfileServiceUri).to receive(:profile).with(@valid_realm, @valid_user_id).and_return(@resulting_url)
|
82
|
+
|
83
|
+
expect(ProfileServiceUri).to receive(:profile).with(@valid_realm, @valid_user_id)
|
84
|
+
|
85
|
+
api = double('api')
|
86
|
+
allow(api).to receive(:put).with(@resulting_url, @profile, @valid_delegate_token).and_return @success_result
|
87
|
+
@service.api = api
|
88
|
+
result = @service.update_profile @valid_realm, @valid_user_id, @valid_delegate_token, @profile
|
89
|
+
|
90
|
+
expect(result).to be_instance_of(ProfileServiceResult)
|
91
|
+
expect(result.code).to eq(:OK)
|
92
|
+
expect(result.body).to eq(@profile)
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
describe '#get_profile' do
|
98
|
+
|
99
|
+
it 'should throw an error when no realm is passed' do
|
100
|
+
expect { @service.get_profile(nil, nil, nil) }.to throw_symbol(:no_realm_passed)
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'should throw an error when no user id is passed' do
|
104
|
+
expect { @service.get_profile(@valid_realm, nil, nil) }.to throw_symbol(:no_user_id_passed)
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should throw an error when no delegate token is passed' do
|
108
|
+
expect { @service.get_profile(@valid_realm, @valid_user_id, nil) }.to throw_symbol(:no_delegate_token_passed)
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should call get on the api with the correct parameters and return an OK result' do
|
112
|
+
|
113
|
+
allow(ProfileServiceUri).to receive(:profile).with(@valid_realm, @valid_user_id).and_return(@resulting_url)
|
114
|
+
|
115
|
+
expect(ProfileServiceUri).to receive(:profile).with(@valid_realm, @valid_user_id)
|
116
|
+
|
117
|
+
api = double('api')
|
118
|
+
allow(api).to receive(:get).with(@resulting_url, @valid_delegate_token).and_return @success_result
|
119
|
+
@service.api = api
|
120
|
+
result = @service.get_profile @valid_realm, @valid_user_id, @valid_delegate_token
|
121
|
+
|
122
|
+
expect(result).to be_instance_of(ProfileServiceResult)
|
123
|
+
expect(result.code).to eq(:OK)
|
124
|
+
expect(result.body).to eq(@profile)
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
describe '#get_nested_profile' do
|
130
|
+
|
131
|
+
it 'should throw an error when no realm is passed' do
|
132
|
+
expect { @service.get_profile(nil, nil, nil) }.to throw_symbol(:no_realm_passed)
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'should throw an error when no user id is passed' do
|
136
|
+
expect { @service.get_profile(@valid_realm, nil, nil) }.to throw_symbol(:no_user_id_passed)
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'should throw an error when no delegate token is passed' do
|
140
|
+
expect { @service.get_profile(@valid_realm, @valid_user_id, nil) }.to throw_symbol(:no_delegate_token_passed)
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'should call get on the api with the correct parameters and return an OK result' do
|
144
|
+
|
145
|
+
allow(ProfileServiceUri).to receive(:nested_profile).with(@valid_realm, @valid_user_id).and_return(@resulting_url)
|
146
|
+
|
147
|
+
expect(ProfileServiceUri).to receive(:nested_profile).with(@valid_realm, @valid_user_id)
|
148
|
+
|
149
|
+
api = double('api')
|
150
|
+
allow(api).to receive(:get).with(@resulting_url, @valid_delegate_token).and_return @success_result
|
151
|
+
@service.api = api
|
152
|
+
result = @service.get_nested_profile @valid_realm, @valid_user_id, @valid_delegate_token
|
153
|
+
|
154
|
+
expect(result).to be_instance_of(ProfileServiceResult)
|
155
|
+
expect(result.code).to eq(:OK)
|
156
|
+
expect(result.body).to eq(@profile)
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
describe '#get_nested_fieldset' do
|
162
|
+
|
163
|
+
it 'should throw an error when no realm is passed' do
|
164
|
+
expect { @service.get_nested_fieldset(nil, nil) }.to throw_symbol(:no_realm_passed)
|
165
|
+
end
|
166
|
+
it 'should throw an error when no fieldset name is passed' do
|
167
|
+
expect { @service.get_nested_fieldset(@valid_realm, nil) }.to throw_symbol(:no_fieldsetname_passed)
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'should call get on the api with the correct parameters and return an OK result' do
|
171
|
+
|
172
|
+
allow(ProfileServiceUri).to receive(:nested_fieldset).with(@valid_realm, @valid_fieldset_name).and_return(@resulting_url)
|
173
|
+
|
174
|
+
expect(ProfileServiceUri).to receive(:nested_fieldset).with(@valid_realm, @valid_fieldset_name)
|
175
|
+
|
176
|
+
api = double('api')
|
177
|
+
allow(api).to receive(:get).with(@resulting_url).and_return @success_result
|
178
|
+
@service.api = api
|
179
|
+
result = @service.get_nested_fieldset @valid_realm, @valid_fieldset_name
|
180
|
+
|
181
|
+
expect(result).to be_instance_of(ProfileServiceResult)
|
182
|
+
expect(result.code).to eq(:OK)
|
183
|
+
expect(result.body).to eq(@profile)
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
187
|
+
|
188
|
+
describe '#get_fieldset' do
|
189
|
+
|
190
|
+
it 'should throw an error when no realm is passed' do
|
191
|
+
expect { @service.get_fieldset(nil, nil) }.to throw_symbol(:no_realm_passed)
|
192
|
+
end
|
193
|
+
it 'should throw an error when no fieldset name is passed' do
|
194
|
+
expect { @service.get_fieldset(@valid_realm, nil) }.to throw_symbol(:no_fieldsetname_passed)
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'should call get on the api with the correct parameters and return an OK result' do
|
198
|
+
|
199
|
+
allow(ProfileServiceUri).to receive(:fieldset).with(@valid_realm, @valid_fieldset_name).and_return(@resulting_url)
|
200
|
+
|
201
|
+
expect(ProfileServiceUri).to receive(:fieldset).with(@valid_realm, @valid_fieldset_name)
|
202
|
+
|
203
|
+
api = double('api')
|
204
|
+
allow(api).to receive(:get).with(@resulting_url).and_return @success_result
|
205
|
+
@service.api = api
|
206
|
+
result = @service.get_fieldset @valid_realm, @valid_fieldset_name
|
207
|
+
|
208
|
+
expect(result).to be_instance_of(ProfileServiceResult)
|
209
|
+
expect(result.code).to eq(:OK)
|
210
|
+
expect(result.body).to eq(@profile)
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
describe '#is_profile_complete' do
|
216
|
+
|
217
|
+
it 'should throw an error when no realm is passed' do
|
218
|
+
expect { @service.is_profile_complete(nil, nil, nil) }.to throw_symbol(:no_realm_passed)
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'should throw an error when no user id is passed' do
|
222
|
+
expect { @service.is_profile_complete(@valid_realm, nil, nil) }.to throw_symbol(:no_user_id_passed)
|
223
|
+
end
|
224
|
+
|
225
|
+
it 'should throw an error when no delegate token is passed' do
|
226
|
+
expect { @service.is_profile_complete(@valid_realm, @valid_user_id, nil) }.to throw_symbol(:no_delegate_token_passed)
|
227
|
+
end
|
228
|
+
|
229
|
+
it 'should call get on the api with the correct parameters and return an OK result' do
|
230
|
+
|
231
|
+
allow(ProfileServiceUri).to receive(:is_profile_complete).with(@valid_realm, @valid_user_id).and_return(@resulting_url)
|
232
|
+
|
233
|
+
expect(ProfileServiceUri).to receive(:is_profile_complete).with(@valid_realm, @valid_user_id)
|
234
|
+
|
235
|
+
api = double('api')
|
236
|
+
allow(api).to receive(:get).with(@resulting_url, @valid_delegate_token).and_return @success_result
|
237
|
+
@service.api = api
|
238
|
+
result = @service.is_profile_complete @valid_realm, @valid_user_id, @valid_delegate_token
|
239
|
+
|
240
|
+
expect(result).to be_instance_of(ProfileServiceResult)
|
241
|
+
expect(result.code).to eq(:OK)
|
242
|
+
expect(result.body).to eq(@profile)
|
243
|
+
end
|
244
|
+
|
245
|
+
end
|
246
|
+
|
247
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ProfileServiceUri do
|
4
|
+
|
5
|
+
describe '#profile' do
|
6
|
+
|
7
|
+
it 'should build the uri correctly' do
|
8
|
+
expect(ProfileServiceUri.profile 'my.realm.com', 'my_user_id').to eq('https://amidouserprofile.azure-api.net/client/api/profiles/my.realm.com/my_user_id')
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
describe '#is_profile_complete' do
|
13
|
+
|
14
|
+
it 'should build the uri correctly' do
|
15
|
+
expect(ProfileServiceUri.is_profile_complete 'my.realm.com', 'my_user_id').to eq('https://amidouserprofile.azure-api.net/client/api/profile/my.realm.com/my_user_id/status')
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#nested_profile' do
|
21
|
+
|
22
|
+
it 'should build the uri correctly' do
|
23
|
+
expect(ProfileServiceUri.nested_profile 'my.realm.com', 'my_user_id').to eq('https://amidouserprofile.azure-api.net/client/api/nestedprofiles/my.realm.com/my_user_id')
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#nested_fieldset' do
|
29
|
+
|
30
|
+
it 'should build the uri correctly' do
|
31
|
+
expect(ProfileServiceUri.nested_fieldset 'my.realm.com', 'register').to eq('https://amidouserprofile.azure-api.net/client/api/nestedfieldsets/my.realm.com/register')
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#fieldset' do
|
37
|
+
|
38
|
+
it 'should build the uri correctly' do
|
39
|
+
expect(ProfileServiceUri.fieldset 'my.realm.com', 'register').to eq('https://amidouserprofile.azure-api.net/client/api/fieldsets/my.realm.com/register')
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: amidoprofileservice
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Antony Koch
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 10.4.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 10.4.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.1.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.1.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: capybara
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.4.4
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.4.4
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.9.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.9.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: httparty
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.11.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.11.0
|
97
|
+
description: This gem allows subscribers to the amido profile service to consume the
|
98
|
+
service in Ruby
|
99
|
+
email:
|
100
|
+
- ant@iamkoch.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- amidoprofileservice.gemspec
|
112
|
+
- lib/amidoprofileservice.rb
|
113
|
+
- lib/amidoprofileservice/api.rb
|
114
|
+
- lib/amidoprofileservice/profile_service_result.rb
|
115
|
+
- lib/amidoprofileservice/profile_service_uri.rb
|
116
|
+
- lib/amidoprofileservice/version.rb
|
117
|
+
- spec/api_spec.rb
|
118
|
+
- spec/profile_service_result_spec.rb
|
119
|
+
- spec/profile_service_spec.rb
|
120
|
+
- spec/profile_service_uri_spec.rb
|
121
|
+
- spec/spec_helper.rb
|
122
|
+
homepage: http://amido.com
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.2.0
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: Ruby Gem to access the Amido profile service
|
146
|
+
test_files:
|
147
|
+
- spec/api_spec.rb
|
148
|
+
- spec/profile_service_result_spec.rb
|
149
|
+
- spec/profile_service_spec.rb
|
150
|
+
- spec/profile_service_uri_spec.rb
|
151
|
+
- spec/spec_helper.rb
|