stytch 0.1.20 → 2.0.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/Gemfile +4 -2
- data/README.md +1 -1
- data/Rakefile +5 -3
- data/bin/console +4 -3
- data/lib/stytch.rb +2 -0
- data/lib/stytch/client.rb +17 -48
- data/lib/stytch/magic_links.rb +117 -0
- data/lib/stytch/middleware.rb +4 -2
- data/lib/stytch/otps.rb +78 -0
- data/lib/stytch/request_helper.rb +43 -0
- data/lib/stytch/users.rb +100 -0
- data/lib/stytch/version.rb +3 -1
- data/stytch.gemspec +14 -12
- metadata +13 -11
- data/lib/stytch/endpoints/magic.rb +0 -111
- data/lib/stytch/endpoints/user.rb +0 -75
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1f99d2093072e2e5ee91b23fa745105f56a4ae2b8abcd4ce01f76048d9bec42
|
4
|
+
data.tar.gz: 718a09bc69310b8e30627ebe66cdddb49713f9101dd06cfe13746c8ad88a0ff3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a90634d8f228fd2860f3674dc7fd522d0d14cf0c36928bc547cafcba1e428597de622e503d1e1758df2fe90e62d0ca6e6fcdb8ff73232b6ce73cdd7b77565591
|
7
|
+
data.tar.gz: 48117adc597da070fdd886e3bb30e9a27820913933dfe3636b1222a698ad135837debee40c4d71d04d984075a1d324659e25e9e5b7368452add397698027e60a
|
data/Gemfile
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'stytch'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "stytch"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start(__FILE__)
|
data/lib/stytch.rb
CHANGED
data/lib/stytch/client.rb
CHANGED
@@ -1,28 +1,35 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'users'
|
4
|
+
require_relative 'magic_links'
|
5
|
+
require_relative 'otps'
|
3
6
|
|
4
7
|
module Stytch
|
5
8
|
class Client
|
6
|
-
include Stytch::Endpoints::User
|
7
|
-
include Stytch::Endpoints::Magic
|
8
|
-
|
9
9
|
ENVIRONMENTS = %i[live test].freeze
|
10
10
|
|
11
|
+
attr_reader :users, :magic_links, :otps
|
12
|
+
|
11
13
|
def initialize(env:, project_id:, secret:, &block)
|
12
14
|
@api_host = api_host(env)
|
13
|
-
@project_id
|
15
|
+
@project_id = project_id
|
14
16
|
@secret = secret
|
15
17
|
|
16
18
|
create_connection(&block)
|
19
|
+
|
20
|
+
@users = Stytch::Users.new(@connection)
|
21
|
+
@magic_links = Stytch::MagicLinks.new(@connection)
|
22
|
+
@otps = Stytch::OTPs.new(@connection)
|
17
23
|
end
|
18
24
|
|
19
25
|
private
|
20
26
|
|
21
27
|
def api_host(env)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
28
|
+
case env
|
29
|
+
when :live
|
30
|
+
'https://api.stytch.com'
|
31
|
+
when :test
|
32
|
+
'https://test.stytch.com'
|
26
33
|
else
|
27
34
|
raise ArgumentError, "Invalid value for env (#{@env}): should be live or test"
|
28
35
|
end
|
@@ -43,43 +50,5 @@ module Stytch
|
|
43
50
|
builder.response :json, content_type: /\bjson$/
|
44
51
|
builder.adapter Faraday.default_adapter
|
45
52
|
end
|
46
|
-
|
47
|
-
def get(path)
|
48
|
-
@connection.get(
|
49
|
-
path
|
50
|
-
).body
|
51
|
-
end
|
52
|
-
|
53
|
-
def post(path, payload)
|
54
|
-
@connection.post(
|
55
|
-
path,
|
56
|
-
payload
|
57
|
-
).body
|
58
|
-
end
|
59
|
-
|
60
|
-
def put(path, payload)
|
61
|
-
@connection.put(
|
62
|
-
path,
|
63
|
-
payload
|
64
|
-
).body
|
65
|
-
end
|
66
|
-
|
67
|
-
def delete(path)
|
68
|
-
@connection.delete(
|
69
|
-
path
|
70
|
-
).body
|
71
|
-
end
|
72
|
-
|
73
|
-
def request_with_query_params(path, params)
|
74
|
-
request = path
|
75
|
-
params.compact.each_with_index do |p, i|
|
76
|
-
if i == 0
|
77
|
-
request += "?#{p[0].to_s}=#{p[1]}"
|
78
|
-
else
|
79
|
-
request += "&#{p[0].to_s}=#{p[1]}"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
request
|
83
|
-
end
|
84
53
|
end
|
85
54
|
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'request_helper'
|
4
|
+
|
5
|
+
module Stytch
|
6
|
+
class MagicLinks
|
7
|
+
include Stytch::RequestHelper
|
8
|
+
|
9
|
+
attr_reader :email
|
10
|
+
|
11
|
+
PATH = '/v1/magic_links'
|
12
|
+
|
13
|
+
def initialize(connection)
|
14
|
+
@connection = connection
|
15
|
+
|
16
|
+
@email = Stytch::MagicLinks::Email.new(@connection)
|
17
|
+
end
|
18
|
+
|
19
|
+
def authenticate(
|
20
|
+
token:,
|
21
|
+
attributes: {},
|
22
|
+
options: {}
|
23
|
+
)
|
24
|
+
request = {
|
25
|
+
token: token
|
26
|
+
}
|
27
|
+
|
28
|
+
request[:attributes] = attributes if attributes != {}
|
29
|
+
request[:options] = options if options != {}
|
30
|
+
|
31
|
+
post_request("#{PATH}/authenticate", request)
|
32
|
+
end
|
33
|
+
|
34
|
+
class Email
|
35
|
+
include Stytch::RequestHelper
|
36
|
+
|
37
|
+
PATH = "#{Stytch::MagicLinks::PATH}/email"
|
38
|
+
|
39
|
+
def initialize(connection)
|
40
|
+
@connection = connection
|
41
|
+
end
|
42
|
+
|
43
|
+
def send(
|
44
|
+
email:,
|
45
|
+
login_magic_link_url:,
|
46
|
+
signup_magic_link_url:,
|
47
|
+
login_expiration_minutes: nil,
|
48
|
+
signup_expiration_minutes: nil,
|
49
|
+
attributes: {}
|
50
|
+
)
|
51
|
+
request = {
|
52
|
+
email: email,
|
53
|
+
login_magic_link_url: login_magic_link_url,
|
54
|
+
signup_magic_link_url: signup_magic_link_url
|
55
|
+
}
|
56
|
+
|
57
|
+
request[:login_expiration_minutes] = login_expiration_minutes unless login_expiration_minutes.nil?
|
58
|
+
request[:signup_expiration_minutes] = signup_expiration_minutes unless signup_expiration_minutes.nil?
|
59
|
+
request[:attributes] = attributes if attributes != {}
|
60
|
+
|
61
|
+
post_request("#{PATH}/send", request)
|
62
|
+
end
|
63
|
+
|
64
|
+
def login_or_create(
|
65
|
+
email:,
|
66
|
+
login_magic_link_url:,
|
67
|
+
signup_magic_link_url:,
|
68
|
+
login_expiration_minutes: nil,
|
69
|
+
signup_expiration_minutes: nil,
|
70
|
+
attributes: {},
|
71
|
+
create_user_as_pending: false
|
72
|
+
)
|
73
|
+
request = {
|
74
|
+
email: email,
|
75
|
+
login_magic_link_url: login_magic_link_url,
|
76
|
+
signup_magic_link_url: signup_magic_link_url,
|
77
|
+
create_user_as_pending: create_user_as_pending
|
78
|
+
}
|
79
|
+
|
80
|
+
request[:login_expiration_minutes] = login_expiration_minutes unless login_expiration_minutes.nil?
|
81
|
+
request[:signup_expiration_minutes] = signup_expiration_minutes unless signup_expiration_minutes.nil?
|
82
|
+
request[:attributes] = attributes if attributes != {}
|
83
|
+
|
84
|
+
post_request("#{PATH}/login_or_create", request)
|
85
|
+
end
|
86
|
+
|
87
|
+
def invite(
|
88
|
+
email:,
|
89
|
+
invite_magic_link_url:,
|
90
|
+
invite_expiration_minutes: nil,
|
91
|
+
attributes: {},
|
92
|
+
name: {}
|
93
|
+
)
|
94
|
+
request = {
|
95
|
+
email: email,
|
96
|
+
invite_magic_link_url: invite_magic_link_url
|
97
|
+
}
|
98
|
+
|
99
|
+
request[:invite_expiration_minutes] = invite_expiration_minutes unless invite_expiration_minutes.nil?
|
100
|
+
request[:attributes] = attributes if attributes != {}
|
101
|
+
request[:name] = name if name != {}
|
102
|
+
|
103
|
+
post_request("#{PATH}/invite", request)
|
104
|
+
end
|
105
|
+
|
106
|
+
def revoke_invite(
|
107
|
+
email:
|
108
|
+
)
|
109
|
+
request = {
|
110
|
+
email: email
|
111
|
+
}
|
112
|
+
|
113
|
+
post_request("#{PATH}/revoke_invite", request)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
data/lib/stytch/middleware.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'json'
|
2
4
|
require 'net/http'
|
3
5
|
require 'uri'
|
@@ -7,8 +9,8 @@ require_relative 'version'
|
|
7
9
|
module Stytch
|
8
10
|
class Middleware < ::Faraday::Response::Middleware
|
9
11
|
NETWORK_HEADERS = {
|
10
|
-
'User-Agent'
|
11
|
-
'Content-Type'
|
12
|
+
'User-Agent' => "Stytch Ruby v#{Stytch::VERSION}",
|
13
|
+
'Content-Type' => 'application/json'
|
12
14
|
}.freeze
|
13
15
|
|
14
16
|
NETWORK_TIMEOUT = 300
|
data/lib/stytch/otps.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'request_helper'
|
4
|
+
|
5
|
+
module Stytch
|
6
|
+
class OTPs
|
7
|
+
include Stytch::RequestHelper
|
8
|
+
|
9
|
+
attr_reader :sms
|
10
|
+
|
11
|
+
PATH = '/v1/otps'
|
12
|
+
|
13
|
+
def initialize(connection)
|
14
|
+
@connection = connection
|
15
|
+
|
16
|
+
@sms = Stytch::OTPs::SMS.new(@connection)
|
17
|
+
end
|
18
|
+
|
19
|
+
def authenticate(
|
20
|
+
method_id:,
|
21
|
+
code:,
|
22
|
+
attributes: {},
|
23
|
+
options: {}
|
24
|
+
)
|
25
|
+
request = {
|
26
|
+
method_id: method_id,
|
27
|
+
code: code
|
28
|
+
}
|
29
|
+
|
30
|
+
request[:attributes] = attributes if attributes != {}
|
31
|
+
request[:options] = options if options != {}
|
32
|
+
|
33
|
+
post_request("#{PATH}/authenticate", request)
|
34
|
+
end
|
35
|
+
|
36
|
+
class SMS
|
37
|
+
include Stytch::RequestHelper
|
38
|
+
|
39
|
+
PATH = "#{Stytch::OTPs::PATH}/sms"
|
40
|
+
|
41
|
+
def initialize(connection)
|
42
|
+
@connection = connection
|
43
|
+
end
|
44
|
+
|
45
|
+
def send(
|
46
|
+
phone_number:,
|
47
|
+
expiration_minutes: nil,
|
48
|
+
attributes: {}
|
49
|
+
)
|
50
|
+
request = {
|
51
|
+
phone_number: phone_number,
|
52
|
+
expiration_minutes: expiration_minutes
|
53
|
+
}
|
54
|
+
|
55
|
+
request[:attributes] = attributes if attributes != {}
|
56
|
+
|
57
|
+
post_request("#{PATH}/send", request)
|
58
|
+
end
|
59
|
+
|
60
|
+
def login_or_create(
|
61
|
+
phone_number:,
|
62
|
+
expiration_minutes: nil,
|
63
|
+
attributes: {},
|
64
|
+
create_user_as_pending: false
|
65
|
+
)
|
66
|
+
request = {
|
67
|
+
phone_number: phone_number,
|
68
|
+
expiration_minutes: expiration_minutes,
|
69
|
+
create_user_as_pending: create_user_as_pending
|
70
|
+
}
|
71
|
+
|
72
|
+
request[:attributes] = attributes if attributes != {}
|
73
|
+
|
74
|
+
post_request("#{PATH}/login_or_create", request)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Stytch
|
4
|
+
module RequestHelper
|
5
|
+
def get_request(path)
|
6
|
+
@connection.get(
|
7
|
+
path
|
8
|
+
).body
|
9
|
+
end
|
10
|
+
|
11
|
+
def post_request(path, payload)
|
12
|
+
@connection.post(
|
13
|
+
path,
|
14
|
+
payload
|
15
|
+
).body
|
16
|
+
end
|
17
|
+
|
18
|
+
def put_request(path, payload)
|
19
|
+
@connection.put(
|
20
|
+
path,
|
21
|
+
payload
|
22
|
+
).body
|
23
|
+
end
|
24
|
+
|
25
|
+
def delete_request(path)
|
26
|
+
@connection.delete(
|
27
|
+
path
|
28
|
+
).body
|
29
|
+
end
|
30
|
+
|
31
|
+
def request_with_query_params(path, params)
|
32
|
+
request = path
|
33
|
+
params.compact.each_with_index do |p, i|
|
34
|
+
request += if i.zero?
|
35
|
+
"?#{p[0]}=#{p[1]}"
|
36
|
+
else
|
37
|
+
"&#{p[0]}=#{p[1]}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
request
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/stytch/users.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'request_helper'
|
4
|
+
|
5
|
+
module Stytch
|
6
|
+
class Users
|
7
|
+
include Stytch::RequestHelper
|
8
|
+
|
9
|
+
PATH = '/v1/users'
|
10
|
+
|
11
|
+
def initialize(connection)
|
12
|
+
@connection = connection
|
13
|
+
end
|
14
|
+
|
15
|
+
def get(user_id:)
|
16
|
+
get_request("#{PATH}/#{user_id}")
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_pending(
|
20
|
+
limit: nil,
|
21
|
+
starting_after_id: nil
|
22
|
+
)
|
23
|
+
query_params = {
|
24
|
+
limit: limit,
|
25
|
+
starting_after_id: starting_after_id
|
26
|
+
}
|
27
|
+
|
28
|
+
request = request_with_query_params("#{PATH}/pending", query_params)
|
29
|
+
|
30
|
+
get_request(request)
|
31
|
+
end
|
32
|
+
|
33
|
+
def create(
|
34
|
+
email: nil,
|
35
|
+
phone_number: nil,
|
36
|
+
name: {},
|
37
|
+
create_user_as_pending: false,
|
38
|
+
attributes: {}
|
39
|
+
)
|
40
|
+
request = {
|
41
|
+
email: email,
|
42
|
+
phone_number: phone_number,
|
43
|
+
create_user_as_pending: create_user_as_pending
|
44
|
+
}
|
45
|
+
|
46
|
+
request[:name] = name if name != {}
|
47
|
+
request[:attributes] = attributes if attributes != {}
|
48
|
+
|
49
|
+
post_request(PATH, request)
|
50
|
+
end
|
51
|
+
|
52
|
+
def update(
|
53
|
+
user_id:,
|
54
|
+
name: {},
|
55
|
+
emails: [],
|
56
|
+
phone_numbers: [],
|
57
|
+
attributes: {}
|
58
|
+
)
|
59
|
+
request = {
|
60
|
+
emails: format_emails(emails),
|
61
|
+
phone_numbers: format_phone_numbers(phone_numbers)
|
62
|
+
}
|
63
|
+
|
64
|
+
request[:name] = name if name != {}
|
65
|
+
request[:attributes] = attributes if attributes != {}
|
66
|
+
|
67
|
+
put_request("#{PATH}/#{user_id}", request)
|
68
|
+
end
|
69
|
+
|
70
|
+
def delete(user_id:)
|
71
|
+
delete_request("#{PATH}/#{user_id}")
|
72
|
+
end
|
73
|
+
|
74
|
+
def delete_email(
|
75
|
+
email_id:
|
76
|
+
)
|
77
|
+
delete_request("#{PATH}/emails/#{email_id}")
|
78
|
+
end
|
79
|
+
|
80
|
+
def delete_phone_number(
|
81
|
+
phone_id:
|
82
|
+
)
|
83
|
+
delete_request("#{PATH}/phone_numbers/#{phone_id}")
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def format_emails(emails)
|
89
|
+
e = []
|
90
|
+
emails.each { |email| e << { email: email } }
|
91
|
+
e
|
92
|
+
end
|
93
|
+
|
94
|
+
def format_phone_numbers(phone_numbers)
|
95
|
+
p = []
|
96
|
+
phone_numbers.each { |phone_number| p << { phone_number: phone_number } }
|
97
|
+
p
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/lib/stytch/version.rb
CHANGED
data/stytch.gemspec
CHANGED
@@ -1,27 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'lib/stytch/version'
|
2
4
|
|
3
5
|
Gem::Specification.new do |spec|
|
4
|
-
spec.name =
|
6
|
+
spec.name = 'stytch'
|
5
7
|
spec.version = Stytch::VERSION
|
6
|
-
spec.authors = [
|
7
|
-
spec.email = [
|
8
|
+
spec.authors = ['stytch']
|
9
|
+
spec.email = ['support@stytch.com']
|
8
10
|
|
9
|
-
spec.summary =
|
10
|
-
spec.homepage =
|
11
|
-
spec.license =
|
12
|
-
spec.required_ruby_version = Gem::Requirement.new(
|
11
|
+
spec.summary = 'Stytch Ruby Gem'
|
12
|
+
spec.homepage = 'https://stytch.com'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
13
15
|
|
14
|
-
spec.metadata[
|
15
|
-
spec.metadata[
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = 'https://github.com/stytchauth/stytch-ruby'
|
16
18
|
|
17
19
|
# Specify which files should be added to the gem when it is released.
|
18
20
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
-
spec.files
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
20
22
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
23
|
end
|
22
|
-
spec.bindir =
|
24
|
+
spec.bindir = 'exe'
|
23
25
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
-
spec.require_paths = [
|
26
|
+
spec.require_paths = ['lib']
|
25
27
|
|
26
28
|
spec.add_dependency 'faraday', '>= 0.17.0', '< 2.0'
|
27
29
|
spec.add_dependency 'faraday_middleware', '>= 0.14.0', '< 2.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stytch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
autorequire:
|
7
|
+
- stytch
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -50,9 +50,9 @@ dependencies:
|
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '2.0'
|
53
|
-
description:
|
53
|
+
description:
|
54
54
|
email:
|
55
|
-
-
|
55
|
+
- support@stytch.com
|
56
56
|
executables: []
|
57
57
|
extensions: []
|
58
58
|
extra_rdoc_files: []
|
@@ -69,9 +69,11 @@ files:
|
|
69
69
|
- bin/setup
|
70
70
|
- lib/stytch.rb
|
71
71
|
- lib/stytch/client.rb
|
72
|
-
- lib/stytch/
|
73
|
-
- lib/stytch/endpoints/user.rb
|
72
|
+
- lib/stytch/magic_links.rb
|
74
73
|
- lib/stytch/middleware.rb
|
74
|
+
- lib/stytch/otps.rb
|
75
|
+
- lib/stytch/request_helper.rb
|
76
|
+
- lib/stytch/users.rb
|
75
77
|
- lib/stytch/version.rb
|
76
78
|
- stytch.gemspec
|
77
79
|
homepage: https://stytch.com
|
@@ -80,7 +82,7 @@ licenses:
|
|
80
82
|
metadata:
|
81
83
|
homepage_uri: https://stytch.com
|
82
84
|
source_code_uri: https://github.com/stytchauth/stytch-ruby
|
83
|
-
post_install_message:
|
85
|
+
post_install_message:
|
84
86
|
rdoc_options: []
|
85
87
|
require_paths:
|
86
88
|
- lib
|
@@ -95,8 +97,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
97
|
- !ruby/object:Gem::Version
|
96
98
|
version: '0'
|
97
99
|
requirements: []
|
98
|
-
rubygems_version: 3.
|
99
|
-
signing_key:
|
100
|
+
rubygems_version: 3.1.4
|
101
|
+
signing_key:
|
100
102
|
specification_version: 4
|
101
103
|
summary: Stytch Ruby Gem
|
102
104
|
test_files: []
|
@@ -1,111 +0,0 @@
|
|
1
|
-
module Stytch
|
2
|
-
module Endpoints
|
3
|
-
module Magic
|
4
|
-
PATH = "/v1/magic_links".freeze
|
5
|
-
|
6
|
-
def send_magic(
|
7
|
-
method_id:,
|
8
|
-
user_id:,
|
9
|
-
magic_link_url:,
|
10
|
-
expiration_minutes: nil,
|
11
|
-
attributes: {}
|
12
|
-
)
|
13
|
-
request = {
|
14
|
-
method_id: method_id,
|
15
|
-
user_id: user_id,
|
16
|
-
magic_link_url: magic_link_url,
|
17
|
-
}
|
18
|
-
|
19
|
-
request[:expiration_minutes] = expiration_minutes if expiration_minutes != nil
|
20
|
-
request[:attributes] = attributes if attributes != {}
|
21
|
-
|
22
|
-
post("#{PATH}/send", request)
|
23
|
-
end
|
24
|
-
|
25
|
-
def send_magic_by_email(
|
26
|
-
email:,
|
27
|
-
magic_link_url:,
|
28
|
-
expiration_minutes: nil,
|
29
|
-
attributes: {}
|
30
|
-
)
|
31
|
-
request = {
|
32
|
-
email: email,
|
33
|
-
magic_link_url: magic_link_url,
|
34
|
-
}
|
35
|
-
|
36
|
-
request[:expiration_minutes] = expiration_minutes if expiration_minutes != nil
|
37
|
-
request[:attributes] = attributes if attributes != {}
|
38
|
-
|
39
|
-
post("#{PATH}/send_by_email", request)
|
40
|
-
end
|
41
|
-
|
42
|
-
def login_or_create_user(
|
43
|
-
email:,
|
44
|
-
login_magic_link_url:,
|
45
|
-
signup_magic_link_url:,
|
46
|
-
login_expiration_minutes: nil,
|
47
|
-
signup_expiration_minutes: nil,
|
48
|
-
attributes: {},
|
49
|
-
create_user_as_pending: false
|
50
|
-
)
|
51
|
-
|
52
|
-
request = {
|
53
|
-
email: email,
|
54
|
-
login_magic_link_url: login_magic_link_url,
|
55
|
-
signup_magic_link_url: signup_magic_link_url,
|
56
|
-
create_user_as_pending: create_user_as_pending,
|
57
|
-
}
|
58
|
-
|
59
|
-
request[:login_expiration_minutes] = login_expiration_minutes if login_expiration_minutes != nil
|
60
|
-
request[:signup_expiration_minutes] = signup_expiration_minutes if signup_expiration_minutes != nil
|
61
|
-
request[:attributes] = attributes if attributes != {}
|
62
|
-
|
63
|
-
post("#{PATH}/login_or_create", request)
|
64
|
-
end
|
65
|
-
|
66
|
-
def invite_by_email(
|
67
|
-
email:,
|
68
|
-
magic_link_url:,
|
69
|
-
expiration_minutes: nil,
|
70
|
-
attributes: {},
|
71
|
-
name: {}
|
72
|
-
)
|
73
|
-
|
74
|
-
request = {
|
75
|
-
email: email,
|
76
|
-
magic_link_url: magic_link_url,
|
77
|
-
}
|
78
|
-
|
79
|
-
request[:expiration_minutes] = expiration_minutes if expiration_minutes != nil
|
80
|
-
request[:attributes] = attributes if attributes != {}
|
81
|
-
request[:name] = name if name != {}
|
82
|
-
|
83
|
-
post("#{PATH}/invite_by_email", request)
|
84
|
-
end
|
85
|
-
|
86
|
-
def revoke_invite_by_email(
|
87
|
-
email:
|
88
|
-
)
|
89
|
-
|
90
|
-
request = {
|
91
|
-
email: email,
|
92
|
-
}
|
93
|
-
|
94
|
-
post("#{PATH}/revoke_invite", request)
|
95
|
-
end
|
96
|
-
|
97
|
-
def authenticate_magic(
|
98
|
-
token:,
|
99
|
-
attributes: {},
|
100
|
-
options: {}
|
101
|
-
)
|
102
|
-
request = {}
|
103
|
-
|
104
|
-
request[:attributes] = attributes if attributes != {}
|
105
|
-
request[:options] = options if options != {}
|
106
|
-
|
107
|
-
post("#{PATH}/#{token}/authenticate", request)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
module Stytch
|
2
|
-
module Endpoints
|
3
|
-
module User
|
4
|
-
PATH = "/v1/users".freeze
|
5
|
-
|
6
|
-
def get_user(user_id:)
|
7
|
-
get("#{PATH}/#{user_id}")
|
8
|
-
end
|
9
|
-
|
10
|
-
def get_pending_users(
|
11
|
-
limit: nil,
|
12
|
-
starting_after_id: nil
|
13
|
-
)
|
14
|
-
query_params = {
|
15
|
-
limit: limit,
|
16
|
-
starting_after_id: starting_after_id,
|
17
|
-
}
|
18
|
-
|
19
|
-
request = request_with_query_params("#{PATH}/pending", query_params)
|
20
|
-
|
21
|
-
get(request)
|
22
|
-
end
|
23
|
-
|
24
|
-
def create_user(
|
25
|
-
email:,
|
26
|
-
name: {},
|
27
|
-
attributes: {}
|
28
|
-
)
|
29
|
-
request = {
|
30
|
-
email: email,
|
31
|
-
}
|
32
|
-
|
33
|
-
request[:name] = name if name != {}
|
34
|
-
request[:attributes] = attributes if attributes != {}
|
35
|
-
|
36
|
-
post(PATH, request)
|
37
|
-
end
|
38
|
-
|
39
|
-
def update_user(
|
40
|
-
user_id:,
|
41
|
-
name: {},
|
42
|
-
emails: [],
|
43
|
-
attributes: {}
|
44
|
-
)
|
45
|
-
request = {
|
46
|
-
emails: format_emails(emails),
|
47
|
-
}
|
48
|
-
|
49
|
-
request[:name] = name if name != {}
|
50
|
-
request[:attributes] = attributes if attributes != {}
|
51
|
-
|
52
|
-
put("#{PATH}/#{user_id}", request)
|
53
|
-
end
|
54
|
-
|
55
|
-
def delete_user(user_id:)
|
56
|
-
delete("#{PATH}/#{user_id}")
|
57
|
-
end
|
58
|
-
|
59
|
-
def delete_user_email(
|
60
|
-
user_id:,
|
61
|
-
email:
|
62
|
-
)
|
63
|
-
delete("#{PATH}/#{user_id}/emails/#{email}")
|
64
|
-
end
|
65
|
-
|
66
|
-
private
|
67
|
-
|
68
|
-
def format_emails(emails)
|
69
|
-
e = []
|
70
|
-
emails.each { |email| e << { email: email} }
|
71
|
-
e
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|