stytch 1.0.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f31f4c1727653f8dbdd402bb9e97d31ed7893f537c7f98923b3abfa6d1bbcc14
4
- data.tar.gz: a3cdadaa143fcfc4e0d72b1d0f0e35246a254ff8482c56627fa6d7cb6cb2e898
3
+ metadata.gz: e40426c4e4622ec2de65ac043377a0ce080e0fad6b93fb19f848676b32bae3d0
4
+ data.tar.gz: dc82a3b5b69da73bf40d2ff29d62c3afad63baa565fcf4ba59301b205e8dc6d8
5
5
  SHA512:
6
- metadata.gz: 56aec4b2699da311092641a43150259a8315ff6c53a460377910dddebffb8c5f02986481a8ef9b8851bb40e25dfb46805b058055bef59b68d6a1d1b688c438fc
7
- data.tar.gz: 07c8003263f90593c7c9e86920b8d866621e2890fb477e4d3b05eeb80c56b23c2cfab5913db80b76fe0b4be8d6260e26ce877f2000e8e3686515fce6a5867e5b
6
+ metadata.gz: 80b2cc7201c3f24d8486d4cbe76242b7d28f37c07a3128124e0420fd161bd62b802c875d22a1056a2743eac68c30f264a2bde070fe34876f4d722067c71705a2
7
+ data.tar.gz: d5ce170c73e22b94853395012c2245824059a7eeaf833c8dfb815e4319ae093c42383889320947921a2438541ee70900848354f43ffc9c9afe6e456116996d0f
data/CODEOWNERS ADDED
@@ -0,0 +1,7 @@
1
+ # Stytch code owners file
2
+
3
+ # These owners will be the default owners for everything in
4
+ # the repo. Unless a later match takes precedence,
5
+ # @stytchauth/client-libraries will be requested for
6
+ # review when someone opens a pull request.
7
+ * @stytchauth/client-libraries
data/CODE_OF_CONDUCT.md CHANGED
@@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
55
55
  ## Enforcement
56
56
 
57
57
  Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at alex@stytch.com. All
58
+ reported by contacting the project team at support@stytch.com. All
59
59
  complaints will be reviewed and investigated and will result in a response that
60
60
  is deemed necessary and appropriate to the circumstances. The project team is
61
61
  obligated to maintain confidentiality with regard to the reporter of an incident.
data/DEVELOPMENT.md ADDED
@@ -0,0 +1,18 @@
1
+ # Development
2
+
3
+ Thanks for contributing to Stytch's Ruby library! If you run into trouble, find us in [Slack].
4
+
5
+ ## Setup
6
+
7
+ 1. Clone this repo.
8
+ 2. To test your changes locally, update your GEMFILE with `gem 'stytch', path: '../stytch'` where `../stytch` is the path to your cloned copy of stytch-ruby.
9
+
10
+ ## Issues and Pull Requests
11
+
12
+ Please file issues in this repo. We don't have an issue template yet, but for now, say whatever you think is important!
13
+
14
+ If you have non-trivial changes you'd like us to incorporate, please open an issue first so we can discuss the changes before starting on a pull request. (It's fine to start with the PR for a typo or simple bug.) If we think the changes align with the direction of the project, we'll either ask you to open the PR or assign someone on the Stytch team to make the changes.
15
+
16
+ When you're ready for someone to look at your issue or PR, assign `@stytchauth/client-libraries` (GitHub should do this automatically). If we don't acknowledge it within one business day, please escalate it by tagging `@stytchauth/engineering` in a comment or letting us know in [Slack].
17
+
18
+ [Slack]: https://join.slack.com/t/stytch/shared_invite/zt-nil4wo92-jApJ9Cl32cJbEd9esKkvyg
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
@@ -1,8 +1,10 @@
1
- # Stytch
1
+ # Stytch Ruby Gem
2
2
 
3
- Welcome to the official Stytch ruby gem! This gem provides easy access to Stytch's API.
3
+ The Stytch Ruby gem makes it easy to use the Stytch user infrastructure API in Ruby applications.
4
4
 
