stytch 0.1.21 → 2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f7f81b30c19471d94ea6c9c3dac52b2e50485bedd40429b66e395dd272aa2ee
4
- data.tar.gz: 49ea0b78ec5b829011f2d3b2519b5d8abb1327d913ec7eb9bc678edd7bbe1976
3
+ metadata.gz: e297565a826ab7318a1471d3b4286bba6d8a58c1f335bb5fe39b31355dad8bb0
4
+ data.tar.gz: 6d5873eed220a0d85539b0264408757451ce18e106dd58cf5b747543697808cc
5
5
  SHA512:
6
- metadata.gz: 510b3a0466324f2349198f92ebb316e851d059f57f28ea2f349ac72d49b3ba01d721362cd613236b792472ade599bc6b2773d3f5c77f1e6844095a7d846bb3b8
7
- data.tar.gz: a260451b3ed384fcec781780bde436699ac4ebb2ea24d8bc55f594cf1bb8982583f22d58dc5fe4dcdf9de6da7adfbb333f4c989f4ed5d0b75dc6c1dca2486df7
6
+ metadata.gz: bcec30dcf3b4e89293bb41f05202aca38b6b46d2a42531d9cae2471a1b6c8a7052bca1aa962a4017a2486b92a0f1c24b7634c59c3ed8725f3763d17a6162cef7
7
+ data.tar.gz: 36d398ca7e3a987cb94efa45875d17473dfdd348266474e9c2f29ec6a1491a0bf001a1960f9ed712f946904daf0265f79e851689a7ff9cb9cf6e546d843d64af
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in stytch.gemspec
4
- gemspec
6
+ gemspec
data/README.md CHANGED
@@ -32,7 +32,7 @@ client = Stytch::Client.new(
32
32
 
33
33
  Then make desired API call.
34
34
  ```
35
- client.get_user(user_id: user_id)
35
+ client.users.get(user_id: user_id)
36
36
  ```
37
37
 
38
38
  ## License
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "stytch"
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 "irb"
14
+ require 'irb'
14
15
  IRB.start(__FILE__)
data/lib/stytch.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'faraday'
2
4
  require 'faraday_middleware'
3
5
 
data/lib/stytch/client.rb CHANGED
@@ -1,30 +1,35 @@
1
- require_relative 'endpoints/user'
2
- require_relative 'endpoints/magic'
3
- require_relative 'endpoints/otp'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'users'
4
+ require_relative 'magic_links'
5
+ require_relative 'otps'
4
6
 
5
7
  module Stytch
6
8
  class Client
7
- include Stytch::Endpoints::User
8
- include Stytch::Endpoints::Magic
9
- include Stytch::Endpoints::OTP
10
-
11
9
  ENVIRONMENTS = %i[live test].freeze
12
10
 
11
+ attr_reader :users, :magic_links, :otps
12
+
13
13
  def initialize(env:, project_id:, secret:, &block)
14
14
  @api_host = api_host(env)
15
- @project_id = project_id
15
+ @project_id = project_id
16
16
  @secret = secret
17
17
 
18
18
  create_connection(&block)
19
+
20
+ @users = Stytch::Users.new(@connection)
21
+ @magic_links = Stytch::MagicLinks.new(@connection)
22
+ @otps = Stytch::OTPs.new(@connection)
19
23
  end
20
24
 
21
25
  private
22
26
 
23
27
  def api_host(env)
24
- if env == :live
25
- "https://api.stytch.com"
26
- elsif env == :test
27
- "https://test.stytch.com"
28
+ case env
29
+ when :live
30
+ 'https://api.stytch.com'
31
+ when :test
32
+ 'https://test.stytch.com'
28
33
  else
29
34
  raise ArgumentError, "Invalid value for env (#{@env}): should be live or test"
30
35
  end
@@ -45,43 +50,5 @@ module Stytch
45
50
  builder.response :json, content_type: /\bjson$/
46
51
  builder.adapter Faraday.default_adapter
47
52
  end
48
-
49
- def get(path)
50
- @connection.get(
51
- path
52
- ).body
53
- end
54
-
55
- def post(path, payload)
56
- @connection.post(
57
- path,
58
- payload
59
- ).body
60
- end
61
-
62
- def put(path, payload)
63
- @connection.put(
64
- path,
65
- payload
66
- ).body
67
- end
68
-
69
- def delete(path)
70
- @connection.delete(
71
- path
72
- ).body
73
- end
74
-
75
- def request_with_query_params(path, params)
76
- request = path
77
- params.compact.each_with_index do |p, i|
78
- if i == 0
79
- request += "?#{p[0].to_s}=#{p[1]}"
80
- else
81
- request += "&#{p[0].to_s}=#{p[1]}"
82
- end
83
- end
84
- request
85
- end
86
53
  end
87
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
@@ -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' => "Stytch Ruby v#{Stytch::VERSION}",
11
- 'Content-Type' => 'application/json',
12
+ 'User-Agent' => "Stytch Ruby v#{Stytch::VERSION}",
13
+ 'Content-Type' => 'application/json'
12
14
  }.freeze
