ribose 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/test.yml +27 -0
- data/lib/ribose/client.rb +27 -9
- data/lib/ribose/configuration.rb +12 -4
- data/lib/ribose/request.rb +33 -7
- data/lib/ribose/session.rb +36 -22
- data/lib/ribose/user.rb +9 -5
- data/lib/ribose/version.rb +1 -1
- data/ribose.gemspec +3 -4
- data/spec/ribose/session_spec.rb +2 -2
- metadata +19 -34
- data/.travis.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6f07dcb32d639879659c0ff04134fb21531fb31184d9f446045b7c6bf159d7b8
|
4
|
+
data.tar.gz: 6b4b18cff60096ad9437c593a1d50c781d00226da781f3354192b01f4f83b300
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a07d25023569d184f6250c9cf0f7106ee9e9a6e3ae465516f58a5be597ee96f064c047fe5c434a573385b519c55a78fc7776b75d56f8c37666d89e98819fb19
|
7
|
+
data.tar.gz: d09ccceb23eed385f3270b9adb4653f6f4787495dc435366c6989ab51dec49509833c7e4c5d40650d238eb3826334425e1f8aa598c5effae84cea849059aa386
|
@@ -0,0 +1,27 @@
|
|
1
|
+
name: test
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ main ]
|
6
|
+
tags: [ v* ]
|
7
|
+
pull_request:
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
name: RSpec
|
12
|
+
runs-on: ${{ matrix.os }}
|
13
|
+
strategy:
|
14
|
+
fail-fast: false
|
15
|
+
matrix:
|
16
|
+
ruby: [ '2.4', '2.5', '2.6', '2.7' ] #3.0
|
17
|
+
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
18
|
+
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@v2
|
21
|
+
|
22
|
+
- uses: ruby/setup-ruby@v1
|
23
|
+
with:
|
24
|
+
ruby-version: ${{ matrix.ruby }}
|
25
|
+
bundler-cache: true
|
26
|
+
|
27
|
+
- run: bundle exec rake
|
data/lib/ribose/client.rb
CHANGED
@@ -1,25 +1,43 @@
|
|
1
1
|
module Ribose
|
2
2
|
class Client
|
3
|
-
|
3
|
+
attr_accessor :api_token, :api_email, :user_email,
|
4
|
+
:client_id, :uid, :access_token
|
4
5
|
|
5
6
|
def initialize(options = {})
|
6
|
-
@api_token
|
7
|
-
@
|
7
|
+
@api_token = options.fetch(:api_token, configuration.api_token).to_s
|
8
|
+
@api_email = options.fetch(:api_email, configuration.api_email).to_s
|
9
|
+
@client_id = options[:client_id]
|
10
|
+
@uid = options[:uid]
|
11
|
+
@access_token = options[:access_token]
|
8
12
|
end
|
9
13
|
|
10
14
|
# Initiate a ribose client
|
11
15
|
#
|
12
|
-
# This interface takes email
|
13
|
-
# do all the underlying work to find out
|
14
|
-
#
|
16
|
+
# This interface takes email, password, api_email and api_token
|
17
|
+
# Then it will do all the underlying work to find out client id and uid
|
18
|
+
# Finally it will return a ribose client.
|
15
19
|
#
|
16
20
|
# @param :email [String] The email for your Ribose account
|
17
21
|
# @param :password [String] The password for your account
|
22
|
+
# @param :api_email [String] The email for your API account
|
23
|
+
# @param :api_token [String] The authentication token for your API account
|
18
24
|
# @return [Ribose::Client] A new client with your details
|
19
25
|
#
|
20
|
-
def self.from_login(email:, password:)
|
21
|
-
session = Session.create(
|
22
|
-
|
26
|
+
def self.from_login(email:, password:, api_email:, api_token:)
|
27
|
+
session = Session.create(
|
28
|
+
username: email,
|
29
|
+
password: password,
|
30
|
+
api_email: api_email,
|
31
|
+
api_token: api_token
|
32
|
+
)
|
33
|
+
|
34
|
+
new(
|
35
|
+
api_email: api_email,
|
36
|
+
api_token: api_token,
|
37
|
+
client_id: session.nil? ? nil : session['client'],
|
38
|
+
uid: session.nil? ? nil : session['uid'],
|
39
|
+
access_token: session.nil? ? nil : session['access-token'],
|
40
|
+
)
|
23
41
|
end
|
24
42
|
|
25
43
|
private
|
data/lib/ribose/configuration.rb
CHANGED
@@ -2,19 +2,27 @@ require "ribose/response/raise_error"
|
|
2
2
|
|
3
3
|
module Ribose
|
4
4
|
class Configuration
|
5
|
-
attr_accessor :api_host, :
|
5
|
+
attr_accessor :api_host, :api_email, :api_token,
|
6
|
+
:user_email, :user_password,
|
7
|
+
:verify_ssl,
|
8
|
+
:debug_mode
|
6
9
|
|
7
10
|
def initialize
|
8
11
|
@debug_mode = false
|
9
|
-
@
|
12
|
+
@verify_ssl = true
|
13
|
+
@api_host ||= "https://www.ribose.com"
|
10
14
|
end
|
11
15
|
|
12
16
|
def debug_mode?
|
13
17
|
debug_mode == true
|
14
18
|
end
|
15
19
|
|
16
|
-
def
|
17
|
-
|
20
|
+
def verify_ssl?
|
21
|
+
!!verify_ssl
|
22
|
+
end
|
23
|
+
|
24
|
+
def ssl_verification_mode
|
25
|
+
verify_ssl? ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
|
18
26
|
end
|
19
27
|
|
20
28
|
def add_default_middleware(builder)
|
data/lib/ribose/request.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Ribose
|
2
2
|
class Request
|
3
|
+
|
4
|
+
DEFAULT_CONTENT_TYPE = "application/json"
|
3
5
|
# Initialize a Request
|
4
6
|
#
|
5
7
|
# @param http_method [Symbol] HTTP verb as sysmbol
|
@@ -24,6 +26,12 @@ module Ribose
|
|
24
26
|
options[:query] = extract_config_option(:query) || {}
|
25
27
|
|
26
28
|
response = agent.call(http_method, api_endpoint, data, options)
|
29
|
+
|
30
|
+
# update client headers from response
|
31
|
+
client.client_id = response.headers['client']
|
32
|
+
client.uid = response.headers['uid']
|
33
|
+
client.access_token = response.headers['access-token']
|
34
|
+
|
27
35
|
parsable == true ? response.data : response
|
28
36
|
end
|
29
37
|
|
@@ -71,7 +79,7 @@ module Ribose
|
|
71
79
|
attr_reader :client, :data, :http_method
|
72
80
|
|
73
81
|
def ribose_host
|
74
|
-
Ribose.configuration.api_host
|
82
|
+
Ribose.configuration.api_host.host
|
75
83
|
end
|
76
84
|
|
77
85
|
def extract_config_option(key)
|
@@ -81,7 +89,13 @@ module Ribose
|
|
81
89
|
end
|
82
90
|
|
83
91
|
def find_suitable_client
|
84
|
-
client = extract_config_option(:client) || Ribose::Client.new
|
92
|
+
# client = extract_config_option(:client) || Ribose::Client.new
|
93
|
+
client = extract_config_option(:client) ||
|
94
|
+
Ribose::Client.from_login(
|
95
|
+
email: Ribose.configuration.user_email,
|
96
|
+
password: Ribose.configuration.user_password,
|
97
|
+
api_token: Ribose.configuration.api_token
|
98
|
+
)
|
85
99
|
client.is_a?(Ribose::Client) ? client : raise(Ribose::Unauthorized)
|
86
100
|
end
|
87
101
|
|
@@ -101,9 +115,17 @@ module Ribose
|
|
101
115
|
end
|
102
116
|
|
103
117
|
def sawyer_options
|
118
|
+
faraday_options = { builder: custom_rack_builder }
|
119
|
+
unless Ribose.configuration.verify_ssl?
|
120
|
+
faraday_options.merge!(ssl: Faraday::SSLOptions.new(
|
121
|
+
false, nil, nil, OpenSSL::SSL::VERIFY_NONE
|
122
|
+
)
|
123
|
+
)
|
124
|
+
end
|
125
|
+
|
104
126
|
{
|
105
127
|
links_parser: Sawyer::LinkParsers::Simple.new,
|
106
|
-
faraday: Faraday.new(
|
128
|
+
faraday: Faraday.new(faraday_options),
|
107
129
|
}
|
108
130
|
end
|
109
131
|
|
@@ -115,19 +137,23 @@ module Ribose
|
|
115
137
|
|
116
138
|
def set_content_type(headers)
|
117
139
|
header = custom_content_headers
|
118
|
-
default_type = "application/json"
|
119
140
|
|
120
|
-
headers[:content_type] =
|
121
|
-
headers[:accept] = header.fetch(:accept,
|
141
|
+
headers[:content_type] = DEFAULT_CONTENT_TYPE
|
142
|
+
headers[:accept] = header.fetch(:accept, DEFAULT_CONTENT_TYPE)
|
122
143
|
end
|
123
144
|
|
124
145
|
def agent
|
125
146
|
@agent ||= Sawyer::Agent.new(ribose_host, sawyer_options) do |http|
|
126
147
|
set_content_type(http.headers)
|
127
148
|
|
149
|
+
# set headers for devise-token-auth
|
150
|
+
http.headers["access-token"] = client.access_token
|
151
|
+
http.headers["client"] = client.client_id
|
152
|
+
http.headers["uid"] = client.uid
|
153
|
+
|
128
154
|
if require_auth_headers?
|
129
155
|
http.headers["X-Indigo-Token"] = client.api_token
|
130
|
-
http.headers["X-Indigo-Email"] = client.
|
156
|
+
http.headers["X-Indigo-Email"] = client.api_email
|
131
157
|
end
|
132
158
|
end
|
133
159
|
end
|
data/lib/ribose/session.rb
CHANGED
@@ -1,40 +1,54 @@
|
|
1
1
|
require "json"
|
2
|
-
require
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
3
4
|
require "ribose/config"
|
4
5
|
|
5
6
|
module Ribose
|
6
7
|
class Session
|
7
|
-
def initialize(username, password)
|
8
|
-
@username
|
9
|
-
@password
|
8
|
+
def initialize(username, password, api_email, api_token)
|
9
|
+
@username = username
|
10
|
+
@password = password
|
11
|
+
@api_email = api_email
|
12
|
+
@api_token = api_token
|
10
13
|
end
|
11
14
|
|
12
15
|
def create
|
13
|
-
|
14
|
-
rescue NoMethodError, JSON::ParserError
|
15
|
-
raise Ribose::Unauthorized
|
16
|
+
authenticate_user
|
16
17
|
end
|
17
18
|
|
18
|
-
def self.create(username:, password:)
|
19
|
-
new(username, password).create
|
19
|
+
def self.create(username:, password:, api_email:, api_token:)
|
20
|
+
new(username, password, api_email, api_token).create
|
20
21
|
end
|
21
22
|
|
22
23
|
private
|
23
24
|
|
24
|
-
attr_reader :username, :password
|
25
|
+
attr_reader :username, :password, :api_email, :api_token
|
25
26
|
|
26
27
|
def authenticate_user
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
28
|
+
uri = URI.parse(ribose_url_for("api/v2/auth/sign_in"))
|
29
|
+
response = Net::HTTP.start(
|
30
|
+
uri.host,
|
31
|
+
uri.port,
|
32
|
+
use_ssl: true,
|
33
|
+
verify_mode: Ribose.configuration.ssl_verification_mode
|
34
|
+
) do |http|
|
35
|
+
request = Net::HTTP::Post.new(uri)
|
36
|
+
# set request headers
|
37
|
+
request['X-Indigo-Username'] = api_email
|
38
|
+
request['X-Indigo-Token'] = api_token
|
39
|
+
request['Content-Type'] = 'application/json'
|
40
|
+
|
41
|
+
# set form data
|
42
|
+
request.set_form_data(
|
43
|
+
'username' => username,
|
44
|
+
'password' => password
|
45
|
+
)
|
46
|
+
http.request(request)
|
47
|
+
end
|
48
|
+
|
49
|
+
# return response headers in hash if success
|
50
|
+
return response.each_header.to_h if response.is_a? Net::HTTPSuccess
|
51
|
+
nil
|
38
52
|
end
|
39
53
|
|
40
54
|
def agent
|
@@ -42,7 +56,7 @@ module Ribose
|
|
42
56
|
end
|
43
57
|
|
44
58
|
def ribose_url_for(*endpoint)
|
45
|
-
[Ribose.configuration.
|
59
|
+
[Ribose.configuration.api_host, *endpoint].join("/")
|
46
60
|
end
|
47
61
|
end
|
48
62
|
end
|
data/lib/ribose/user.rb
CHANGED
@@ -8,8 +8,12 @@ module Ribose
|
|
8
8
|
|
9
9
|
def activate
|
10
10
|
Ribose::Request.post(
|
11
|
-
"
|
12
|
-
custom_option.merge(
|
11
|
+
"api/v2/auth",
|
12
|
+
custom_option.merge(
|
13
|
+
user: attributes,
|
14
|
+
auth_header: false,
|
15
|
+
client: Ribose::Client.new
|
16
|
+
),
|
13
17
|
)
|
14
18
|
end
|
15
19
|
|
@@ -17,12 +21,12 @@ module Ribose
|
|
17
21
|
#
|
18
22
|
# @param email [String] The registering user email
|
19
23
|
# @param password [String] A strong password for login
|
20
|
-
# @param
|
24
|
+
# @param edata [String] The OTP received via the email
|
21
25
|
# @param attributes [Hash] The other attributes as Hash.
|
22
26
|
# @return [Sawyer::Resoruce] The newly activated user
|
23
27
|
#
|
24
|
-
def self.activate(email:, password:,
|
25
|
-
new(attributes.merge(email: email, password: password,
|
28
|
+
def self.activate(email:, password:, edata:, **attributes)
|
29
|
+
new(attributes.merge(email: email, password: password, edata: edata)).activate
|
26
30
|
end
|
27
31
|
|
28
32
|
private
|
data/lib/ribose/version.rb
CHANGED
data/ribose.gemspec
CHANGED
@@ -21,13 +21,12 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.1.9")
|
22
22
|
|
23
23
|
spec.add_dependency "id_pack", "~> 1.0.1"
|
24
|
-
spec.add_dependency "mechanize", "~> 2.7.5"
|
25
24
|
spec.add_dependency "mime-types", "~> 3.1"
|
26
25
|
spec.add_dependency "sawyer", "~> 0.8.1"
|
27
26
|
|
28
|
-
spec.add_development_dependency "bundler"
|
29
|
-
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "bundler"
|
28
|
+
spec.add_development_dependency "rake"
|
30
29
|
spec.add_development_dependency "rspec", "~> 3.0"
|
31
|
-
spec.add_development_dependency "pry"
|
30
|
+
spec.add_development_dependency "pry"
|
32
31
|
spec.add_development_dependency "webmock", "~> 2.0"
|
33
32
|
end
|
data/spec/ribose/session_spec.rb
CHANGED
@@ -15,11 +15,11 @@ RSpec.describe Ribose::Session do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def login_url
|
18
|
-
ribose_url_for("
|
18
|
+
ribose_url_for("api/v2/auth/sign_in")
|
19
19
|
end
|
20
20
|
|
21
21
|
def ribose_url_for(*endpoints)
|
22
|
-
[Ribose.configuration.
|
22
|
+
[Ribose.configuration.api_host, *endpoints].join("/")
|
23
23
|
end
|
24
24
|
|
25
25
|
def stub_session_creation_request_via_web
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ribose
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: id_pack
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.0.1
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: mechanize
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 2.7.5
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 2.7.5
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: mime-types
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,30 +56,30 @@ dependencies:
|
|
70
56
|
name: bundler
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
|
-
- - "
|
59
|
+
- - ">="
|
74
60
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
61
|
+
version: '0'
|
76
62
|
type: :development
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
|
-
- - "
|
66
|
+
- - ">="
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
68
|
+
version: '0'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: rake
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
|
-
- - "
|
73
|
+
- - ">="
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
75
|
+
version: '0'
|
90
76
|
type: :development
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
|
-
- - "
|
80
|
+
- - ">="
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
82
|
+
version: '0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: rspec
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,16 +98,16 @@ dependencies:
|
|
112
98
|
name: pry
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
114
100
|
requirements:
|
115
|
-
- - "
|
101
|
+
- - ">="
|
116
102
|
- !ruby/object:Gem::Version
|
117
|
-
version: 0
|
103
|
+
version: '0'
|
118
104
|
type: :development
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
107
|
requirements:
|
122
|
-
- - "
|
108
|
+
- - ">="
|
123
109
|
- !ruby/object:Gem::Version
|
124
|
-
version: 0
|
110
|
+
version: '0'
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
112
|
name: webmock
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -143,12 +129,12 @@ executables: []
|
|
143
129
|
extensions: []
|
144
130
|
extra_rdoc_files: []
|
145
131
|
files:
|
132
|
+
- ".github/workflows/test.yml"
|
146
133
|
- ".gitignore"
|
147
134
|
- ".hound.yml"
|
148
135
|
- ".rspec"
|
149
136
|
- ".rubocop.yml"
|
150
137
|
- ".sample.pryrc"
|
151
|
-
- ".travis.yml"
|
152
138
|
- CHANGELOG.md
|
153
139
|
- Gemfile
|
154
140
|
- LICENSE.txt
|
@@ -300,7 +286,7 @@ homepage: https://github.com/riboseinc/ribose-ruby
|
|
300
286
|
licenses:
|
301
287
|
- MIT
|
302
288
|
metadata: {}
|
303
|
-
post_install_message:
|
289
|
+
post_install_message:
|
304
290
|
rdoc_options: []
|
305
291
|
require_paths:
|
306
292
|
- lib
|
@@ -315,9 +301,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
315
301
|
- !ruby/object:Gem::Version
|
316
302
|
version: '0'
|
317
303
|
requirements: []
|
318
|
-
|
319
|
-
|
320
|
-
signing_key:
|
304
|
+
rubygems_version: 3.0.1
|
305
|
+
signing_key:
|
321
306
|
specification_version: 4
|
322
307
|
summary: The Ruby interface for Ribose API
|
323
308
|
test_files: []
|