5
- ## Installation
5
+ It pairs well with the Stytch [Web SDK](https://www.npmjs.com/package/@stytch/stytch-js) or your own custom authentication flow.
6
+
7
+ ## Install
6
8
 
7
9
  Add this line to your application's Gemfile:
8
10
 
@@ -20,25 +22,61 @@ Or install it yourself as:
20
22
 
21
23
  ## Usage
22
24
 
23
- To make a request, first create a Stytch Client.
24
- Set `env` to either `:test` or `:api` depending on which environment you want to use.
25
- ```
25
+ You can find your API credentials in the [Stytch Dashboard](https://stytch.com/dashboard/api-keys).
26
+
27
+ Create an API client:
28
+ ```ruby
26
29
  client = Stytch::Client.new(
27
- env: :test,
30
+ env: :test, # available environments are :test and :live
28
31
  project_id: "***",
29
32
  secret: "***"
30
33
  )
31
34
  ```
32
35
 
33
- Then make desired API call.
36
+ Send a magic link by email:
37
+ ```ruby
38
+ client.magic_links.email.login_or_create(
39
+ email: "sandbox@stytch.com",
40
+ login_magic_link_url: "https://example.com/login",
41
+ signup_magic_link_url: "https://example.com/signup",
42
+ )
34
43
  ```
35
- client.get_user(user_id: user_id)
44
+
45
+ Authenticate the token from the magic link:
46
+ ```ruby
47
+ client.magic_links.authenticate(
48
+ token: "DOYoip3rvIMMW5lgItikFK-Ak1CfMsgjuiCyI7uuU94=",
49
+ )
36
50
  ```
37
51
 
52
+ ## Handling Errors
53
+
54
+ When possible the response will contain an `error_type` and an `error_message` that can be used to distinguish errors.
55
+
56
+ Learn more about errors in the [docs](https://stytch.com/docs/api/errors).
57
+
58
+ ## Documentation
59
+
60
+ See example requests and responses for all the endpoints in the [Stytch API Reference](https://stytch.com/docs/api).
61
+
62
+ Follow one of the [integration guides](https://stytch.com/docs/guides) or start with one of our [example apps](https://stytch.com/docs/example-apps).
63
+
64
+ ## Support
65
+
66
+ If you've found a bug, [open an issue](https://github.com/stytchauth/stytch-ruby/issues/new)!
67
+
68
+ If you have questions or want help troubleshooting, join us in [Slack](https://join.slack.com/t/stytch/shared_invite/zt-nil4wo92-jApJ9Cl32cJbEd9esKkvyg) or email support@stytch.com.
69
+
70
+ If you've found a security vulnerability, please follow our [responsible disclosure instructions](https://stytch.com/docs/security).
71
+
72
+ ## Development
73
+
74
+ See [DEVELOPMENT.md](DEVELOPMENT.md)
75
+
38
76
  ## License
39
77
 
40
78
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
41
79
 
42
80
  ## Code of Conduct
43
81
 
44
- Everyone interacting in the Stytch project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/stytchauth/stytch-ruby/blob/main/CODE_OF_CONDUCT.md).
82
+ Everyone interacting in the Stytch project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).
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/client.rb CHANGED
@@ -1,30 +1,37 @@
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'
6
+ require_relative 'sessions'
4
7
 
5
8
  module Stytch
6
9
  class Client
7
- include Stytch::Endpoints::User
8
- include Stytch::Endpoints::Magic
9
- include Stytch::Endpoints::OTP
10
-
11
10
  ENVIRONMENTS = %i[live test].freeze
12
11
 
12
+ attr_reader :users, :magic_links, :otps, :sessions
13
+
13
14
  def initialize(env:, project_id:, secret:, &block)
14
15
  @api_host = api_host(env)
15
- @project_id = project_id
16
+ @project_id = project_id
16
17
  @secret = secret
17
18
 
18
19
  create_connection(&block)
20
+
21
+ @users = Stytch::Users.new(@connection)
22
+ @magic_links = Stytch::MagicLinks.new(@connection)
23
+ @otps = Stytch::OTPs.new(@connection)
24
+ @sessions = Stytch::Sessions.new(@connection)
19
25
  end
20
26
 
21
27
  private
22
28
 
23
29
  def api_host(env)
24
- if env == :live
25
- "https://api.stytch.com"
26
- elsif env == :test
27
- "https://test.stytch.com"
30
+ case env
31
+ when :live
32
+ 'https://api.stytch.com'
33
+ when :test
34
+ 'https://test.stytch.com'
28
35
  else
29
36
  raise ArgumentError, "Invalid value for env (#{@env}): should be live or test"
30
37
  end
@@ -45,43 +52,5 @@ module Stytch
45
52
  builder.response :json, content_type: /\bjson$/
46
53
  builder.adapter Faraday.default_adapter
47
54
  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
55
  end
87
56
  end
@@ -0,0 +1,121 @@
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
+ session_token: nil,
24
+ session_duration_minutes: nil
25
+ )
26
+ request = {
27
+ token: token
28
+ }
29
+
30
+ request[:attributes] = attributes if attributes != {}
31
+ request[:options] = options if options != {}
32
+ request[:session_token] = session_token unless session_token.nil?
33
+ request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
34
+
35
+ post_request("#{PATH}/authenticate", request)
36
+ end
37
+
38
+ class Email
39
+ include Stytch::RequestHelper
40
+
41
+ PATH = "#{Stytch::MagicLinks::PATH}/email"
42
+
43
+ def initialize(connection)
44
+ @connection = connection
45
+ end
46
+
47
+ def send(
48
+ email:,
49
+ login_magic_link_url:,
50
+ signup_magic_link_url:,
51
+ login_expiration_minutes: nil,
52
+ signup_expiration_minutes: nil,
53
+ attributes: {}
54
+ )
55
+ request = {
56
+ email: email,
57
+ login_magic_link_url: login_magic_link_url,
58
+ signup_magic_link_url: signup_magic_link_url
59
+ }
60
+
61
+ request[:login_expiration_minutes] = login_expiration_minutes unless login_expiration_minutes.nil?
62
+ request[:signup_expiration_minutes] = signup_expiration_minutes unless signup_expiration_minutes.nil?
63
+ request[:attributes] = attributes if attributes != {}
64
+
65
+ post_request("#{PATH}/send", request)
66
+ end
67
+
68
+ def login_or_create(
69
+ email:,
70
+ login_magic_link_url:,
71
+ signup_magic_link_url:,
72
+ login_expiration_minutes: nil,
73
+ signup_expiration_minutes: nil,
74
+ attributes: {},
75
+ create_user_as_pending: false
76
+ )
77
+ request = {
78
+ email: email,
79
+ login_magic_link_url: login_magic_link_url,
80
+ signup_magic_link_url: signup_magic_link_url,
81
+ create_user_as_pending: create_user_as_pending
82
+ }
83
+
84
+ request[:login_expiration_minutes] = login_expiration_minutes unless login_expiration_minutes.nil?
85
+ request[:signup_expiration_minutes] = signup_expiration_minutes unless signup_expiration_minutes.nil?
86
+ request[:attributes] = attributes if attributes != {}
87
+
88
+ post_request("#{PATH}/login_or_create", request)
89
+ end
90
+
91
+ def invite(
92
+ email:,
93
+ invite_magic_link_url:,
94
+ invite_expiration_minutes: nil,
95
+ attributes: {},
96
+ name: {}
97
+ )
98
+ request = {
99
+ email: email,
100
+ invite_magic_link_url: invite_magic_link_url
101
+ }
102
+
103
+ request[:invite_expiration_minutes] = invite_expiration_minutes unless invite_expiration_minutes.nil?
104
+ request[:attributes] = attributes if attributes != {}
105
+ request[:name] = name if name != {}
106
+
107
+ post_request("#{PATH}/invite", request)
108
+ end
109
+
110
+ def revoke_invite(
111
+ email:
112
+ )
113
+ request = {
114
+ email: email
115
+ }
116
+
117
+ post_request("#{PATH}/revoke_invite", request)
118
+ end
119
+ end
120
+ end
121
+ 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,125 @@
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
+ session_token: nil,
26
+ session_duration_minutes: nil
27
+ )
28
+ request = {
29
+ method_id: method_id,
30
+ code: code
31
+ }
32
+
33
+ request[:attributes] = attributes if attributes != {}
34
+ request[:options] = options if options != {}
35
+ request[:session_token] = session_token unless session_token.nil?
36
+ request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
37
+
38
+ post_request("#{PATH}/authenticate", request)
39
+ end
40
+
41
+ class SMS
42
+ include Stytch::RequestHelper
43
+
44
+ PATH = "#{Stytch::OTPs::PATH}/sms"
45
+
46
+ def initialize(connection)
47
+ @connection = connection
48
+ end
49
+
50
+ def send(
51
+ phone_number:,
52
+ expiration_minutes: nil,
53
+ attributes: {}
54
+ )
55
+ request = {
56
+ phone_number: phone_number,
57
+ expiration_minutes: expiration_minutes
58
+ }
59
+
60
+ request[:attributes] = attributes if attributes != {}
61
+
62
+ post_request("#{PATH}/send", request)
63
+ end
64
+
65
+ def login_or_create(
66
+ phone_number:,
67
+ expiration_minutes: nil,
68
+ attributes: {},
69
+ create_user_as_pending: false
70
+ )
71
+ request = {
72
+ phone_number: phone_number,
73
+ expiration_minutes: expiration_minutes,
74
+ create_user_as_pending: create_user_as_pending
75
+ }
76
+
77
+ request[:attributes] = attributes if attributes != {}
78
+
79
+ post_request("#{PATH}/login_or_create", request)
80
+ end
81
+ end
82
+
83
+ class WhatsApp
84
+ include Stytch::RequestHelper
85
+
86
+ PATH = "#{Stytch::OTPs::PATH}/whatsapp"
87
+
88
+ def initialize(connection)
89
+ @connection = connection
90
+ end
91
+
92
+ def send(
93
+ phone_number:,
94
+ expiration_minutes: nil,
95
+ attributes: {}
96
+ )
97
+ request = {
98
+ phone_number: phone_number,
99
+ expiration_minutes: expiration_minutes
100
+ }
101
+
102
+ request[:attributes] = attributes if attributes != {}
103
+
104
+ post_request("#{PATH}/send", request)
105
+ end
106
+
107
+ def login_or_create(
108
+ phone_number:,
109
+ expiration_minutes: nil,
110
+ attributes: {},
111
+ create_user_as_pending: false
112
+ )
113
+ request = {
114
+ phone_number: phone_number,
115
+ expiration_minutes: expiration_minutes,
116
+ create_user_as_pending: create_user_as_pending
117
+ }
118
+
119
+ request[:attributes] = attributes if attributes != {}
120
+
121
+ post_request("#{PATH}/login_or_create", request)
122
+ end
123
+ end
124
+ end
125
+ 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,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'request_helper'
4
+
5
+ module Stytch
6
+ class Sessions
7
+ include Stytch::RequestHelper
8
+
9
+ PATH = '/v1/sessions'
10
+
11
+ def initialize(connection)
12
+ @connection = connection
13
+ end
14
+
15
+ def get(user_id:)
16
+ query_params = {
17
+ user_id: user_id
18
+ }
19
+
20
+ request = request_with_query_params(PATH, query_params)
21
+
22
+ get_request(request)
23
+ end
24
+
25
+ def authenticate(
26
+ session_token:,
27
+ session_duration_minutes: nil
28
+ )
29
+ request = {
30
+ session_token: session_token
31
+ }
32
+
33
+ request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
34
+
35
+ post_request("#{PATH}/authenticate", request)
36
+ end
37
+
38
+ def revoke(
39
+ session_id: nil,
40
+ session_token: nil
41
+ )
42
+ request = {}
43
+
44
+ request[:session_id] = session_id unless session_id.nil?
45
+ request[:session_token] = session_token unless session_token.nil?
46
+
47
+ post_request("#{PATH}/revoke", request)
48
+ end
49
+ end
50
+ 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 = "1.0.0"
4
+ VERSION = '2.2.0'
3
5
  end
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/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: 1.0.0
4
+ version: 2.2.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-06-01 00:00:00.000000000 Z
11
+ date: 2021-08-31 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: []
@@ -60,7 +60,9 @@ files:
60
60
  - ".gitignore"
61
61
  - ".rspec"
62
62
  - ".travis.yml"
63
+ - CODEOWNERS
63
64
  - CODE_OF_CONDUCT.md
65
+ - DEVELOPMENT.md
64
66
  - Gemfile
65
67
  - LICENSE.txt
66
68
  - README.md
@@ -69,10 +71,12 @@ files:
69
71
  - bin/setup
70
72
  - lib/stytch.rb
71
73
  - lib/stytch/client.rb
72
- - lib/stytch/endpoints/magic.rb
73
- - lib/stytch/endpoints/otp.rb
74
- - lib/stytch/endpoints/user.rb
74
+ - lib/stytch/magic_links.rb
75
75
  - lib/stytch/middleware.rb
76
+ - lib/stytch/otps.rb
77
+ - lib/stytch/request_helper.rb
78
+ - lib/stytch/sessions.rb
79
+ - lib/stytch/users.rb
76
80
  - lib/stytch/version.rb
77
81
  - stytch.gemspec
78
82
  homepage: https://stytch.com
@@ -1,96 +0,0 @@
1
- module Stytch
2
- module Endpoints
3
- module Magic
4
- PATH = "/v1/magic_links".freeze
5
-
6
- def send_magic_by_email(
7
- email:,
8
- login_magic_link_url:,
9
- signup_magic_link_url:,
10
- login_expiration_minutes: nil,
11
- signup_expiration_minutes: nil,
12
- attributes: {}
13
- )
14
- request = {
15
- email: email,
16
- login_magic_link_url: login_magic_link_url,
17
- signup_magic_link_url: signup_magic_link_url,
18
- }
19
-
20
- request[:login_expiration_minutes] = login_expiration_minutes if login_expiration_minutes != nil
21
- request[:signup_expiration_minutes] = signup_expiration_minutes if signup_expiration_minutes != nil
22
- request[:attributes] = attributes if attributes != {}
23
-
24
- post("#{PATH}/send_by_email", request)
25
- end
26
-
27
- def login_or_create_user(
28
- email:,
29
- login_magic_link_url:,
30
- signup_magic_link_url:,
31
- login_expiration_minutes: nil,
32
- signup_expiration_minutes: nil,
33
- attributes: {},
34
- create_user_as_pending: false
35
- )
36
-
37
- request = {
38
- email: email,
39
- login_magic_link_url: login_magic_link_url,
40
- signup_magic_link_url: signup_magic_link_url,
41
- create_user_as_pending: create_user_as_pending,
42
- }
43
-
44
- request[:login_expiration_minutes] = login_expiration_minutes if login_expiration_minutes != nil
45
- request[:signup_expiration_minutes] = signup_expiration_minutes if signup_expiration_minutes != nil
46
- request[:attributes] = attributes if attributes != {}
47
-
48
- post("#{PATH}/login_or_create", request)
49
- end
50
-
51
- def invite_by_email(
52
- email:,
53
- invite_magic_link_url:,
54
- invite_expiration_minutes: nil,
55
- attributes: {},
56
- name: {}
57
- )
58
-
59
- request = {
60
- email: email,
61
- invite_magic_link_url: invite_magic_link_url,
62
- }
63
-
64
- request[:invite_expiration_minutes] = invite_expiration_minutes if invite_expiration_minutes != nil
65
- request[:attributes] = attributes if attributes != {}
66
- request[:name] = name if name != {}
67
-
68
- post("#{PATH}/invite_by_email", request)
69
- end
70
-
71
- def revoke_invite_by_email(
72
- email:
73
- )
74
-
75
- request = {
76
- email: email,
77
- }
78
-
79
- post("#{PATH}/revoke_invite", request)
80
- end
81
-
82
- def authenticate_magic(
83
- token:,
84
- attributes: {},
85
- options: {}
86
- )
87
- request = {}
88
-
89
- request[:attributes] = attributes if attributes != {}
90
- request[:options] = options if options != {}
91
-
92
- post("#{PATH}/#{token}/authenticate", request)
93
- end
94
- end
95
- end
96
- 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,92 +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: nil,
26
- phone_number: nil,
27
- name: {},
28
- create_user_as_pending: false,
29
- attributes: {}
30
- )
31
- request = {
32
- email: email,
33
- phone_number: phone_number,
34
- create_user_as_pending: create_user_as_pending
35
- }
36
-
37
- request[:name] = name if name != {}
38
- request[:attributes] = attributes if attributes != {}
39
-
40
- post(PATH, request)
41
- end
42
-
43
- def update_user(
44
- user_id:,
45
- name: {},
46
- emails: [],
47
- phone_numbers: [],
48
- attributes: {}
49
- )
50
- request = {
51
- emails: format_emails(emails),
52
- phone_numbers: format_phone_numbers(phone_numbers),
53
- }
54
-
55
- request[:name] = name if name != {}
56
- request[:attributes] = attributes if attributes != {}
57
-
58
- put("#{PATH}/#{user_id}", request)
59
- end
60
-
61
- def delete_user(user_id:)
62
- delete("#{PATH}/#{user_id}")
63
- end
64
-
65
- def delete_user_email(
66
- email_id:
67
- )
68
- delete("#{PATH}/emails/#{email_id}")
69
- end
70
-
71
- def delete_user_phone_number(
72
- phone_id:
73
- )
74
- delete("#{PATH}/phone_numbers/#{phone_id}")
75
- end
76
-
77
- private
78
-
79
- def format_emails(emails)
80
- e = []
81
- emails.each { |email| e << { email: email} }
82
- e
83
- end
84
-
85
- def format_phone_numbers(phone_numbers)
86
- p = []
87
- phone_numbers.each { |phone_number| p << { phone_number: phone_number} }
88
- p
89
- end
90
- end
91
- end
92
- end