lexer-identity 0.1.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/.gitignore +6 -0
- data/.rubocop.yml +5 -0
- data/.travis.yml +15 -0
- data/Gemfile +12 -0
- data/LICENSE +20 -0
- data/README.md +66 -0
- data/Rakefile +11 -0
- data/lexer-identity.gemspec +30 -0
- data/lib/lexer.rb +7 -0
- data/lib/lexer/identity.rb +92 -0
- data/lib/lexer/identity/api.rb +68 -0
- data/lib/lexer/identity/configuration.rb +37 -0
- data/lib/lexer/identity/enriched_result.rb +26 -0
- data/lib/lexer/identity/version.rb +9 -0
- data/spec/lexer/identity/api_spec.rb +95 -0
- data/spec/lexer/identity/configuration_spec.rb +57 -0
- data/spec/lexer/identity_spec.rb +17 -0
- data/spec/spec_helper.rb +20 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a395e6932b3a744d3a9e85f22a14842139afa5dd
|
4
|
+
data.tar.gz: c1772af7cfaae2a992d2ddbc599edd3481913d70
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dfd879f57b3a28d98d54033966dc35f6089a5df8d08f11935d78c1d6dbbb8fffa64cd27a2f4ad7d51a7092277129a36432bc4cf5773727d8ebb84755bf0c2ab4
|
7
|
+
data.tar.gz: 13284a564344bfc9220ec37a9d048d3f59b84761674bc8086858b9be3150dc5c42ce3588b0d5bc786019227b86d65208695e310e2523124ee1ebf07d5050399c
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2015 Lexer
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Lexer Identities Official Ruby Client Library
|
2
|
+
|
3
|
+
[](http://travis-ci.org/lexerdev/lexer-identity-gem)
|
4
|
+
[](https://codeclimate.com/github/lexerdev/lexer-identity-gem)
|
5
|
+
|
6
|
+
lexer-identity-gem is the official Ruby Client for the [Lexer Identity](https://lexer.io/) API. The
|
7
|
+
Lexer Identity API lets brands contribute and consume from Lexer's Identity database directly from their apps.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add to your Gemfile:
|
12
|
+
|
13
|
+
gem 'lexer-identity'
|
14
|
+
|
15
|
+
or install from Rubygems:
|
16
|
+
|
17
|
+
gem install lexer-identity
|
18
|
+
|
19
|
+
|
20
|
+
## Details
|
21
|
+
|
22
|
+
### Links:
|
23
|
+
|
24
|
+
Have a limited list of keys which can be reviewed at: http://developer.lexer.io/
|
25
|
+
Your hash should reflect the following format:
|
26
|
+
|
27
|
+
{
|
28
|
+
email: "joe.smith@mybrand.com",
|
29
|
+
phone: "61440000000",
|
30
|
+
twitter: "camplexer"
|
31
|
+
}
|
32
|
+
|
33
|
+
Multiple values can be provided via arrays:
|
34
|
+
|
35
|
+
{
|
36
|
+
email: ["joe.smith@mybrand.com", "j.smith@mybrand.com"],
|
37
|
+
phone: "61440000000",
|
38
|
+
twitter: "camplexer"
|
39
|
+
}
|
40
|
+
|
41
|
+
### Attributes:
|
42
|
+
|
43
|
+
Need to be defined by the valid namespace which should be provided
|
44
|
+
to you along with your tokens.
|
45
|
+
An attribute namespace is defined by: `com.brand.*` where `com.brand`
|
46
|
+
is defined along with your tokens and `*` can be replaced with any
|
47
|
+
`A-Za-z0-9._-` character.
|
48
|
+
|
49
|
+
Your attribute hash should reflect the following format:
|
50
|
+
|
51
|
+
{
|
52
|
+
"com.brand.email" => "joe.smith@mybrand.com",
|
53
|
+
"com.brand.phone" => "61440000000",
|
54
|
+
"com.brand.twitter" => "camplexer"
|
55
|
+
}
|
56
|
+
|
57
|
+
Permitted values include:
|
58
|
+
|
59
|
+
- String
|
60
|
+
- Numbers
|
61
|
+
- Arrays
|
62
|
+
- Simple Hashes
|
63
|
+
|
64
|
+
Attribute hashes are transported via JSON so any format supported
|
65
|
+
by JSON is supported by Lexer.
|
66
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'lexer/identity/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'lexer-identity'
|
7
|
+
s.version = Lexer::Identity::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.licenses = ['MIT']
|
10
|
+
s.authors = ['Aaron Wallis']
|
11
|
+
s.email = 'code@Lexer.io'
|
12
|
+
s.homepage = 'https://github.com/lexerdev/lexer-identity-api.gem'
|
13
|
+
s.summary = 'Lexer Identity API Client'
|
14
|
+
s.description = 'Consume and Contribute Identity data from your Ruby applications.'
|
15
|
+
|
16
|
+
s.add_dependency 'multi_json', '~> 1.3'
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split($RS).reject do |file|
|
19
|
+
file =~ %r{^(?:
|
20
|
+
spec/.*
|
21
|
+
|Gemfile
|
22
|
+
|Rakefile
|
23
|
+
|\.gitignore
|
24
|
+
|\.rubocop.yml
|
25
|
+
|\.travis.yml
|
26
|
+
)$}x
|
27
|
+
end
|
28
|
+
s.test_files = `git ls-files`.split($RS)
|
29
|
+
s.require_paths = ['lib']
|
30
|
+
end
|
data/lib/lexer.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
module Lexer
|
5
|
+
# Identity allows businesses to Contribute or Consume data from
|
6
|
+
# the Lexer Identity platform.
|
7
|
+
#
|
8
|
+
# The module acts as a light wrapper to the Identity API who's
|
9
|
+
# documentation can be found at http://lexer.io.
|
10
|
+
#
|
11
|
+
# See +Lexer::Identity.configuration+ and
|
12
|
+
# +Lexer::Identity.enrich+ for more details.
|
13
|
+
#
|
14
|
+
# To use the API you will first require API tokens which should have
|
15
|
+
# been provided to you already, or can be obtained from support@lexer.io.
|
16
|
+
#
|
17
|
+
# Basic use of the gem is as follows:
|
18
|
+
#
|
19
|
+
# Lexer::Identity.configure do |config|
|
20
|
+
# config.api_token = "..."
|
21
|
+
# config.contributor_token = "..."
|
22
|
+
# config.consumer_token = "..."
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# Lexer::Identity.enrich( links: { email: "...", ... }, attributes: { "com.mybrand.name": "...", ... } )
|
26
|
+
#
|
27
|
+
# See the +Lexer::Identity.enrich+ documentation for more details.
|
28
|
+
module Identity
|
29
|
+
# Base RuntimeError class for Identity related errors.
|
30
|
+
# Most Lexer and Identiy errors inherit this class.
|
31
|
+
class Error < RuntimeError
|
32
|
+
attr_accessor :original_error
|
33
|
+
def initialize(message, original = nil)
|
34
|
+
self.original_error = original
|
35
|
+
Lexer::Identity.logger.error("#{self}: #{message}")
|
36
|
+
super(message)
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
"Lexer Identity Exception: #{super}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Will be thrown when there is an error with the Module's configuration
|
45
|
+
class ConfigurationError < Error; end
|
46
|
+
|
47
|
+
# Will be thrown when there is an error communicating with the API
|
48
|
+
# Also inherited by other errors
|
49
|
+
class HttpError < Error; end
|
50
|
+
|
51
|
+
# Will be thrown when there is an error in the API request
|
52
|
+
class BadRequestError < HttpError; end
|
53
|
+
|
54
|
+
# Will be thrown when the tokens are invalid
|
55
|
+
class AuthenticationError < HttpError; end
|
56
|
+
|
57
|
+
# Will be thrown when the object can't be loaded from the API
|
58
|
+
class NotFoundError < HttpError; end
|
59
|
+
|
60
|
+
# inherit configuration
|
61
|
+
class << self
|
62
|
+
attr_accessor :configuration
|
63
|
+
attr_writer :logger
|
64
|
+
|
65
|
+
# Defines the modules logger
|
66
|
+
# Accessible via:
|
67
|
+
#
|
68
|
+
# Lexer::Identity.logger
|
69
|
+
#
|
70
|
+
def logger
|
71
|
+
@logger ||= lambda do
|
72
|
+
logger = Logger.new($stdout)
|
73
|
+
logger.level = Logger::INFO
|
74
|
+
logger
|
75
|
+
end.call
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Creates or uses active configutation
|
80
|
+
# See +Lexer::Identity.configuration+ for options
|
81
|
+
def self.configure
|
82
|
+
self.configuration ||= Configuration.new
|
83
|
+
yield(configuration)
|
84
|
+
|
85
|
+
self.configuration
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
require 'lexer/identity/configuration'
|
91
|
+
require 'lexer/identity/api'
|
92
|
+
require 'lexer/identity/enriched_result'
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
# :nordoc:
|
5
|
+
module Lexer
|
6
|
+
# :nordoc:
|
7
|
+
module Identity
|
8
|
+
# The backbone of the Identity API.
|
9
|
+
# Enrich accepts links and attributes as per the
|
10
|
+
# API Documentation hosted at http://developer.lexer.io/
|
11
|
+
#
|
12
|
+
# Options:
|
13
|
+
#
|
14
|
+
# +links+ - A hash of links to search for and link to the identity. Default: {}.
|
15
|
+
# +attributes+ - A hash of attributes where keys are valid namespaces. Default: {}.
|
16
|
+
#
|
17
|
+
# Response:
|
18
|
+
#
|
19
|
+
# A hash containing the Lexer Identity ID and any attributes on the identity
|
20
|
+
#
|
21
|
+
def self.enrich(links: {}, attributes: {})
|
22
|
+
# ensure the module is configured
|
23
|
+
fail Lexer::Identity::ConfigurationError, 'Module has not been configured.' if configuration.nil?
|
24
|
+
configuration.validate
|
25
|
+
|
26
|
+
# produce the request body
|
27
|
+
body = {}
|
28
|
+
body[:links] = links
|
29
|
+
body[:attributes] = attributes unless configuration.contributor_token.nil?
|
30
|
+
body[:api_token] = configuration.api_token unless configuration.api_token.nil?
|
31
|
+
body[:contributor_token] = configuration.contributor_token unless configuration.contributor_token.nil?
|
32
|
+
body[:consumer_token] = configuration.consumer_token unless configuration.consumer_token.nil?
|
33
|
+
|
34
|
+
post_request body
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def self.post_request(body)
|
40
|
+
uri = URI(configuration.api_url)
|
41
|
+
header = { 'Content-Type' => 'application/json' }
|
42
|
+
request = Net::HTTP::Post.new(uri, header)
|
43
|
+
request.body = MultiJson.encode(body)
|
44
|
+
|
45
|
+
# XXX: SSL VALIDATION IS DISABLED - BAD BAD BAD
|
46
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
|
47
|
+
http.request(request)
|
48
|
+
end
|
49
|
+
|
50
|
+
parse_response response
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.parse_response(response)
|
54
|
+
case response.code.to_i
|
55
|
+
when 200..204
|
56
|
+
Lexer::Identity::EnrichedResult.from_json response.body
|
57
|
+
when 400
|
58
|
+
fail Lexer::Identity::BadRequestError, response_body
|
59
|
+
when 401
|
60
|
+
fail Lexer::Identity::AuthenticationError, response_body
|
61
|
+
when 404
|
62
|
+
fail Lexer::Identity::NotFoundError, response_body
|
63
|
+
else
|
64
|
+
fail Lexer::Identity::HttpError, response_body
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# :nordoc:
|
4
|
+
module Lexer
|
5
|
+
# :nordoc:
|
6
|
+
module Identity
|
7
|
+
# Stores configuration details for communicating with the Lexer Identiy API.
|
8
|
+
class Configuration
|
9
|
+
# The full path to the API and endpoint
|
10
|
+
attr_accessor :api_url
|
11
|
+
|
12
|
+
# the API token provided by Lexer
|
13
|
+
attr_accessor :api_token
|
14
|
+
|
15
|
+
# the contributor token provided by Lexer
|
16
|
+
attr_accessor :contributor_token
|
17
|
+
|
18
|
+
# the consumer token provided by Lexer
|
19
|
+
attr_accessor :consumer_token
|
20
|
+
|
21
|
+
# Creates the configuration instance and defines default values
|
22
|
+
def initialize
|
23
|
+
@api_url = 'https://identity.lexer.io/identity'
|
24
|
+
@api_token = nil
|
25
|
+
@contributor_token = nil
|
26
|
+
@consumer_token = nil
|
27
|
+
end
|
28
|
+
|
29
|
+
# validates the current configuration, raising exceptions when invalid
|
30
|
+
def validate
|
31
|
+
fail Lexer::Identity::ConfigurationError, 'An API token is required' if @api_token.nil?
|
32
|
+
fail Lexer::Identity::ConfigurationError, 'A Contributor or Consumer token is required' if @contributor_token.nil? && @consumer_token.nil?
|
33
|
+
fail Lexer::Identity::ConfigurationError, 'Contributor and Consumer tokens are not interchangable' if @contributor_token == @consumer_token
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
# :nordoc:
|
5
|
+
module Lexer
|
6
|
+
# :nordoc:
|
7
|
+
module Identity
|
8
|
+
# The treturned result of an +Lexer::Identity.enrich+ request.
|
9
|
+
# Contains accessors for the returned +id+ and +attributes+.
|
10
|
+
class EnrichedResult
|
11
|
+
attr_accessor :id
|
12
|
+
attr_accessor :attributes
|
13
|
+
|
14
|
+
def initialize(args)
|
15
|
+
args.each do |k, v|
|
16
|
+
instance_variable_set("@#{k}", v) unless v.nil?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.from_json(json)
|
21
|
+
data = MultiJson.decode(json)
|
22
|
+
Lexer::Identity::EnrichedResult.new(data)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Lexer::Identity do
|
5
|
+
describe 'contributions' do
|
6
|
+
before do
|
7
|
+
Lexer::Identity.configuration = nil
|
8
|
+
Lexer::Identity.configure do |config|
|
9
|
+
config.api_token = 'abc-123'
|
10
|
+
config.contributor_token = 'bcd-234'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
it 'produces a valid request' do
|
14
|
+
stub_request(:post, 'https://identity.lexer.io/identity').
|
15
|
+
with(body: '{"links":{"email":["user1@brand.com","usera@brand.com"],"mobile":"61440000000"},"attributes":{"com.brand.car":"Tesla","com.brand.code":10,"com.brand.products":["a","b","c"],"com.brand.detail":{"make":"cake"}},"api_token":"abc-123","contributor_token":"bcd-234"}', headers: { 'Content-Type' => 'application/json' }).
|
16
|
+
to_return(status: 200, body: '{"id":"0a224111-ac64-4142-9198-adf8bf2c1a04"}')
|
17
|
+
|
18
|
+
Lexer::Identity.enrich(
|
19
|
+
links: {
|
20
|
+
email: %w(user1@brand.com usera@brand.com),
|
21
|
+
mobile: '61440000000'
|
22
|
+
}, attributes: {
|
23
|
+
'com.brand.car' => 'Tesla',
|
24
|
+
'com.brand.code' => 10,
|
25
|
+
'com.brand.products' => %w(a b c),
|
26
|
+
'com.brand.detail' => { make: 'cake' }
|
27
|
+
}
|
28
|
+
)
|
29
|
+
|
30
|
+
assert_requested(:post, 'https://identity.lexer.io/identity', times: 1)
|
31
|
+
end
|
32
|
+
it 'returns an EnrichedResult' do
|
33
|
+
stub_request(:post, 'https://identity.lexer.io/identity').
|
34
|
+
with(body: '{"links":{"email":"user1@brand.com"},"attributes":{"com.brand.car":"Tesla"},"api_token":"abc-123","contributor_token":"bcd-234"}', headers: { 'Content-Type' => 'application/json' }).
|
35
|
+
to_return(status: 200, body: '{"id":"0a224111-ac64-4142-9198-adf8bf2c1a04"}')
|
36
|
+
|
37
|
+
result = Lexer::Identity.enrich(
|
38
|
+
links: {
|
39
|
+
email: 'user1@brand.com'
|
40
|
+
}, attributes: {
|
41
|
+
'com.brand.car' => 'Tesla'
|
42
|
+
}
|
43
|
+
)
|
44
|
+
|
45
|
+
result.must_be_instance_of Lexer::Identity::EnrichedResult
|
46
|
+
result.id.must_be_kind_of String
|
47
|
+
result.attributes.must_be_nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'consumptions' do
|
52
|
+
before do
|
53
|
+
Lexer::Identity.configuration = nil
|
54
|
+
Lexer::Identity.configure do |config|
|
55
|
+
config.api_token = 'abc-123'
|
56
|
+
config.consumer_token = 'bcd-234'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
it 'produces a valid request' do
|
60
|
+
stub_request(:post, 'https://identity.lexer.io/identity').
|
61
|
+
with(body: '{"links":{"email":["user1@brand.com","usera@brand.com"],"mobile":"61440000000"},"api_token":"abc-123","consumer_token":"bcd-234"}', headers: { 'Content-Type' => 'application/json' }).
|
62
|
+
to_return(status: 200, body: '{"id":"0a224111-ac64-4142-9198-adf8bf2c1a04","attributes":{"com.brand.car":"Tesla","com.brand.code":10,"com.brand.products":["a","b","c"],"com.brand.detail":{"make":"cake"}}}')
|
63
|
+
|
64
|
+
Lexer::Identity.enrich(
|
65
|
+
links: {
|
66
|
+
email: %w(user1@brand.com usera@brand.com),
|
67
|
+
mobile: '61440000000'
|
68
|
+
}, attributes: {
|
69
|
+
'com.brand.car' => 'Tesla' # note: this will be discarded as consumers can't contribute
|
70
|
+
}
|
71
|
+
)
|
72
|
+
|
73
|
+
assert_requested(:post, 'https://identity.lexer.io/identity', times: 1)
|
74
|
+
end
|
75
|
+
it 'returns an EnrichedResult' do
|
76
|
+
stub_request(:post, 'https://identity.lexer.io/identity').
|
77
|
+
with(body: '{"links":{"email":["user1@brand.com","usera@brand.com"],"mobile":"61440000000"},"api_token":"abc-123","consumer_token":"bcd-234"}', headers: { 'Content-Type' => 'application/json' }).
|
78
|
+
to_return(status: 200, body: '{"id":"0a224111-ac64-4142-9198-adf8bf2c1a04","attributes":{"com.brand.car":"Tesla","com.brand.code":10,"com.brand.products":["a","b","c"],"com.brand.detail":{"make":"cake"}}}')
|
79
|
+
|
80
|
+
result = Lexer::Identity.enrich(
|
81
|
+
links: {
|
82
|
+
email: %w(user1@brand.com usera@brand.com),
|
83
|
+
mobile: '61440000000'
|
84
|
+
}, attributes: {
|
85
|
+
'com.brand.car' => 'Tesla' # note: this will be discarded as consumers can't contribute
|
86
|
+
}
|
87
|
+
)
|
88
|
+
|
89
|
+
result.must_be_instance_of Lexer::Identity::EnrichedResult
|
90
|
+
result.id.must_be_kind_of String
|
91
|
+
hash = { 'com.brand.car' => 'Tesla', 'com.brand.code' => 10, 'com.brand.products' => %w(a b c), 'com.brand.detail' => { 'make' => 'cake' } }
|
92
|
+
result.attributes.must_equal hash
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Lexer::Identity do
|
6
|
+
before do
|
7
|
+
Lexer::Identity.configuration = nil
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'configuration setup' do
|
11
|
+
it 'has valid defaults' do
|
12
|
+
Lexer::Identity.configure {}
|
13
|
+
|
14
|
+
config = Lexer::Identity.configuration
|
15
|
+
|
16
|
+
config.api_url.must_equal 'https://identity.lexer.io/identity'
|
17
|
+
config.api_token.must_be_nil
|
18
|
+
config.consumer_token.must_be_nil
|
19
|
+
config.contributor_token.must_be_nil
|
20
|
+
end
|
21
|
+
it 'sets configuration arguments' do
|
22
|
+
Lexer::Identity.configure do |config|
|
23
|
+
config.api_token = 'abc123'
|
24
|
+
config.consumer_token = 'abc124'
|
25
|
+
config.contributor_token = 'abc125'
|
26
|
+
end
|
27
|
+
|
28
|
+
config = Lexer::Identity.configuration
|
29
|
+
|
30
|
+
config.api_url.must_equal 'https://identity.lexer.io/identity'
|
31
|
+
config.api_token.must_equal 'abc123'
|
32
|
+
config.consumer_token.must_equal 'abc124'
|
33
|
+
config.contributor_token.must_equal 'abc125'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'configuration validation' do
|
38
|
+
it 'validates the presense of an API token' do
|
39
|
+
Lexer::Identity.configure {}
|
40
|
+
proc { Lexer::Identity.configuration.validate }.must_raise Lexer::Identity::ConfigurationError
|
41
|
+
end
|
42
|
+
it 'validates the presense of a contributor or consumer token' do
|
43
|
+
Lexer::Identity.configure do |config|
|
44
|
+
config.api_token = 'abc123'
|
45
|
+
end
|
46
|
+
proc { Lexer::Identity.configuration.validate }.must_raise Lexer::Identity::ConfigurationError
|
47
|
+
end
|
48
|
+
it 'validates the difference of a contributor or consumer token' do
|
49
|
+
Lexer::Identity.configure do |config|
|
50
|
+
config.api_token = 'abc123'
|
51
|
+
config.contributor_token = 'abc123'
|
52
|
+
config.consumer_token = 'abc123'
|
53
|
+
end
|
54
|
+
proc { Lexer::Identity.configuration.validate }.must_raise Lexer::Identity::ConfigurationError
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Lexer::Identity do
|
6
|
+
describe 'versioning' do
|
7
|
+
it 'returns a version' do
|
8
|
+
Lexer::Identity::VERSION.wont_be_nil
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'logger' do
|
13
|
+
it 'should be set to info' do
|
14
|
+
Lexer::Identity.logger.level.must_equal Logger::INFO
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'Use of Bundler is recommended'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'minitest/spec'
|
10
|
+
require 'minitest/autorun'
|
11
|
+
require 'minitest/reporters'
|
12
|
+
require 'webmock/minitest'
|
13
|
+
|
14
|
+
require File.expand_path('../../lib/lexer', __FILE__)
|
15
|
+
|
16
|
+
Minitest::Reporters.use!(
|
17
|
+
[Minitest::Reporters::SpecReporter.new],
|
18
|
+
ENV,
|
19
|
+
Minitest.backtrace_filter
|
20
|
+
)
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lexer-identity
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aaron Wallis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: multi_json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
description: Consume and Contribute Identity data from your Ruby applications.
|
28
|
+
email: code@Lexer.io
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- ".gitignore"
|
34
|
+
- ".rubocop.yml"
|
35
|
+
- ".travis.yml"
|
36
|
+
- Gemfile
|
37
|
+
- LICENSE
|
38
|
+
- README.md
|
39
|
+
- Rakefile
|
40
|
+
- lexer-identity.gemspec
|
41
|
+
- lib/lexer.rb
|
42
|
+
- lib/lexer/identity.rb
|
43
|
+
- lib/lexer/identity/api.rb
|
44
|
+
- lib/lexer/identity/configuration.rb
|
45
|
+
- lib/lexer/identity/enriched_result.rb
|
46
|
+
- lib/lexer/identity/version.rb
|
47
|
+
- spec/lexer/identity/api_spec.rb
|
48
|
+
- spec/lexer/identity/configuration_spec.rb
|
49
|
+
- spec/lexer/identity_spec.rb
|
50
|
+
- spec/spec_helper.rb
|
51
|
+
homepage: https://github.com/lexerdev/lexer-identity-api.gem
|
52
|
+
licenses:
|
53
|
+
- MIT
|
54
|
+
metadata: {}
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 2.2.2
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: Lexer Identity API Client
|
75
|
+
test_files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rubocop.yml"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- lexer-identity.gemspec
|
84
|
+
- lib/lexer.rb
|
85
|
+
- lib/lexer/identity.rb
|
86
|
+
- lib/lexer/identity/api.rb
|
87
|
+
- lib/lexer/identity/configuration.rb
|
88
|
+
- lib/lexer/identity/enriched_result.rb
|
89
|
+
- lib/lexer/identity/version.rb
|
90
|
+
- spec/lexer/identity/api_spec.rb
|
91
|
+
- spec/lexer/identity/configuration_spec.rb
|
92
|
+
- spec/lexer/identity_spec.rb
|
93
|
+
- spec/spec_helper.rb
|
94
|
+
has_rdoc:
|