streambird 1.0.1

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: dc7c798a9d73a5e3c7d2c76bfb2c06a49ed96a5c57999c3a1d15769024b5457d
4
+ data.tar.gz: 8ba83f95ae432d0be726b67c19629dd04505f7714ceb64f19439ff097f9f4855
5
+ SHA512:
6
+ metadata.gz: f2c7f1865c6093960cada4050eb708fffbd73c07e74979df6f1911a692737f62fbb9f8e6d88f8fd8f847896d563989d351ee9d6a74a2adeddd981cbbd0fbd13f
7
+ data.tar.gz: bfc73850bd1d4eccba28a21c1039d143d28ce78621aab02964a8019d1519d75a6cdec0d07fdaa761ba75141eeb5e9a9b881a9bf0350b5d90c63e219010dc79cb
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ - 2.5.0
5
+ notifications:
6
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in streambird-ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Streambird, Inc.
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,61 @@
1
+ # Streambird
2
+
3
+ This is the official Streambird RubyGem (`streambird`).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'streambird'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install streambird
20
+
21
+ ## Usage
22
+
23
+ First, initialize the Streambird client:
24
+
25
+ ```ruby
26
+ require 'streambird'
27
+
28
+ streambird = Streambird.new(api_key: 'API_KEY')
29
+ ```
30
+
31
+ ## Errors
32
+
33
+ This gem will raise exceptions on application-level errors. Here are the list of errors:
34
+
35
+ ```ruby
36
+ Streambird::Api::BadRequest
37
+ Streambird::Api::TooManyRequests
38
+ Streambird::Api::NotFound
39
+ Streambird::Api::Unauthorized
40
+ Streambird::Api::InternalServerError
41
+ Streambird::Api::ConnectionError
42
+ Streambird::Api::APIKeyInvalid
43
+ ```
44
+
45
+ ## Development
46
+
47
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
48
+
49
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `streambird-ruby.gemspec`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
50
+
51
+ To test locally, run `bundle exec rspec`. By default, client - server communication is mocked by [vcr](https://github.com/vcr/vcr), which uses local [casettes](spec/cassettes) recorded from production server.
52
+ To test against production server, set a test api key as `STREAMBIRD_TEST_API_KEY` and run `bundle exec rake spec:production`, which sets environment variable `STREAMBIRD_TEST_SERVER` to `production`. It will also update new client - server communication in the cassette.
53
+ Please note that changes in the cassettes will break existing specs. This is because 1) the server may return random results for test api key, and 2) some of the cassettes have been modified specifically for the specs.
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/streambird/streambird-ruby.
58
+
59
+ ## License
60
+
61
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ import './tasks/spec_production.rake'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "streambird"
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
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,46 @@
1
+ class Streambird
2
+ class Api
3
+ class Error < StandardError
4
+ attr_accessor :status_code
5
+
6
+ def initialize(message = 'Please double check the request was properly formed and try again', status_code = 400)
7
+ super(message)
8
+ self.status_code = status_code
9
+ end
10
+ end
11
+
12
+ class BadRequest < Error
13
+ end
14
+
15
+ class TooManyRequests < Error
16
+ end
17
+
18
+ class NotFound < Error
19
+ end
20
+
21
+ class Unauthorized < Error
22
+ def initialize(message = "Please ensure that the api_key provided is correct. To find your API key, go to your Streambird Dashboard", status_code = 401)
23
+ super(message, status_code)
24
+ end
25
+ end
26
+
27
+ class InternalServerError < Error
28
+ def initialize(message = "Streambird's servers are currently experiencing issues. Please wait a moment and try again.", status_code = 500)
29
+ super(message, status_code)
30
+ end
31
+ end
32
+
33
+ class ConnectionError < Error
34
+ def initialize(message = "There's an issue connecting to Streambird's servers. Please check you're connected to the internet, and try again.'", status_code = nil)
35
+ super(message, status_code)
36
+ end
37
+ end
38
+
39
+ class APIKeyInvalid < Error
40
+ def initialize(message = "Provided api_key is invalid. Please double check you passed it in correctly and try again. If you're having trouble finding it, check your Streambird Dashboard", status_code = nil)
41
+ super(message, status_code)
42
+ end
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,47 @@
1
+ class Streambird
2
+ class Api
3
+ class MagicLinks < Struct.new(:client)
4
+
5
+ def email
6
+ @email ||= Streambird::Api::MagicLinks::Email.new(client)
7
+ end
8
+
9
+ def create(user_id:)
10
+ req = {
11
+ 'user_id': user_id,
12
+ }
13
+ response = client.post('auth/magic_links/create', req)
14
+ json_body = JSON.parse(response.body, symbolize_names: true)
15
+ return json_body
16
+ end
17
+
18
+ class Email < Struct.new(:client)
19
+
20
+ def login_or_create(email:,
21
+ login_redirect_url: nil,
22
+ registration_redirect_url: nil,
23
+ login_expires_in: nil,
24
+ registration_expires_in: nil,
25
+ requires_verification: nil,
26
+ device_fingerprint: {}
27
+ )
28
+
29
+ req = {
30
+ 'email': email,
31
+ }
32
+
33
+ req['login_redirect_url'] = login_redirect_url if !login_redirect_url.nil?
34
+ req['registration_redirect_url'] = registration_redirect_url if !registration_redirect_url.nil?
35
+ req['registration_expires_in'] = registration_expires_in if !registration_expires_in.nil?
36
+ req['login_expires_in'] = login_expires_in if !login_expires_in.nil?
37
+ req['requires_verification'] = requires_verification if !requires_verification.nil?
38
+ req['device_fingerprint'] = device_fingerprint if device_fingerprint != {}
39
+ response = client.post('auth/magic_links/email/login_or_create', req)
40
+
41
+ json_body = JSON.parse(response.body, symbolize_names: true)
42
+ return json_body
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,77 @@
1
+ require 'uri'
2
+ require 'faraday'
3
+ require 'json'
4
+
5
+ class Streambird
6
+ class Api < Struct.new(:api_key, :default_request_params, :logging)
7
+ STREAMBIRD_API_URL = 'http://localhost:11019/v1/'
8
+ STREAMBIRD_GEM_INFO = Gem.loaded_specs["streambird"]
9
+ STREAMBIRD_RUBY_CLIENT_VERSION = STREAMBIRD_GEM_INFO ? STREAMBIRD_GEM_INFO.version.to_s : '0.1.1'.freeze
10
+
11
+ def connection
12
+ @connection ||= Faraday.new(:url => STREAMBIRD_API_URL) do |faraday|
13
+ faraday.request :authorization, 'Bearer', self.api_key
14
+ faraday.request :url_encoded # form-encode POST params
15
+ faraday.response :logger if logging # log requests to STDOUT
16
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
17
+ end
18
+ end
19
+
20
+ def get(url, params = {})
21
+ response = connection.get do |req|
22
+ req.url "#{STREAMBIRD_API_URL}#{url}"
23
+ req.params.merge!(default_request_params.merge(params))
24
+ req.headers['X-API-Client'] = "Ruby"
25
+ req.headers["X-API-Client-Version"] = STREAMBIRD_RUBY_CLIENT_VERSION
26
+ end
27
+
28
+ if response.status != 200
29
+ return handle_error(response)
30
+ end
31
+
32
+ response
33
+ rescue Faraday::Error::ConnectionFailed
34
+ raise Streambird::Api::ConnectionError
35
+ end
36
+
37
+ def post(url, body = {})
38
+
39
+ body = default_request_params.merge(body)
40
+ response = connection.post do |req|
41
+ req.url "#{STREAMBIRD_API_URL}#{url}"
42
+ req.headers['Content-Type'] = 'application/json'
43
+ req.body = body.to_json
44
+ req.headers['X-API-Client'] = "Ruby"
45
+ req.headers["X-API-Client-Version"] = STREAMBIRD_RUBY_CLIENT_VERSION
46
+ end
47
+
48
+ if response.status != 200 and response.status != 201
49
+ return handle_error(response)
50
+ end
51
+
52
+ response
53
+ rescue Faraday::Error::ConnectionFailed
54
+ raise Streambird::Api::ConnectionError
55
+ end
56
+
57
+ def handle_error(response)
58
+ error_body = JSON.parse(response.body)
59
+ if response.status == 404
60
+ raise Streambird::Api::NotFound.new(error_body['error_message'], response.status)
61
+ elsif response.status == 429
62
+ raise Streambird::Api::TooManyRequests.new(error_body['error_message'], response.status)
63
+ elsif response.status > 499
64
+ raise Streambird::Api::InternalServerError.new(error_body['error_message'], response.status)
65
+ elsif response.status == 401
66
+ raise Streambird::Api::Unauthorized.new(error_body['error_message'], response.status)
67
+ else
68
+ raise Streambird::Api::BadRequest.new(error_body['error_message'], response.status)
69
+ end
70
+ rescue JSON::ParserError
71
+ raise Streambird::Api::InternalServerError
72
+ end
73
+ end
74
+ end
75
+
76
+ require 'streambird/api/errors'
77
+
data/lib/streambird.rb ADDED
@@ -0,0 +1,43 @@
1
+ class Streambird
2
+ attr_accessor :api_key, :default_request_params, :logging
3
+
4
+ def self.validate_api_key(api_key)
5
+ if api_key.length < 5 || !(api_key.start_with?('sk_live') || api_key.start_with?('sk_test'))
6
+ raise Api::APIKeyInvalid
7
+ end
8
+ end
9
+
10
+ def initialize(api_key: nil, default_request_params: {}, logging: false)
11
+ Streambird.validate_api_key(api_key)
12
+
13
+ self.api_key = api_key
14
+ self.default_request_params = default_request_params
15
+ self.logging = logging
16
+ end
17
+
18
+ def live?
19
+ api_key.start_with?('sk_live')
20
+ end
21
+
22
+ def test?
23
+ api_key.start_with?('sk_test')
24
+ end
25
+
26
+ def client
27
+ puts default_request_params
28
+ @client ||= Api.new(api_key, default_request_params, logging)
29
+ end
30
+
31
+ def magic_links
32
+ @magic_links ||= Streambird::Api::MagicLinks.new(client)
33
+ end
34
+
35
+ alias_method :live, :live?
36
+ alias_method :test, :test?
37
+ alias_method :live_mode?, :live?
38
+ alias_method :test_mode?, :test?
39
+ end
40
+
41
+ require 'streambird/api'
42
+ require 'streambird/api/errors'
43
+ require 'streambird/api/magic_links'
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "streambird"
7
+ spec.version = "1.0.1"
8
+ spec.authors = ["streambird"]
9
+ spec.email = ["hello@streambird.io"]
10
+
11
+ spec.summary = %q{Official Ruby Client for Streambird API}
12
+ spec.description = %q{Streambird is an API For passwordless authentication for web2 and web3. Onboarding users within minutes. This is the official Ruby client.}
13
+ spec.homepage = "https://streambird.io"
14
+ spec.license = "MIT"
15
+
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.11"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.8"
27
+ spec.add_development_dependency "webmock", "~> 3.5"
28
+ spec.add_development_dependency "vcr", "~> 4.0"
29
+
30
+ spec.add_dependency "faraday", "~> 0.11.0"
31
+ end
@@ -0,0 +1,10 @@
1
+ namespace :spec do
2
+ desc 'Run rspec against production server instead of local cassettes'
3
+ task :production do
4
+ if ENV['STREAMBIRD_TEST_API_KEY'].nil?
5
+ raise 'Please specify STREAMBIRD_TEST_API_KEY to run against production server'
6
+ end
7
+ ENV['STREAMBIRD_TEST_SERVER'] = 'production'
8
+ Rake::Task['spec'].invoke
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: streambird
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - streambird
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-02-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.11.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.11.0
97
+ description: Streambird is an API For passwordless authentication for web2 and web3.
98
+ Onboarding users within minutes. This is the official Ruby client.
99
+ email:
100
+ - hello@streambird.io
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - lib/streambird.rb
115
+ - lib/streambird/api.rb
116
+ - lib/streambird/api/errors.rb
117
+ - lib/streambird/api/magic_links.rb
118
+ - streambird-ruby.gemspec
119
+ - tasks/spec_production.rake
120
+ homepage: https://streambird.io
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.7.6.2
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Official Ruby Client for Streambird API
144
+ test_files: []