streambird 1.0.1 → 1.0.2

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: dc7c798a9d73a5e3c7d2c76bfb2c06a49ed96a5c57999c3a1d15769024b5457d
4
- data.tar.gz: 8ba83f95ae432d0be726b67c19629dd04505f7714ceb64f19439ff097f9f4855
3
+ metadata.gz: 989e0d5603d6e40e6ed372d4c8f677beb1e13fad55ad6ce36bea485c19d87605
4
+ data.tar.gz: 1c4eb4c43250e05dd1f7b8c8aacc189cf85259fa5cfd4af48e9acf333f0507fb
5
5
  SHA512:
6
- metadata.gz: f2c7f1865c6093960cada4050eb708fffbd73c07e74979df6f1911a692737f62fbb9f8e6d88f8fd8f847896d563989d351ee9d6a74a2adeddd981cbbd0fbd13f
7
- data.tar.gz: bfc73850bd1d4eccba28a21c1039d143d28ce78621aab02964a8019d1519d75a6cdec0d07fdaa761ba75141eeb5e9a9b881a9bf0350b5d90c63e219010dc79cb
6
+ metadata.gz: ba63cb91eb8a583fc76b74a937facdd2b75a71d317f4c0ec80de8c86954dfb1e549a2a2345eab9109ddbff4030ee6ec161417a7f3d0f31d9304ada7c90fc0342
7
+ data.tar.gz: 9b6542d9395455f5ac1e6a334571c0e977f7f469668b45a367b6b0dc7007605e27e104ad7c6a74db73f30a6c67a36512be5656e4082804aa2c580e5b35b813b5
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ local_tester.rb
data/README.md CHANGED
@@ -28,6 +28,27 @@ require 'streambird'
28
28
  streambird = Streambird.new(api_key: 'API_KEY')
