stytch 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 31244e7b0111ee9e38bc46a5fb575345e14cb4ac07f9d839776c8729d0b2f09c
4
+ data.tar.gz: 47417725b12c525e71286a92b567a5deb47fae820d2703a0ad7b6cef89eea83e
5
+ SHA512:
6
+ metadata.gz: f7410c8dc1858dbcb3dd2375074f1630bd845082f44431cdd2f55a512f0d5307d0df78b7d8feb68508f7d533fda0a866ee8e1d68e26e2a911190956d2ba2f07a
7
+ data.tar.gz: 8308b3f6b7caa3a26bf3484be4a88829a291225e79e890fdfdcaca8d1af2698ec15cdbb6628ca4b7429625d4caf059fecd466d51fb61eeee342fc9c11e761b7e
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.gem
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.2
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at alex@stytch.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in stytch.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 alex-stytch
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Stytch
2
+
3
+ Welcome to the offical Stytch ruby gem! This gem provides easy access to Stytch's API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'stytch'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install stytch
20
+
21
+ ## Usage
22
+
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
+ ```
26
+ client = Stytch::Client.new(
27
+ env: :test,
28
+ project_id: "***",
29
+ secret: "***"
30
+ )
31
+ ```
32
+
33
+ Then make desired API call.
34
+ ```
35
+ client.get_user(user_id: user_id)
36
+ ```
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
41
+
42
+ ## Code of Conduct
43
+
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/[USERNAME]/stytch/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "stytch"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,75 @@
1
+ require_relative 'endpoints/user'
2
+ require_relative 'endpoints/email'
3
+ require_relative 'endpoints/magic'
4
+
5
+ module Stytch
6
+ class Client
7
+ include Stytch::Endpoints::User
8
+ include Stytch::Endpoints::Email
9
+ include Stytch::Endpoints::Magic
10
+
11
+ ENVIRONMENTS = %i[live test].freeze
12
+
13
+ def initialize(env:, project_id:, secret:, &block)
14
+ @api_host = api_host(env)
15
+ @project_id = project_id
16
+ @secret = secret
17
+
18
+ create_connection(&block)
19
+ end
20
+
21
+ private
22
+
23
+ def api_host(env)
24
+ if env == :live
25
+ "https://api.stytch.com"
26
+ elsif env == :test
27
+ "https://test.stytch.com"
28
+ else
29
+ raise ArgumentError, "Invalid value for env (#{@env}): should be live or test"
30
+ end
31
+ end
32
+
33
+ def create_connection
34
+ @connection = Faraday.new(url: @api_host) do |builder|
35
+ block_given? ? yield(builder) : build_default_connection(builder)
36
+ end
37
+ @connection.basic_auth(@project_id, @secret)
38
+ end
39
+
40
+ def build_default_connection(builder)
41
+ builder.options[:timeout] = Stytch::Middleware::NETWORK_TIMEOUT
42
+ builder.headers = Stytch::Middleware::NETWORK_HEADERS
43
+ builder.request :json
44
+ builder.use Stytch::Middleware
45
+ builder.response :json, content_type: /\bjson$/
46
+ builder.adapter Faraday.default_adapter
47
+ 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
+ end
75
+ end
@@ -0,0 +1,30 @@
1
+ module Stytch
2
+ module Endpoints
3
+ module Email
4
+ PATH = "/v1/emails".freeze
5
+
6
+ def send_email_verification(
7
+ user_id:,
8
+ email_id:,
9
+ magic_link_url:,
10
+ expiration_minutes:
11
+ )
12
+ request = {
13
+ user_id: user_id,
14
+ magic_link_url: magic_link_url,
15
+ expiration_minutes: expiration_minutes
16
+ }
17
+
18
+ post("#{PATH}/#{email_id}/send_verification", request)
19
+ end
20
+
21
+ def verify_email(token:)
22
+ post("#{PATH}/#{token}/verify", {})
23
+ end
24
+
25
+ def delete_email(user_id:, email_id:)
26
+ delete("#{PATH}/#{email_id}/users/#{user_id}")
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,58 @@
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:,
11
+ template_id: nil,
12
+ attributes: {}
13
+ )
14
+ request = {
15
+ method_id: method_id,
16
+ user_id: user_id,
17
+ magic_link_url: magic_link_url,
18
+ expiration_minutes: expiration_minutes,
19
+ template_id: template_id,
20
+ attributes: attributes
21
+ }
22
+
23
+ post("#{PATH}/send", request)
24
+ end
25
+
26
+ def send_magic_by_email(
27
+ email:,
28
+ magic_link_url:,
29
+ expiration_minutes:,
30
+ template_id: nil,
31
+ attributes: {}
32
+ )
33
+ request = {
34
+ email: email,
35
+ magic_link_url: magic_link_url,
36
+ expiration_minutes: expiration_minutes,
37
+ template_id: template_id,
38
+ attributes: attributes
39
+ }
40
+
41
+ post("#{PATH}/send_by_email", request)
42
+ end
43
+
44
+ def authenticate_magic(
45
+ token:,
46
+ attributes: {},
47
+ options:{}
48
+ )
49
+ request = {
50
+ attributes: attributes,
51
+ options: options
52
+ }
53
+
54
+ post("#{PATH}/#{token}/authenticate", request)
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,52 @@
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 create_user(
11
+ email:,
12
+ name: {},
13
+ attributes: {}
14
+ )
15
+ request = {
16
+ email: email,
17
+ name: name,
18
+ attributes: attributes,
19
+ }
20
+
21
+ post(PATH, request)
22
+ end
23
+
24
+ def update_user(
25
+ user_id:,
26
+ name: nil,
27
+ emails: [],
28
+ attributes: {}
29
+ )
30
+ request = {
31
+ name: name,
32
+ emails: format_emails(emails),
33
+ attributes: attributes,
34
+ }
35
+
36
+ put("#{PATH}/#{user_id}", request)
37
+ end
38
+
39
+ def delete_user(user_id:)
40
+ delete("#{PATH}/#{user_id}")
41
+ end
42
+
43
+ private
44
+
45
+ def format_emails(emails)
46
+ e = []
47
+ emails.each { |email| e << { email: email} }
48
+ e
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,16 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'uri'
4
+
5
+ require_relative 'version'
6
+
7
+ module Stytch
8
+ class Middleware < ::Faraday::Response::Middleware
9
+ NETWORK_HEADERS = {
10
+ 'User-Agent' => "Stytch Ruby v#{Stytch::VERSION}",
11
+ 'Content-Type' => 'application/json',
12
+ }.freeze
13
+
14
+ NETWORK_TIMEOUT = 300
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Stytch
2
+ VERSION = "0.1.5"
3
+ end
data/lib/stytch.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+
4
+ require_relative 'stytch/client'
5
+ require_relative 'stytch/middleware'
6
+ require_relative 'stytch/version'
7
+
8
+ module Stytch end
data/stytch.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ require_relative 'lib/stytch/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "stytch"
5
+ spec.version = Stytch::VERSION
6
+ spec.authors = ["alex-stytch"]
7
+ spec.email = ["alex@stytch.com"]
8
+
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")
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = "https://github.com/stytchauth/stytch-ruby"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # 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
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_dependency 'faraday', '~> 1.1.0'
27
+ spec.add_dependency 'faraday_middleware', '~> 1.0.0'
28
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stytch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ platform: ruby
6
+ authors:
7
+ - alex-stytch
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-11-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.0
41
+ description:
42
+ email:
43
+ - alex@stytch.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".travis.yml"
51
+ - CODE_OF_CONDUCT.md
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - bin/console
57
+ - bin/setup
58
+ - lib/stytch.rb
59
+ - lib/stytch/client.rb
60
+ - lib/stytch/endpoints/email.rb
61
+ - lib/stytch/endpoints/magic.rb
62
+ - lib/stytch/endpoints/user.rb
63
+ - lib/stytch/middleware.rb
64
+ - lib/stytch/version.rb
65
+ - stytch.gemspec
66
+ homepage: https://stytch.com
67
+ licenses:
68
+ - MIT
69
+ metadata:
70
+ homepage_uri: https://stytch.com
71
+ source_code_uri: https://github.com/stytchauth/stytch-ruby
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 2.3.0
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubygems_version: 3.1.4
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Stytch Ruby Gem
91
+ test_files: []