cognito-client 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +2 -1
  3. data/Gemfile +37 -0
  4. data/Guardfile +4 -0
  5. data/README.md +55 -18
  6. data/Rakefile +3 -5
  7. data/bin/console +1 -1
  8. data/circle.yml +7 -0
  9. data/cognito.gemspec +4 -6
  10. data/config/devtools.yml +2 -0
  11. data/config/errors.yml +2 -0
  12. data/config/flay.yml +5 -0
  13. data/config/flog.yml +5 -0
  14. data/config/mutant.yml +6 -0
  15. data/config/reek.yml +111 -0
  16. data/config/rubocop.yml +91 -0
  17. data/config/yardstick.yml +2 -0
  18. data/lib/cognito/client.rb +59 -96
  19. data/lib/cognito/client/command.rb +34 -0
  20. data/lib/cognito/client/commands/create_identity.rb +22 -0
  21. data/lib/cognito/client/commands/create_identity_assessment.rb +26 -0
  22. data/lib/cognito/client/commands/create_identity_search.rb +37 -0
  23. data/lib/cognito/client/commands/create_profile.rb +24 -0
  24. data/lib/cognito/client/commands/mixins/create_behavior.rb +20 -0
  25. data/lib/cognito/client/commands/retrieve_identity_location.rb +28 -0
  26. data/lib/cognito/client/commands/retrieve_identity_search_job.rb +40 -0
  27. data/lib/cognito/client/connection.rb +36 -0
  28. data/lib/cognito/client/document.rb +32 -0
  29. data/lib/cognito/client/params.rb +13 -0
  30. data/lib/cognito/client/params/identity.rb +48 -0
  31. data/lib/cognito/client/params/identity_assessment.rb +23 -0
  32. data/lib/cognito/client/params/identity_search.rb +25 -0
  33. data/lib/cognito/client/params/omitted.rb +9 -0
  34. data/lib/cognito/client/request.rb +98 -0
  35. data/lib/cognito/client/resource.rb +124 -0
  36. data/lib/cognito/client/resource/identity_assessment.rb +53 -0
  37. data/lib/cognito/client/resource/identity_search.rb +64 -0
  38. data/lib/cognito/client/resource/identity_search_job.rb +12 -0
  39. data/lib/cognito/client/resource/profile.rb +10 -0
  40. data/lib/cognito/client/resource_identifier.rb +17 -0
  41. data/lib/cognito/client/response.rb +17 -0
  42. data/lib/cognito/client/response/builder.rb +48 -0
  43. data/lib/cognito/client/response/identity_assessment.rb +10 -0
  44. data/lib/cognito/client/response/identity_search.rb +32 -0
  45. data/lib/cognito/client/response/identity_search_job.rb +20 -0
  46. data/lib/cognito/client/response/profile.rb +10 -0
  47. data/lib/cognito/version.rb +3 -3
  48. metadata +77 -83
  49. data/.rubocop.yml +0 -57
  50. data/.travis.yml +0 -4
  51. data/lib/cognito.rb +0 -32
  52. data/lib/cognito/cleaner.rb +0 -30
  53. data/lib/cognito/constants.rb +0 -8
  54. data/lib/cognito/document.rb +0 -33
  55. data/lib/cognito/error.rb +0 -8
  56. data/lib/cognito/notary.rb +0 -56
  57. data/lib/cognito/resource.rb +0 -129
  58. data/lib/cognito/resource/identity_assessment.rb +0 -40
  59. data/lib/cognito/resource/identity_search.rb +0 -63
  60. data/lib/cognito/resource/identity_search_job.rb +0 -11
  61. data/lib/cognito/resource/profile.rb +0 -9
  62. data/lib/cognito/responder.rb +0 -61
