simply_auth 0.2.0 → 0.3.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 +4 -4
- data/app/models/simply_auth/model.rb +16 -16
- data/app/models/simply_auth/session.rb +4 -1
- data/app/models/simply_auth/user.rb +7 -3
- data/app/models/simply_auth/user_pool.rb +2 -1
- data/lib/simply_auth/version.rb +1 -1
- data/lib/simply_auth.rb +14 -0
- metadata +20 -7
- data/app/models/simply_auth/api_key.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19d39d6db1217f751baaf74b2fe5a026cd4640f1
|
4
|
+
data.tar.gz: 82598e3f989129584b8196b33ea9c104aa6b6d3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f7b855c948a085af251243573d7f76baf879976b1a4732236ac082a876adb94e78047f42df04743db243a56a547695e234cf11f53c27b7e971005eef3087a13
|
7
|
+
data.tar.gz: 97b8c1a65cf492d7895aa28068841ec9fd65fc1c9bfe5502decb4c4b6d20b87e0e665ee524f4c8b4e9e25cdfcfbe57b11d2b0fe8df3ea736dc0d13f73da29105
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
1
3
|
module SimplyAuth
|
2
4
|
class Model
|
3
5
|
include ActiveModel::Model
|
@@ -38,38 +40,36 @@ module SimplyAuth
|
|
38
40
|
|
39
41
|
def save
|
40
42
|
if valid?
|
41
|
-
Rails.logger.error([
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
].inspect)
|
43
|
+
# Rails.logger.error([
|
44
|
+
# persisted? ? :patch : :post,
|
45
|
+
# "https://api.simplyauth.com#{persisted? ? instance_path : collection_path}",
|
46
|
+
# {model_name.element.camelize(:lower) => attributes}.to_json,
|
47
|
+
# {accept: :json,
|
48
|
+
# content_type: :json}
|
49
|
+
# ].inspect)
|
48
50
|
response = RestClient.send(
|
49
51
|
persisted? ? :patch : :post,
|
50
52
|
"https://api.simplyauth.com#{persisted? ? instance_path : collection_path}",
|
51
|
-
attributes.to_json,
|
53
|
+
{model_name.element.camelize(:lower) => attributes}.to_json,
|
52
54
|
accept: :json,
|
53
55
|
content_type: :json
|
54
56
|
)
|
55
|
-
|
56
|
-
body = JSON.parse(response.body)
|
57
|
+
body = JSON.parse(response.body)[model_name.element.camelize(:lower)]
|
57
58
|
body = body.deep_transform_keys { |key| key.to_s.underscore }
|
58
|
-
|
59
|
-
self.attributes = body
|
59
|
+
self.attributes = self.class.new.attributes.merge(body)
|
60
60
|
changes_applied
|
61
61
|
self.persisted = true
|
62
|
-
Rails.logger.error("5")
|
63
62
|
true
|
64
63
|
else
|
65
|
-
Rails.logger.error("6")
|
66
64
|
false
|
67
65
|
end
|
68
66
|
end
|
69
67
|
|
70
68
|
def self.owner_class
|
69
|
+
@owner_class_set ||= false
|
71
70
|
return @owner_class if @owner_class_set
|
72
|
-
|
71
|
+
return nil unless self.owner_class_name
|
72
|
+
@owner_class = "SimplyAuth::#{self.owner_class_name}".constantize
|
73
73
|
@owner_class_set = true
|
74
74
|
@owner_class
|
75
75
|
end
|
@@ -125,7 +125,7 @@ module SimplyAuth
|
|
125
125
|
"https://api.simplyauth.com#{instance_path(ids)}",
|
126
126
|
accept: :json
|
127
127
|
)
|
128
|
-
body = JSON.parse(response.body)
|
128
|
+
body = JSON.parse(response.body)[model_name.element.camelize(:lower)]
|
129
129
|
body = body.deep_transform_keys { |key| key.to_s.underscore }
|
130
130
|
new(body).tap do |r|
|
131
131
|
r.persisted = true
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module SimplyAuth
|
2
2
|
class Session < Model
|
3
|
-
attr_accessor :email, :password, :user
|
3
|
+
attr_accessor :email, :password, :user, :user_pool_id
|
4
4
|
validates :email, format: /[^@]+@[^@]+/
|
5
5
|
validates :password, length: 6..72
|
6
6
|
def attributes
|
@@ -12,6 +12,9 @@ module SimplyAuth
|
|
12
12
|
def self.owner_class_name
|
13
13
|
"UserPool"
|
14
14
|
end
|
15
|
+
def owner_id
|
16
|
+
user_pool_id
|
17
|
+
end
|
15
18
|
def destroy
|
16
19
|
response = RestClient.delete(
|
17
20
|
"https://api.simplyauth.com#{instance_path}",
|
@@ -1,9 +1,13 @@
|
|
1
1
|
module SimplyAuth
|
2
2
|
class User < Model
|
3
3
|
attr_accessor :name, :email, :password, :user_pool_id
|
4
|
-
validates :name, presence: true
|
5
4
|
validates :email, format: /[^@]+@[^@]+/
|
6
|
-
validates :password, length: 6..72, if: :
|
5
|
+
validates :password, length: 6..72, if: :password_or_new_record?
|
6
|
+
|
7
|
+
def password_or_new_record?
|
8
|
+
password || !persisted?
|
9
|
+
end
|
10
|
+
|
7
11
|
def attributes
|
8
12
|
super.merge(name: name, email: email, password: password)
|
9
13
|
end
|
@@ -21,7 +25,7 @@ module SimplyAuth
|
|
21
25
|
"https://api.simplyauth.com#{collection_path(ids)}",
|
22
26
|
accept: :json
|
23
27
|
)
|
24
|
-
body = JSON.parse(response.body)
|
28
|
+
body = JSON.parse(response.body)[model_name.element.pluralize.camelize(:lower)]
|
25
29
|
body.map do |data|
|
26
30
|
data = data.deep_transform_keys { |key| key.to_s.underscore }
|
27
31
|
new(data)
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module SimplyAuth
|
2
2
|
class UserPool < Model
|
3
|
+
validates :name, presence: true
|
3
4
|
attr_accessor :name
|
4
5
|
def attributes
|
5
6
|
super.merge(name: name)
|
@@ -18,7 +19,7 @@ module SimplyAuth
|
|
18
19
|
"https://api.simplyauth.com#{collection_path}",
|
19
20
|
accept: :json
|
20
21
|
)
|
21
|
-
body = JSON.parse(response.body)
|
22
|
+
body = JSON.parse(response.body)[model_name.element.pluralize.camelize(:lower)]
|
22
23
|
body.map do |data|
|
23
24
|
data = data.deep_transform_keys { |key| key.to_s.underscore }
|
24
25
|
new(data)
|
data/lib/simply_auth/version.rb
CHANGED
data/lib/simply_auth.rb
CHANGED
@@ -1,6 +1,20 @@
|
|
1
1
|
require "simply_auth/engine"
|
2
2
|
require "simply_auth/version"
|
3
3
|
require "simply_auth/controller_helpers"
|
4
|
+
require 'rest-client'
|
5
|
+
require 'http_signatures'
|
4
6
|
|
5
7
|
module SimplyAuth
|
6
8
|
end
|
9
|
+
|
10
|
+
RestClient.add_before_execution_proc do |req, args|
|
11
|
+
if req.uri.host == "api.simplyauth.com"
|
12
|
+
req["Date"] = Time.now.rfc822
|
13
|
+
req["Content-Length"] = args[:payload] ? args[:payload].length.to_s : "0"
|
14
|
+
HttpSignatures::Context.new(
|
15
|
+
keys: {SimplyAuth::Config.api_key_id => SimplyAuth::Config.api_key_secret},
|
16
|
+
algorithm: "hmac-sha256",
|
17
|
+
headers: ["Date", "Content-Length"],
|
18
|
+
).signer.sign(req)
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simply_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Fogle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -25,17 +25,31 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rest-client
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
|
-
type: :
|
34
|
+
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: http_signatures
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
41
55
|
description:
|
@@ -57,7 +71,6 @@ files:
|
|
57
71
|
- app/helpers/simply_auth/application_helper.rb
|
58
72
|
- app/jobs/simply_auth/application_job.rb
|
59
73
|
- app/mailers/simply_auth/application_mailer.rb
|
60
|
-
- app/models/simply_auth/api_key.rb
|
61
74
|
- app/models/simply_auth/config.rb
|
62
75
|
- app/models/simply_auth/model.rb
|
63
76
|
- app/models/simply_auth/session.rb
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module SimplyAuth
|
2
|
-
class ApiKey < Model
|
3
|
-
attr_accessor :name, :id, :secret
|
4
|
-
|
5
|
-
def attributes
|
6
|
-
super.merge(name: name, id: id, secret: secret)
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.all
|
10
|
-
response = RestClient.get(
|
11
|
-
"https://api.simplyauth.com#{collection_path}",
|
12
|
-
accept: :json
|
13
|
-
)
|
14
|
-
body = JSON.parse(response.body)
|
15
|
-
body.map do |data|
|
16
|
-
data = data.deep_transform_keys { |key| key.to_s.underscore }
|
17
|
-
new(data)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def destroy
|
22
|
-
RestClient.delete(
|
23
|
-
"https://api.simplyauth.com#{instance_path}",
|
24
|
-
accept: :json
|
25
|
-
)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|