ribose 0.4.0 → 0.4.1

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
- SHA1:
3
- metadata.gz: e18f5e392f562d3757a8dffaf903af1f63c2f8d0
4
- data.tar.gz: bcef222cf96830b6d150ead2571d31607f06b4d0
2
+ SHA256:
3
+ metadata.gz: 6f07dcb32d639879659c0ff04134fb21531fb31184d9f446045b7c6bf159d7b8
4
+ data.tar.gz: 6b4b18cff60096ad9437c593a1d50c781d00226da781f3354192b01f4f83b300
5
5
  SHA512:
6
- metadata.gz: 49235eefd2aa174afc2eb97febd0d5fb34b5832aa016665c37e17f6d52ff3a02ee29e352e287e623f9f2074b5176bb41488508e90ab47bb5cab0e3b531d22303
7
- data.tar.gz: c85dc140fa9b23184aa77d6ef9334e59afe0286ad23f5b85417746ad70b78958fe0591ce3b0d6a9712ccab40e3f79babf8e3891d7f3fd87100a17fc681cf18ea
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
- attr_reader :api_token, :user_email
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 = options.fetch(:token, configuration.api_token).to_s
7
- @user_email = options.fetch(:email, configuration.user_email).to_s
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 and password and then it will
13
- # do all the underlying work to find out the authentication
14
- # token and retrun a ribose client.
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(username: email, password: password)
22
- new(email: email, token: session["authentication_token"])
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
@@ -2,19 +2,27 @@ require "ribose/response/raise_error"
2
2
 
3
3
  module Ribose
4
4
  class Configuration
5
- attr_accessor :api_host, :api_token, :user_email, :debug_mode
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
- @api_host ||= "www.ribose.com"
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 web_url
17
- ["https", api_host].join("://")
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)
@@ -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(builder: custom_rack_builder),
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] = default_type
121
- headers[:accept] = header.fetch(:accept, default_type)
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.user_email
156
+ http.headers["X-Indigo-Email"] = client.api_email
131
157
  end
132
158
  end
133
159
  end
@@ -1,40 +1,54 @@
1
1
  require "json"
2
- require "mechanize"
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 = username
9
- @password = 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
- JSON.parse(authenticate_user)
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
- page = agent.get(ribose_url_for("login"))
28
- find_and_submit_the_user_login_form(page)
29
- agent.get(ribose_url_for(["settings", "general", "info"])).body
30
- end
31
-
32
- def find_and_submit_the_user_login_form(page)
33
- login_form = page.form_with(id: "new_user")
34
- login_form.field_with(id: "loginEmail").value = username
35
- login_form.field_with(id: "loginPassword").value = password
36
-
37
- login_form.submit
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.web_url, *endpoint].join("/")
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
- "signup.user",
12
- custom_option.merge(user: attributes, auth_header: false),
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 otp [String] The OTP received via the email
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:, otp:, **attributes)
25
- new(attributes.merge(email: email, password: password, otp: otp)).activate
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
@@ -1,3 +1,3 @@
1
1
  module Ribose
2
- VERSION = "0.4.0".freeze
2
+ VERSION = "0.4.1".freeze
3
3
  end
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", "~> 1.14"
29
- spec.add_development_dependency "rake", "~> 10.0"
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", "~> 0.10.4"
30
+ spec.add_development_dependency "pry"
32
31
  spec.add_development_dependency "webmock", "~> 2.0"
33
32
  end
@@ -15,11 +15,11 @@ RSpec.describe Ribose::Session do
15
15
  end
16
16
 
17
17
  def login_url
18
- ribose_url_for("login")
18
+ ribose_url_for("api/v2/auth/sign_in")
19
19
  end
20
20
 
21
21
  def ribose_url_for(*endpoints)
22
- [Ribose.configuration.web_url, *endpoints].join("/")
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.0
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: 2018-12-15 00:00:00.000000000 Z
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: '1.14'
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: '1.14'
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: '10.0'
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: '10.0'
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.10.4
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.10.4
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
- rubyforge_project:
319
- rubygems_version: 2.6.8
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: []
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.4.0
5
- before_install: gem install bundler -v 1.14.6