13
15
 
14
16
  NETWORK_TIMEOUT = 300
@@ -0,0 +1,121 @@
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, :whatsapp
10
+
11
+ PATH = '/v1/otps'
12
+
13
+ def initialize(connection)
14
+ @connection = connection
15
+
16
+ @sms = Stytch::OTPs::SMS.new(@connection)
17
+ @whatsapp = Stytch::OTPs::WhatsApp.new(@connection)
18
+ end
19
+
20
+ def authenticate(
21
+ method_id:,
22
+ code:,
23
+ attributes: {},
24
+ options: {}
25
+ )
26
+ request = {
27
+ method_id: method_id,
28
+ code: code
29
+ }
30
+
31
+ request[:attributes] = attributes if attributes != {}
32
+ request[:options] = options if options != {}
33
+
34
+ post_request("#{PATH}/authenticate", request)
35
+ end
36
+
37
+ class SMS
38
+ include Stytch::RequestHelper
39
+
40
+ PATH = "#{Stytch::OTPs::PATH}/sms"
41
+
42
+ def initialize(connection)
43
+ @connection = connection
44
+ end
45
+
46
+ def send(
47
+ phone_number:,
48
+ expiration_minutes: nil,
49
+ attributes: {}
50
+ )
51
+ request = {
52
+ phone_number: phone_number,
53
+ expiration_minutes: expiration_minutes
54
+ }
55
+
56
+ request[:attributes] = attributes if attributes != {}
57
+
58
+ post_request("#{PATH}/send", request)
59
+ end
60
+
61
+ def login_or_create(
62
+ phone_number:,
63
+ expiration_minutes: nil,
64
+ attributes: {},
65
+ create_user_as_pending: false
66
+ )
67
+ request = {
68
+ phone_number: phone_number,
69
+ expiration_minutes: expiration_minutes,
70
+ create_user_as_pending: create_user_as_pending
71
+ }
72
+
73
+ request[:attributes] = attributes if attributes != {}
74
+
75
+ post_request("#{PATH}/login_or_create", request)
76
+ end
77
+ end
78
+
79
+ class WhatsApp
80
+ include Stytch::RequestHelper
81
+
82
+ PATH = "#{Stytch::OTPs::PATH}/whatsapp"
83
+
84
+ def initialize(connection)
85
+ @connection = connection
86
+ end
87
+
88
+ def send(
89
+ phone_number:,
90
+ expiration_minutes: nil,
91
+ attributes: {}
92
+ )
93
+ request = {
94
+ phone_number: phone_number,
95
+ expiration_minutes: expiration_minutes
96
+ }
97
+
98
+ request[:attributes] = attributes if attributes != {}
99
+
100
+ post_request("#{PATH}/send", request)
101
+ end
102
+
103
+ def login_or_create(
104
+ phone_number:,
105
+ expiration_minutes: nil,
106
+ attributes: {},
107
+ create_user_as_pending: false
108
+ )
109
+ request = {
110
+ phone_number: phone_number,
111
+ expiration_minutes: expiration_minutes,
112
+ create_user_as_pending: create_user_as_pending
113
+ }
114
+
115
+ request[:attributes] = attributes if attributes != {}
116
+
117
+ post_request("#{PATH}/login_or_create", request)
118
+ end
119
+ end
120
+ end
121
+ 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
@@ -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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Stytch
2
- VERSION = "0.1.21"
4
+ VERSION = '2.1.0'
3
5
  end
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 = "stytch"
6
+ spec.name = 'stytch'
5
7
  spec.version = Stytch::VERSION
6
- spec.authors = ["alex-stytch"]
7
- spec.email = ["alex@stytch.com"]
8
+ spec.authors = ['stytch']
9
+ spec.email = ['support@stytch.com']
8
10
 