@@ -1,57 +0,0 @@
1
- AllCops:
2
- TargetRubyVersion: 2.3
3
- DisplayCopNames: true
4
-
5
- # gemspec is a special snowflake
6
- LineLength:
7
- Exclude:
8
- - cognito.gemspec
9
- Max: 80
10
-
11
- ParameterLists:
12
- Max: 3
13
- CountKeywordArgs: true
14
-
15
- BlockNesting:
16
- Max: 3
17
-
18
- BlockDelimiters:
19
- EnforcedStyle: 'braces_for_chaining'
20
-
21
- CollectionMethods:
22
- Enabled: true
23
- PreferredMethods:
24
- collect: 'map'
25
- inject: 'reduce'
26
- find: 'detect'
27
- find_all: 'select'
28
-
29
- Documentation:
30
- Enabled: false
31
-
32
- # Align if/else blocks with the variable assignment
33
- EndAlignment:
34
- AlignWith: variable
35
-
36
- # Prefer #kind_of? over #is_a?
37
- ClassCheck:
38
- EnforcedStyle: kind_of?
39
-
40
- # Prefer
41
- #
42
- # some_receiver
43
- # .foo
44
- # .bar
45
- # .baz
46
- #
47
- # Over
48
- #
49
- # some_receiver.foo
50
- # .bar
51
- # .baz
52
- MultilineMethodCallIndentation:
53
- EnforcedStyle: indented
54
-
55
- # Prefer `public_send` and `__send__` over `send`
56
- Send:
57
- Enabled: true
@@ -1,4 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.3.0
4
- before_install: gem install bundler -v 1.11.2
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/setup'
4
-
5
- require 'base64'
6
- require 'digest'
7
- require 'json'
8
- require 'openssl'
9
- require 'time'
10
-
11
- require 'abstract_type'
12
- require 'adamantium'
13
- require 'anima'
14
- require 'concord'
15
- require 'httparty'
16
- require 'procto'
17
-
18
- require 'cognito/document'
19
- require 'cognito/resource'
20
- require 'cognito/resource/profile'
21
- require 'cognito/resource/identity_search'
22
- require 'cognito/resource/identity_search_job'
23
- require 'cognito/resource/identity_assessment'
24
-
25
- require 'cognito/cleaner'
26
- require 'cognito/constants'
27
- require 'cognito/error'
28
- require 'cognito/version'
29
- require 'cognito/notary'
30
-
31
- require 'cognito/responder'
32
- require 'cognito/client'
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Cognito
4
- class Cleaner
5
- attr_accessor :response
6
- attr_reader :whitelist
7
-
8
- def initialize(response, whitelist)
9
- @response = response.dup
10
- @whitelist = whitelist
11
- end
12
-
13
- def call
14
- # Only do this when we have an identity_search response.
15
- return response unless response.key?(:included)
16
-
17
- cleaned_includes = included.select do |record|
18
- whitelist.include?(record[:type])
19
- end
20
-
21
- response.tap { |r| r[:included] = cleaned_includes }
22
- end
23
-
24
- private
25
-
26
- def included
27
- response[:included]
28
- end
29
- end
30
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Cognito
4
- PROFILE = 'profile'
5
- IDENTITY_ASSESSMENT = 'identity_assessment'
6
- IDENTITY_SEARCH = 'identity_search'
7
- IDENTITY_SEARCH_JOB = 'identity_search_job'
8
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Cognito
4
- class Document
5
- include Anima.new(:data, :included), Adamantium
6
-
7
- def initialize(data:, included: [])
8
- super
9
- end
10
-
11
- def resolve(resource_object)
12
- lookup.fetch(resource_object).first
13
- end
14
-
15
- def include(resource)
16
- with(included: included + resource.included)
17
- end
18
-
19
- private
20
-
21
- def lookup
22
- resources.group_by do |resource|
23
- { type: resource.fetch(:type), id: resource.fetch(:id) }
24
- end
25
- end
26
- memoize :lookup
27
-
28
- def resources
29
- included + [data]
30
- end
31
- memoize :resources
32
- end
33
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Cognito
4
- class Error < StandardError; end
5
- class ClientError < Error; end
6
- class ResourceNotFound < ClientError; end
7
- class ServerError < Error; end
8
- end
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Cognito
4
- # Signs Cognito requests.
5
- class Notary
6
- include Anima.new(:api_key, :api_secret, :body, :target)
7
-
8
- CONTENT_TYPE = ACCEPT_TYPE = 'application/vnd.api+json'
9
- COGNITO_VERSION = '2016-09-01'
10
-
11
- def headers
12
- @headers ||= {
13
- 'Date' => date,
14
- 'Digest' => digest,
15
- 'Authorization' => authorization,
16
- 'Content-Type' => CONTENT_TYPE,
17
- 'Accept' => ACCEPT_TYPE,
18
- 'Cognito-Version' => COGNITO_VERSION
19
- }
20
- end
21
-
22
- def authorization
23
- @authorization ||= [
24
- 'Signature keyId="' + api_key + '"',
25
- 'algorithm="hmac-sha256"',
26
- 'headers="date digest (request-target)"',
27
- 'signature="' + signature + '"'
28
- ].join(',')
29
- end
30
-
31
- def digest
32
- @digest ||=
33
- "SHA-256=#{Base64.strict_encode64(Digest::SHA256.digest(body))}"
34
- end
35
-
36
- def date
37
- @date ||= Time.now.httpdate
38
- end
39
-
40
- def signature
41
- @signature ||= Base64.strict_encode64(
42
- OpenSSL::HMAC.digest(
43
- OpenSSL::Digest::SHA256.new, api_secret, signing_string
44
- )
45
- )
46
- end
47
-
48
- def signing_string
49
- @signing_string ||= [
50
- "date: #{date}",
51
- "digest: #{digest}",
52
- "(request-target): #{target}"
53
- ].join("\n")
54
- end
55
- end
56
- end
@@ -1,129 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Cognito
4
- class Resource
5
- include AbstractType,
6
- Memoizable,
7
- Anima.new(:id, :type, :attributes, :relationships, :parent)
8
-
9
- class MissingRelation < StandardError
10
- MESSAGE = "Registered relation key, '%s', not in relationships"\
11
- ' for resource: %p'
12
-
13
- def initialize(key, resource)
14
- super(format(MESSAGE, *[key, resource]))
15
- end
16
- end
17
-
18
- def self.register_type(type)
19
- REGISTRY.add(type, self)
20
- end
21
- private_class_method :register_type
22
-
23
- # ignores :reek:TooManyStatements:
24
- def self.one(key)
25
- define_relationship(key) do
26
- identifier = relationship_data(key)
27
- return unless identifier
28
-
29
- find_identifier(identifier)
30
- end
31
- end
32
- private_class_method :one
33
-
34
- def self.many(key)
35
- define_relationship(key) do
36
- relationship_data(key).map(&method(:find_identifier))
37
- end
38
- end
39
- private_class_method :many
40
-
41
- def self.attribute(key, method_name = key)
42
- define_method(method_name) do
43
- attributes[key]
44
- end
45
- end
46
-
47
- def self.define_relationship(key, &block)
48
- memoize(define_method(key, &block))
49
- end
50
- private_class_method :define_relationship
51
-
52
- def self.create(data)
53
- document = Document.new(data)
54
-
55
- build(document.data, document)
56
- end
57
-
58
- def self.build(data, parent)
59
- new(data.merge(parent: parent))
60
- end
61
-
62
- def include(resource)
63
- with(parent: parent.include(resource))
64
- end
65
-
66
- def included
67
- parent.included
68
- end
69
-
70
- def initialize(relationships: nil, **options)
71
- super
72
- end
73
-
74
- protected
75
-
76
- def resolve(identifier)
77
- parent.resolve(identifier)
78
- end
79
-
80
- private
81
-
82
- def find_identifier(identifier)
83
- resource_class = REGISTRY.lookup(identifier.fetch(:type).to_sym)
84
- resource_class.build(resolve(identifier), self)
85
- end
86
-
87
- def relationship_data(key)
88
- fail MissingRelation.new(key, self) unless relationships && relationships.key?(key)
89
-
90
- relationships.fetch(key).fetch(:data)
91
- end
92
-
93
- class Registry
94
- include Concord.new(:registry)
95
-
96
- class Error < StandardError
97
- def initialize(type)
98
- super(format(self.class::MESSAGE, type: type))
99
- end
100
- end
101
-
102
- class MissingError < Error
103
- MESSAGE = 'Resource type not registered: %<type>s'
104
- end
105
-
106
- class DuplicateTypeError < Error
107
- MESSAGE = 'Resource type already registered: %<type>s'
108
- end
109
-
110
- def initialize
111
- super({})
112
- end
113
-
114
- def lookup(type)
115
- registry.fetch(type) do
116
- fail MissingError, type
117
- end
118
- end
119
-
120
- def add(type, resource_class)
121
- fail DuplicateTypeError, type if registry.key?(type)
122
-
123
- registry[type] = resource_class
124
- end
125
- end
126
-
127
- REGISTRY = Registry.new
128
- end
129
- end
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Cognito
4
- class Resource
5
- class IdentityAssessment < self
6
- register_type :identity_assessment
7
-
8
- attribute :name
9
- attribute :phone
10
-
11
- many :identity_record_comparisons
12
- end
13
-
14
- class IdentityRecordComparison < self
15
- register_type :identity_record_comparison
16
-
17
- many :name_comparisons
18
- many :phone_comparisons
19
- one :identity_record
20
-
21
- attribute :score
22
- end
23
-
24
- class PhoneComparison < self
25
- register_type :phone_comparison
26
-
27
- attribute :score
28
-
29
- one :source_record
30
- end
31
-
32
- class NameComparison < self
33
- register_type :name_comparison
34
-
35
- attribute :score
36
-
37
- one :source_record
38
- end
39
- end
40
- end
@@ -1,63 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Cognito
4
- class Resource
5
- class IdentitySearch < self
6
- register_type :identity_search
7
-
8
- many :identity_records
9
- end
10
-
11
- class IdentityRecord < self
12
- register_type :identity_record
13
-
14
- many :addresses
15
- many :names
16
- many :ssns
17
- many :phones
18
- many :births
19
- many :deaths
20
- end
21
-
22
- class USAddress < self
23
- register_type :us_address
24
-
25
- attribute :street
26
- attribute :city
27
- attribute :subdivision
28
- attribute :postal_code
29
- end
30
-
31
- class PartialName < self
32
- register_type :name
33
-
34
- attribute :first
35
- attribute :middle
36
- attribute :last
37
- end
38
-
39
- class SSN < self
40
- register_type :ssn
41
-
42
- attribute :number
43
- end
44
-
45
- class Phone < self
46
- register_type :phone
47
- end
48
-
49
- class PartialDate < self
50
- attribute :day
51
- attribute :month
52
- attribute :year
53
- end
54
-
55
- class Birth < PartialDate
56
- register_type :birth
57
- end
58
-
59
- class Death < PartialDate
60
- register_type :death
61
- end
62
- end
63
- end