29
29
  ```
30
30
 
31
+ ### Example
32
+
33
+
34
+ Start a email magic link flow:
35
+
36
+ ```ruby
37
+ streambird.magic_links.email.login_or_create(
38
+ email: 'dev@streambird.io',
39
+ login_redirect_url: 'https://example.com/login',
40
+ registration_redirect_url: 'https://example.com/register',
41
+ )
42
+ ```
43
+
44
+ Verify the magic llink token:
45
+
46
+ ```ruby
47
+ streambird.magic_links.verify(
48
+ token: 'bbqg5fxQrCkgIZr3HyWlxNdZ5l_lDNPrRlxnQ0KHTBk',
49
+ )
50
+ ```
51
+
31
52
  ## Errors
32
53
 
33
54
  This gem will raise exceptions on application-level errors. Here are the list of errors:
@@ -1,9 +1,9 @@
1
1
  class Streambird
2
2
  class Api
3
- class MagicLinks < Struct.new(:client)
3
+ class MagicLink < Struct.new(:client)
4
4
 
5
5
  def email
6
- @email ||= Streambird::Api::MagicLinks::Email.new(client)
6
+ @email ||= Streambird::Api::MagicLink::Email.new(client)
7
7
  end
8
8
 
9
9
  def create(user_id:)
@@ -15,6 +15,23 @@ class Streambird
15
15
  return json_body
16
16
  end
17
17
 
18
+ def verify(token:,
19
+ session_token: nil,
20
+ session_expires_in: nil,
21
+ device_fingerprint: {}
22
+ )
23
+ req = {
24
+ 'token': token,
25
+ }
26
+
27
+ req['device_fingerprint'] = device_fingerprint if device_fingerprint != {}
28
+ req['session_expires_in'] = session_expires_in if !session_expires_in.nil?
29
+ req['session_token'] = session_token if !session_token.nil?
30
+ response = client.post('auth/magic_links/verify', req)
31
+ json_body = JSON.parse(response.body, symbolize_names: true)
32
+ return json_body
33
+ end
34
+
18
35
  class Email < Struct.new(:client)
19
36
 
20
37
  def login_or_create(email:,
@@ -0,0 +1,23 @@
1
+ class Streambird
2
+ class Api
3
+ class OAuth < Struct.new(:client)
4
+
5
+ def verify(token:,
6
+ session_type: nil,
7
+ session_token: nil,
8
+ session_expires_in: nil
9
+ )
10
+ req = {
11
+ 'token': token,
12
+ }
13
+
14
+ req['session_type'] = session_type if !session_type.nil?
15
+ req['session_expires_in'] = session_expires_in if !session_expires_in.nil?
16
+ req['session_token'] = session_token if !session_token.nil?
17
+ response = client.post('auth/oauth/verify', req)
18
+ json_body = JSON.parse(response.body, symbolize_names: true)
19
+ return json_body
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,111 @@
1
+ class Streambird
2
+ class Api
3
+ class Otp < Struct.new(:client)
4
+
5
+ def email
6
+ @email ||= Streambird::Api::Otp::Email.new(client)
7
+ end
8
+
9
+ def sms
10
+ @sms ||= Streambird::Api::Otp::Sms.new(client)
11
+ end
12
+
13
+ def verify(otp:,
14
+ method_id:,
15
+ session_token: nil,
16
+ session_expires_in: nil,
17
+ device_fingerprint: {}
18
+ )
19
+ req = {
20
+ 'otp': otp,
21
+ 'method_id': method_id,
22
+ }
23
+
24
+ req['device_fingerprint'] = device_fingerprint if device_fingerprint != {}
25
+ req['session_expires_in'] = session_expires_in if !session_expires_in.nil?
26
+ req['session_token'] = session_token if !session_token.nil?
27
+ response = client.post('auth/otps/verify', req)
28
+ json_body = JSON.parse(response.body, symbolize_names: true)
29
+ return json_body
30
+ end
31
+
32
+ class Email < Struct.new(:client)
33
+
34
+ def login_or_create(email:,
35
+ expires_in: nil,
36
+ requires_verification: nil,
37
+ device_fingerprint: {}
38
+ )
39
+
40
+ req = {
41
+ 'email': email,
42
+ }
43
+
44
+ req['expires_in'] = expires_in if !expires_in.nil?
45
+ req['requires_verification'] = requires_verification if !requires_verification.nil?
46
+ req['device_fingerprint'] = device_fingerprint if device_fingerprint != {}
47
+ response = client.post('auth/otps/email/login_or_create', req)
48
+
49
+ json_body = JSON.parse(response.body, symbolize_names: true)
50
+ return json_body
51
+ end
52
+
53
+ def send(email:,
54
+ expires_in: nil,
55
+ device_fingerprint: {}
56
+ )
57
+
58
+ req = {
59
+ 'email': email,
60
+ }
61
+
62
+ req['expires_in'] = expires_in if !expires_in.nil?
63
+ req['device_fingerprint'] = device_fingerprint if device_fingerprint != {}
64
+ response = client.post('auth/otps/email/send', req)
65
+
66
+ json_body = JSON.parse(response.body, symbolize_names: true)
67
+ return json_body
68
+ end
69
+ end
70
+
71
+ class Sms < Struct.new(:client)
72
+
73
+ def login_or_create(phone_number:,
74
+ expires_in: nil,
75
+ requires_verification: nil,
76
+ device_fingerprint: {}
77
+ )
78
+
79
+ req = {
80
+ 'phone_number': phone_number,
81
+ }
82
+
83
+ req['expires_in'] = expires_in if !expires_in.nil?
84
+ req['requires_verification'] = requires_verification if !requires_verification.nil?
85
+ req['device_fingerprint'] = device_fingerprint if device_fingerprint != {}
86
+ response = client.post('auth/otps/sms/login_or_create', req)
87
+
88
+ json_body = JSON.parse(response.body, symbolize_names: true)
89
+ return json_body
90
+ end
91
+
92
+ def send(phone_number:,
93
+ expires_in: nil,
94
+ device_fingerprint: {}
95
+ )
96
+
97
+ req = {
98
+ 'phone_number': phone_number,
99
+ }
100
+
101
+ req['expires_in'] = expires_in if !expires_in.nil?
102
+ req['device_fingerprint'] = device_fingerprint if device_fingerprint != {}
103
+ response = client.post('auth/otps/sms/send', req)
104
+
105
+ json_body = JSON.parse(response.body, symbolize_names: true)
106
+ return json_body
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,29 @@
1
+ class Streambird
2
+ class Api
3
+ class Session < Struct.new(:client)
4
+
5
+ def verify(session_token:,
6
+ session_expires_in: nil
7
+ )
8
+ req = {
9
+ 'session_token': session_token,
10
+ }
11
+
12
+ req['session_expires_in'] = session_expires_in if !session_expires_in.nil?
13
+ response = client.post('auth/sessions/verify', req)
14
+ json_body = JSON.parse(response.body, symbolize_names: true)
15
+ return json_body
16
+ end
17
+
18
+ def list(user_id:)
19
+ params = {
20
+ 'user_id': user_id,
21
+ }
22
+
23
+ response = client.get('auth/sessions/list', params)
24
+ json_body = JSON.parse(response.body, symbolize_names: true)
25
+ return json_body
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,85 @@
1
+ class Streambird
2
+ class Api
3
+ class User < Struct.new(:client)
4
+
5
+ def create(email: nil,
6
+ phone_number: nil,
7
+ first_name: nil,
8
+ middle_name: nil,
9
+ last_name: nil,
10
+ requires_verification: nil
11
+ )
12
+ req = {}
13
+ req['email'] = email if !email.nil?
14
+ req['phone_number'] = phone_number if !phone_number.nil?
15
+ req['first_name'] = first_name if !first_name.nil?
16
+ req['middle_name'] = middle_name if !middle_name.nil?
17
+ req['last_name'] = last_name if !last_name.nil?
18
+ req['requires_verification'] = requires_verification if !requires_verification.nil?
19
+
20
+ response = client.post('auth/users/create', req)
21
+ json_body = JSON.parse(response.body, symbolize_names: true)
22
+ return json_body
23
+ end
24
+
25
+ def update(user_id:,
26
+ first_name: nil,
27
+ middle_name: nil,
28
+ last_name: nil,
29
+ emails: [],
30
+ phone_numbers: []
31
+ )
32
+ req = {}
33
+ req['first_name'] = first_name if !first_name.nil?
34
+ req['middle_name'] = middle_name if !middle_name.nil?
35
+ req['last_name'] = last_name if !last_name.nil?
36
+ req['emails'] = to_emails_req(emails)
37
+ req['phone_numbers'] = to_phone_numbers_req(phone_numbers)
38
+
39
+ response = client.put("auth/users/#{user_id}/update", req)
40
+ json_body = JSON.parse(response.body, symbolize_names: true)
41
+ return json_body
42
+ end
43
+
44
+ def get(user_id:)
45
+ response = client.get("auth/users/#{user_id}")
46
+ json_body = JSON.parse(response.body, symbolize_names: true)
47
+ return json_body
48
+ end
49
+
50
+ def delete(user_id:)
51
+ response = client.delete("auth/users/#{user_id}/delete")
52
+ json_body = JSON.parse(response.body, symbolize_names: true)
53
+ return json_body
54
+ end
55
+
56
+ def delete_email(email_id:)
57
+ response = client.delete("auth/users/emails/#{email_id}/delete")
58
+ json_body = JSON.parse(response.body, symbolize_names: true)
59
+ return json_body
60
+ end
61
+
62
+ def delete_phone_number(phone_number_id:)
63
+ response = client.delete("auth/users/phone_numbers/#{phone_number_id}/delete")
64
+ json_body = JSON.parse(response.body, symbolize_names: true)
65
+ return json_body
66
+ end
67
+
68
+ def to_emails_req(emails)
69
+ emails_req = []
70
+ emails.each do |email|
71
+ emails_req << { email: email }
72
+ end
73
+ emails_req
74
+ end
75
+
76
+ def to_phone_numbers_req(phone_numbers)
77
+ phone_numbers_req = []
78
+ phone_numbers.each do |phone_number|
79
+ phone_numbers_req << { phone_number: phone_number }
80
+ end
81
+ phone_numbers_req
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,36 @@
1
+ class Streambird
2
+ class Api
3
+ class Wallet < Struct.new(:client)
4
+
5
+ def begin_registration(wallet_type:,
6
+ public_address:,
7
+ user_id: nil
8
+ )
9
+ req = {
10
+ 'wallet_type': wallet_type,
11
+ 'public_address': public_address,
12
+ }
13
+
14
+ req['user_id'] = user_id if !user_id.nil?
15
+ response = client.post('auth/wallets/registrations/begin', req)
16
+ json_body = JSON.parse(response.body, symbolize_names: true)
17
+ return json_body
18
+ end
19
+
20
+ def verify(wallet_type:,
21
+ public_address:,
22
+ signature:
23
+ )
24
+ req = {
25
+ 'wallet_type': wallet_type,
26
+ 'public_address': public_address,
27
+ 'signature': signature,
28
+ }
29
+
30
+ response = client.post('auth/wallets/verify', req)
31
+ json_body = JSON.parse(response.body, symbolize_names: true)
32
+ return json_body
33
+ end
34
+ end
35
+ end
36
+ end
@@ -4,7 +4,7 @@ require 'json'
4
4
 
5
5
  class Streambird
6
6
  class Api < Struct.new(:api_key, :default_request_params, :logging)
7
- STREAMBIRD_API_URL = 'http://localhost:11019/v1/'
7
+ STREAMBIRD_API_URL = ENV['STREAMBIRD_API_URL'] || 'https://api.streambird.io/v1/'
8
8
  STREAMBIRD_GEM_INFO = Gem.loaded_specs["streambird"]
9
9
  STREAMBIRD_RUBY_CLIENT_VERSION = STREAMBIRD_GEM_INFO ? STREAMBIRD_GEM_INFO.version.to_s : '0.1.1'.freeze
10
10
 
@@ -35,7 +35,6 @@ class Streambird
35
35
  end
36
36
 
37
37
  def post(url, body = {})
38
-
39
38
  body = default_request_params.merge(body)
40
39
  response = connection.post do |req|
41
40
  req.url "#{STREAMBIRD_API_URL}#{url}"
@@ -54,6 +53,27 @@ class Streambird
54
53
  raise Streambird::Api::ConnectionError
55
54
  end
56
55
 
56
+
57
+ def delete(url, body = {})
58
+
59
+ body = default_request_params.merge(body)
60
+ response = connection.delete do |req|
61
+ req.url "#{STREAMBIRD_API_URL}#{url}"
62
+ req.headers['Content-Type'] = 'application/json'
63
+ req.body = body.to_json
64
+ req.headers['X-API-Client'] = "Ruby"
65
+ req.headers["X-API-Client-Version"] = STREAMBIRD_RUBY_CLIENT_VERSION
66
+ end
67
+
68
+ if response.status != 200 and response.status != 201
69
+ return handle_error(response)
70
+ end
71
+
72
+ response
73
+ rescue Faraday::Error::ConnectionFailed
74
+ raise Streambird::Api::ConnectionError
75
+ end
76
+
57
77
  def handle_error(response)
58
78
  error_body = JSON.parse(response.body)
59
79
  if response.status == 404
data/lib/streambird.rb CHANGED
@@ -24,14 +24,34 @@ class Streambird
24
24
  end
25
25
 
26
26
  def client
27
- puts default_request_params
28
27
  @client ||= Api.new(api_key, default_request_params, logging)
29
28
  end
30
29
 
31
30
  def magic_links
32
- @magic_links ||= Streambird::Api::MagicLinks.new(client)
31
+ @magic_links ||= Streambird::Api::MagicLink.new(client)
33
32
  end
34
33
 
34
+ def otps
35
+ @otps ||= Streambird::Api::Otp.new(client)
36
+ end
37
+
38
+ def users
39
+ @users ||= Streambird::Api::User.new(client)
40
+ end
41
+
42
+ def oauth
43
+ @oauth ||= Streambird::Api::OAuth.new(client)
44
+ end
45
+
46
+ def sessions
47
+ @sessions ||= Streambird::Api::Session.new(client)
48
+ end
49
+
50
+ def wallets
51
+ @wallets ||= Streambird::Api::Wallet.new(client)
52
+ end
53
+
54
+
35
55
  alias_method :live, :live?
36
56
  alias_method :test, :test?
37
57
  alias_method :live_mode?, :live?
@@ -40,4 +60,9 @@ end
40
60
 
41
61
  require 'streambird/api'
42
62
  require 'streambird/api/errors'
43
- require 'streambird/api/magic_links'
63
+ require 'streambird/api/magic_link'
64
+ require 'streambird/api/otp'
65
+ require 'streambird/api/user'
66
+ require 'streambird/api/oauth'
67
+ require 'streambird/api/session'
68
+ require 'streambird/api/wallet'
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "streambird"
7
- spec.version = "1.0.1"
7
+ spec.version = "1.0.2"
8
8
  spec.authors = ["streambird"]
9
9
  spec.email = ["hello@streambird.io"]
10
10
 
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "rspec", "~> 3.8"
27
27
  spec.add_development_dependency "webmock", "~> 3.5"
28
28
  spec.add_development_dependency "vcr", "~> 4.0"
29
+ spec.add_development_dependency "pry", "~> 0.14.1"
29
30
 
30
31
  spec.add_dependency "faraday", "~> 0.11.0"
31
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: streambird
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - streambird
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-23 00:00:00.000000000 Z
11
+ date: 2022-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '4.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.14.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.14.1
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: faraday
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -114,7 +128,12 @@ files:
114
128
  - lib/streambird.rb
115
129
  - lib/streambird/api.rb
116
130
  - lib/streambird/api/errors.rb
117
- - lib/streambird/api/magic_links.rb
131
+ - lib/streambird/api/magic_link.rb
132
+ - lib/streambird/api/oauth.rb
133
+ - lib/streambird/api/otp.rb
134
+ - lib/streambird/api/session.rb
135
+ - lib/streambird/api/user.rb
136
+ - lib/streambird/api/wallet.rb
118
137
  - streambird-ruby.gemspec
119
138
  - tasks/spec_production.rake
120
139
  homepage: https://streambird.io