9
- spec.summary = "Stytch Ruby Gem"
10
- spec.homepage = "https://stytch.com"
11
- spec.license = "MIT"
12
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
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["homepage_uri"] = spec.homepage
15
- spec.metadata["source_code_uri"] = "https://github.com/stytchauth/stytch-ruby"
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 = Dir.chdir(File.expand_path('..', __FILE__)) do
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 = "exe"
24
+ spec.bindir = 'exe'
23
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
- spec.require_paths = ["lib"]
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.1.21
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
- - alex-stytch
7
+ - stytch
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-04 00:00:00.000000000 Z
11
+ date: 2021-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -52,7 +52,7 @@ dependencies:
52
52
  version: '2.0'
53
53
  description:
54
54
  email:
55
- - alex@stytch.com
55
+ - support@stytch.com
56
56
  executables: []
57
57
  extensions: []
58
58
  extra_rdoc_files: []
@@ -69,10 +69,11 @@ files:
69
69
  - bin/setup
70
70
  - lib/stytch.rb
71
71
  - lib/stytch/client.rb
72
- - lib/stytch/endpoints/magic.rb
73
- - lib/stytch/endpoints/otp.rb
74
- - lib/stytch/endpoints/user.rb
72
+ - lib/stytch/magic_links.rb
75
73
  - lib/stytch/middleware.rb
74
+ - lib/stytch/otps.rb
75
+ - lib/stytch/request_helper.rb
76
+ - lib/stytch/users.rb
76
77
  - lib/stytch/version.rb
77
78
  - stytch.gemspec
78
79
  homepage: https://stytch.com
@@ -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,56 +0,0 @@
1
- module Stytch
2
- module Endpoints
3
- module OTP
4
- PATH = "/v1/otp".freeze
5
-
6
- def send_otp_by_sms(
7
- phone_number:,
8
- expiration_minutes: nil,
9
- attributes: {}
10
- )
11
- request = {
12
- phone_number: phone_number,
13
- expiration_minutes: expiration_minutes,
14
- }
15
-
16
- request[:attributes] = attributes if attributes != {}
17
-
18
- post("#{PATH}/send_by_sms", request)
19
- end
20
-
21
- def login_or_create_user_by_sms(
22
- phone_number:,
23
- expiration_minutes: nil,
24
- attributes: {},
25
- create_user_as_pending: false
26
- )
27
- request = {
28
- phone_number: phone_number,
29
- expiration_minutes: expiration_minutes,
30
- create_user_as_pending: create_user_as_pending
31
- }
32
-
33
- request[:attributes] = attributes if attributes != {}
34
-
35
- post("#{PATH}/login_or_create", request)
36
- end
37
-
38
- def authenticate_otp(
39
- method_id:,
40
- code:,
41
- attributes: {},
42
- options: {}
43
- )
44
- request = {
45
- method_id: method_id,
46
- code: code,
47
- }
48
-
49
- request[:attributes] = attributes if attributes != {}
50
- request[:options] = options if options != {}
51
-
52
- post("#{PATH}/authenticate", request)
53
- end
54
- end
55
- end
56
- end
@@ -1,91 +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
- phone_number: nil,
27
- name: {},
28
- attributes: {}
29
- )
30
- request = {
31
- email: email,
32
- phone_number: phone_number
33
- }
34
-
35
- request[:name] = name if name != {}
36
- request[:attributes] = attributes if attributes != {}
37
-
38
- post(PATH, request)
39
- end
40
-
41
- def update_user(
42
- user_id:,
43
- name: {},
44
- emails: [],
45
- phone_numbers: [],
46
- attributes: {}
47
- )
48
- request = {
49
- emails: format_emails(emails),
50
- phone_numbers: format_phone_numbers(phone_numbers),
51
- }
52
-
53
- request[:name] = name if name != {}
54
- request[:attributes] = attributes if attributes != {}
55
-
56
- put("#{PATH}/#{user_id}", request)
57
- end
58
-
59
- def delete_user(user_id:)
60
- delete("#{PATH}/#{user_id}")
61
- end
62
-
63
- def delete_user_email(
64
- user_id:,
65
- email:
66
- )
67
- delete("#{PATH}/#{user_id}/emails/#{email}")
68
- end
69
-
70
- def delete_user_phone_number(
71
- phone_id:
72
- )
73
- delete("#{PATH}/phone_numbers/#{phone_id}")
74
- end
75
-
76
- private
77
-
78
- def format_emails(emails)
79
- e = []
80
- emails.each { |email| e << { email: email} }
81
- e
82
- end
83
-
84
- def format_phone_numbers(phone_numbers)
85
- p = []
86
- phone_numbers.each { |phone_number| p << { phone_number: phone_number} }
87
- p
88
- end
89
- end
90
- end
91
- end