cheminee 0.1.34 → 0.1.36
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +19 -7
- data/README.md +5 -4
- data/cheminee.gemspec +3 -1
- data/docs/DefaultApi.md +67 -8
- data/lib/cheminee/api/default_api.rb +61 -3
- data/lib/cheminee/api_client.rb +133 -89
- data/lib/cheminee/configuration.rb +106 -22
- data/lib/cheminee/version.rb +1 -1
- data/pkg/cheminee-0.1.36.gem +0 -0
- metadata +37 -9
- data/pkg/cheminee-0.1.34.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6af426bbcd4778f0d0da91851010456e7ec6262e66dcbf367fa67674b3bbee24
|
4
|
+
data.tar.gz: 0a38cf05b5f535ae644caff1ad0aa7d2876ebd7a1fdbe115829d568f3efc83c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75379d5f3605463f219e25963221c249f4fb76d0acb9b140186325aee1d07467fc0f8e6111ed7f67ae2e58c56b91aad93ac1a58a97f839eced55db6fb7f4f101
|
7
|
+
data.tar.gz: f1769ec639ac34b1f0c6748aa1a0a4ea2038f3fbec48755ed07fedea857994e298e03326c0b61c6b0e8e74c93cd764146b5a86ea335ed0e35afbef956a93539d
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cheminee (0.1.
|
5
|
-
|
4
|
+
cheminee (0.1.36)
|
5
|
+
faraday (>= 1.0.1, < 3.0)
|
6
|
+
faraday-multipart
|
7
|
+
marcel
|
6
8
|
|
7
9
|
GEM
|
8
10
|
remote: https://rubygems.org/
|
@@ -11,11 +13,22 @@ GEM
|
|
11
13
|
byebug (11.1.3)
|
12
14
|
coderay (1.1.3)
|
13
15
|
diff-lcs (1.5.1)
|
14
|
-
|
15
|
-
|
16
|
-
|
16
|
+
faraday (2.12.0)
|
17
|
+
faraday-net_http (>= 2.0, < 3.4)
|
18
|
+
json
|
19
|
+
logger
|
20
|
+
faraday-multipart (1.0.4)
|
21
|
+
multipart-post (~> 2)
|
22
|
+
faraday-net_http (3.3.0)
|
23
|
+
net-http
|
17
24
|
jaro_winkler (1.5.6)
|
25
|
+
json (2.7.2)
|
26
|
+
logger (1.6.1)
|
27
|
+
marcel (1.0.4)
|
18
28
|
method_source (1.1.0)
|
29
|
+
multipart-post (2.4.1)
|
30
|
+
net-http (0.4.1)
|
31
|
+
uri
|
19
32
|
parallel (1.26.3)
|
20
33
|
parser (3.3.5.0)
|
21
34
|
ast (~> 2.4.1)
|
@@ -54,9 +67,8 @@ GEM
|
|
54
67
|
unicode-display_width (>= 1.4.0, < 1.6)
|
55
68
|
ruby-progressbar (1.13.0)
|
56
69
|
stringio (3.1.1)
|
57
|
-
typhoeus (1.4.1)
|
58
|
-
ethon (>= 0.9.0)
|
59
70
|
unicode-display_width (1.5.0)
|
71
|
+
uri (0.13.1)
|
60
72
|
|
61
73
|
PLATFORMS
|
62
74
|
x86_64-linux
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ Cheminée: The Chemical Structure Search Engine
|
|
7
7
|
This SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
|
8
8
|
|
9
9
|
- API version: 1.0
|
10
|
-
- Package version: 0.1.
|
10
|
+
- Package version: 0.1.36
|
11
11
|
- Generator version: 7.9.0-SNAPSHOT
|
12
12
|
- Build package: org.openapitools.codegen.languages.RubyClientCodegen
|
13
13
|
For more information, please visit [https://github.com/rdkit-rs/cheminee](https://github.com/rdkit-rs/cheminee)
|
@@ -25,16 +25,16 @@ gem build cheminee.gemspec
|
|
25
25
|
Then either install the gem locally:
|
26
26
|
|
27
27
|
```shell
|
28
|
-
gem install ./cheminee-0.1.
|
28
|
+
gem install ./cheminee-0.1.36.gem
|
29
29
|
```
|
30
30
|
|
31
|
-
(for development, run `gem install --dev ./cheminee-0.1.
|
31
|
+
(for development, run `gem install --dev ./cheminee-0.1.36.gem` to install the development dependencies)
|
32
32
|
|
33
33
|
or publish the gem to a gem hosting service, e.g. [RubyGems](https://rubygems.org/).
|
34
34
|
|
35
35
|
Finally add this to the Gemfile:
|
36
36
|
|
37
|
-
gem 'cheminee', '~> 0.1.
|
37
|
+
gem 'cheminee', '~> 0.1.36'
|
38
38
|
|
39
39
|
### Install from Git
|
40
40
|
|
@@ -85,6 +85,7 @@ Class | Method | HTTP request | Description
|
|
85
85
|
*Cheminee::DefaultApi* | [**v1_indexes_index_bulk_index_post**](docs/DefaultApi.md#v1_indexes_index_bulk_index_post) | **POST** /v1/indexes/{index}/bulk_index | Index a list of SMILES and associated, free-form JSON attributes which are indexed and searchable
|
86
86
|
*Cheminee::DefaultApi* | [**v1_indexes_index_delete**](docs/DefaultApi.md#v1_indexes_index_delete) | **DELETE** /v1/indexes/{index} | Delete an index
|
87
87
|
*Cheminee::DefaultApi* | [**v1_indexes_index_get**](docs/DefaultApi.md#v1_indexes_index_get) | **GET** /v1/indexes/{index} | Get extended information about an index
|
88
|
+
*Cheminee::DefaultApi* | [**v1_indexes_index_merge_post**](docs/DefaultApi.md#v1_indexes_index_merge_post) | **POST** /v1/indexes/{index}/merge | Merge segments inside the index
|
88
89
|
*Cheminee::DefaultApi* | [**v1_indexes_index_post**](docs/DefaultApi.md#v1_indexes_index_post) | **POST** /v1/indexes/{index} | Create an index
|
89
90
|
*Cheminee::DefaultApi* | [**v1_indexes_index_search_basic_get**](docs/DefaultApi.md#v1_indexes_index_search_basic_get) | **GET** /v1/indexes/{index}/search/basic | Perform basic query search against index
|
90
91
|
*Cheminee::DefaultApi* | [**v1_indexes_index_search_identity_get**](docs/DefaultApi.md#v1_indexes_index_search_identity_get) | **GET** /v1/indexes/{index}/search/identity | Perform identity search (i.e. exact match) against index
|
data/cheminee.gemspec
CHANGED
@@ -28,7 +28,9 @@ Gem::Specification.new do |s|
|
|
28
28
|
s.required_ruby_version = ">= 3.0"
|
29
29
|
s.metadata = {}
|
30
30
|
|
31
|
-
s.add_runtime_dependency '
|
31
|
+
s.add_runtime_dependency 'faraday', '>= 1.0.1', '< 3.0'
|
32
|
+
s.add_runtime_dependency 'faraday-multipart'
|
33
|
+
s.add_runtime_dependency 'marcel'
|
32
34
|
|
33
35
|
s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0'
|
34
36
|
|
data/docs/DefaultApi.md
CHANGED
@@ -11,6 +11,7 @@ All URIs are relative to *http://localhost:4001/api*
|
|
11
11
|
| [**v1_indexes_index_bulk_index_post**](DefaultApi.md#v1_indexes_index_bulk_index_post) | **POST** /v1/indexes/{index}/bulk_index | Index a list of SMILES and associated, free-form JSON attributes which are indexed and searchable |
|
12
12
|
| [**v1_indexes_index_delete**](DefaultApi.md#v1_indexes_index_delete) | **DELETE** /v1/indexes/{index} | Delete an index |
|
13
13
|
| [**v1_indexes_index_get**](DefaultApi.md#v1_indexes_index_get) | **GET** /v1/indexes/{index} | Get extended information about an index |
|
14
|
+
| [**v1_indexes_index_merge_post**](DefaultApi.md#v1_indexes_index_merge_post) | **POST** /v1/indexes/{index}/merge | Merge segments inside the index |
|
14
15
|
| [**v1_indexes_index_post**](DefaultApi.md#v1_indexes_index_post) | **POST** /v1/indexes/{index} | Create an index |
|
15
16
|
| [**v1_indexes_index_search_basic_get**](DefaultApi.md#v1_indexes_index_search_basic_get) | **GET** /v1/indexes/{index}/search/basic | Perform basic query search against index |
|
16
17
|
| [**v1_indexes_index_search_identity_get**](DefaultApi.md#v1_indexes_index_search_identity_get) | **GET** /v1/indexes/{index}/search/identity | Perform identity search (i.e. exact match) against index |
|
@@ -457,9 +458,71 @@ No authorization required
|
|
457
458
|
- **Accept**: application/json
|
458
459
|
|
459
460
|
|
461
|
+
## v1_indexes_index_merge_post
|
462
|
+
|
463
|
+
> String v1_indexes_index_merge_post(index)
|
464
|
+
|
465
|
+
Merge segments inside the index
|
466
|
+
|
467
|
+
### Examples
|
468
|
+
|
469
|
+
```ruby
|
470
|
+
require 'time'
|
471
|
+
require 'cheminee'
|
472
|
+
|
473
|
+
api_instance = Cheminee::DefaultApi.new
|
474
|
+
index = 'index_example' # String |
|
475
|
+
|
476
|
+
begin
|
477
|
+
# Merge segments inside the index
|
478
|
+
result = api_instance.v1_indexes_index_merge_post(index)
|
479
|
+
p result
|
480
|
+
rescue Cheminee::ApiError => e
|
481
|
+
puts "Error when calling DefaultApi->v1_indexes_index_merge_post: #{e}"
|
482
|
+
end
|
483
|
+
```
|
484
|
+
|
485
|
+
#### Using the v1_indexes_index_merge_post_with_http_info variant
|
486
|
+
|
487
|
+
This returns an Array which contains the response data, status code and headers.
|
488
|
+
|
489
|
+
> <Array(String, Integer, Hash)> v1_indexes_index_merge_post_with_http_info(index)
|
490
|
+
|
491
|
+
```ruby
|
492
|
+
begin
|
493
|
+
# Merge segments inside the index
|
494
|
+
data, status_code, headers = api_instance.v1_indexes_index_merge_post_with_http_info(index)
|
495
|
+
p status_code # => 2xx
|
496
|
+
p headers # => { ... }
|
497
|
+
p data # => String
|
498
|
+
rescue Cheminee::ApiError => e
|
499
|
+
puts "Error when calling DefaultApi->v1_indexes_index_merge_post_with_http_info: #{e}"
|
500
|
+
end
|
501
|
+
```
|
502
|
+
|
503
|
+
### Parameters
|
504
|
+
|
505
|
+
| Name | Type | Description | Notes |
|
506
|
+
| ---- | ---- | ----------- | ----- |
|
507
|
+
| **index** | **String** | | |
|
508
|
+
|
509
|
+
### Return type
|
510
|
+
|
511
|
+
**String**
|
512
|
+
|
513
|
+
### Authorization
|
514
|
+
|
515
|
+
No authorization required
|
516
|
+
|
517
|
+
### HTTP request headers
|
518
|
+
|
519
|
+
- **Content-Type**: Not defined
|
520
|
+
- **Accept**: application/json, application/json; charset=utf-8
|
521
|
+
|
522
|
+
|
460
523
|
## v1_indexes_index_post
|
461
524
|
|
462
|
-
> <IndexMeta> v1_indexes_index_post(index, schema
|
525
|
+
> <IndexMeta> v1_indexes_index_post(index, schema)
|
463
526
|
|
464
527
|
Create an index
|
465
528
|
|
@@ -472,13 +535,10 @@ require 'cheminee'
|
|
472
535
|
api_instance = Cheminee::DefaultApi.new
|
473
536
|
index = 'index_example' # String |
|
474
537
|
schema = 'schema_example' # String |
|
475
|
-
opts = {
|
476
|
-
sort_by: 'sort_by_example' # String |
|
477
|
-
}
|
478
538
|
|
479
539
|
begin
|
480
540
|
# Create an index
|
481
|
-
result = api_instance.v1_indexes_index_post(index, schema
|
541
|
+
result = api_instance.v1_indexes_index_post(index, schema)
|
482
542
|
p result
|
483
543
|
rescue Cheminee::ApiError => e
|
484
544
|
puts "Error when calling DefaultApi->v1_indexes_index_post: #{e}"
|
@@ -489,12 +549,12 @@ end
|
|
489
549
|
|
490
550
|
This returns an Array which contains the response data, status code and headers.
|
491
551
|
|
492
|
-
> <Array(<IndexMeta>, Integer, Hash)> v1_indexes_index_post_with_http_info(index, schema
|
552
|
+
> <Array(<IndexMeta>, Integer, Hash)> v1_indexes_index_post_with_http_info(index, schema)
|
493
553
|
|
494
554
|
```ruby
|
495
555
|
begin
|
496
556
|
# Create an index
|
497
|
-
data, status_code, headers = api_instance.v1_indexes_index_post_with_http_info(index, schema
|
557
|
+
data, status_code, headers = api_instance.v1_indexes_index_post_with_http_info(index, schema)
|
498
558
|
p status_code # => 2xx
|
499
559
|
p headers # => { ... }
|
500
560
|
p data # => <IndexMeta>
|
@@ -509,7 +569,6 @@ end
|
|
509
569
|
| ---- | ---- | ----------- | ----- |
|
510
570
|
| **index** | **String** | | |
|
511
571
|
| **schema** | **String** | | |
|
512
|
-
| **sort_by** | **String** | | [optional] |
|
513
572
|
|
514
573
|
### Return type
|
515
574
|
|
@@ -479,11 +479,71 @@ module Cheminee
|
|
479
479
|
return data, status_code, headers
|
480
480
|
end
|
481
481
|
|
482
|
+
# Merge segments inside the index
|
483
|
+
# @param index [String]
|
484
|
+
# @param [Hash] opts the optional parameters
|
485
|
+
# @return [String]
|
486
|
+
def v1_indexes_index_merge_post(index, opts = {})
|
487
|
+
data, _status_code, _headers = v1_indexes_index_merge_post_with_http_info(index, opts)
|
488
|
+
data
|
489
|
+
end
|
490
|
+
|
491
|
+
# Merge segments inside the index
|
492
|
+
# @param index [String]
|
493
|
+
# @param [Hash] opts the optional parameters
|
494
|
+
# @return [Array<(String, Integer, Hash)>] String data, response status code and response headers
|
495
|
+
def v1_indexes_index_merge_post_with_http_info(index, opts = {})
|
496
|
+
if @api_client.config.debugging
|
497
|
+
@api_client.config.logger.debug 'Calling API: DefaultApi.v1_indexes_index_merge_post ...'
|
498
|
+
end
|
499
|
+
# verify the required parameter 'index' is set
|
500
|
+
if @api_client.config.client_side_validation && index.nil?
|
501
|
+
fail ArgumentError, "Missing the required parameter 'index' when calling DefaultApi.v1_indexes_index_merge_post"
|
502
|
+
end
|
503
|
+
# resource path
|
504
|
+
local_var_path = '/v1/indexes/{index}/merge'.sub('{' + 'index' + '}', CGI.escape(index.to_s))
|
505
|
+
|
506
|
+
# query parameters
|
507
|
+
query_params = opts[:query_params] || {}
|
508
|
+
|
509
|
+
# header parameters
|
510
|
+
header_params = opts[:header_params] || {}
|
511
|
+
# HTTP header 'Accept' (if needed)
|
512
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json', 'application/json; charset=utf-8']) unless header_params['Accept']
|
513
|
+
|
514
|
+
# form parameters
|
515
|
+
form_params = opts[:form_params] || {}
|
516
|
+
|
517
|
+
# http body (model)
|
518
|
+
post_body = opts[:debug_body]
|
519
|
+
|
520
|
+
# return_type
|
521
|
+
return_type = opts[:debug_return_type] || 'String'
|
522
|
+
|
523
|
+
# auth_names
|
524
|
+
auth_names = opts[:debug_auth_names] || []
|
525
|
+
|
526
|
+
new_options = opts.merge(
|
527
|
+
:operation => :"DefaultApi.v1_indexes_index_merge_post",
|
528
|
+
:header_params => header_params,
|
529
|
+
:query_params => query_params,
|
530
|
+
:form_params => form_params,
|
531
|
+
:body => post_body,
|
532
|
+
:auth_names => auth_names,
|
533
|
+
:return_type => return_type
|
534
|
+
)
|
535
|
+
|
536
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
|
537
|
+
if @api_client.config.debugging
|
538
|
+
@api_client.config.logger.debug "API called: DefaultApi#v1_indexes_index_merge_post\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
539
|
+
end
|
540
|
+
return data, status_code, headers
|
541
|
+
end
|
542
|
+
|
482
543
|
# Create an index
|
483
544
|
# @param index [String]
|
484
545
|
# @param schema [String]
|
485
546
|
# @param [Hash] opts the optional parameters
|
486
|
-
# @option opts [String] :sort_by
|
487
547
|
# @return [IndexMeta]
|
488
548
|
def v1_indexes_index_post(index, schema, opts = {})
|
489
549
|
data, _status_code, _headers = v1_indexes_index_post_with_http_info(index, schema, opts)
|
@@ -494,7 +554,6 @@ module Cheminee
|
|
494
554
|
# @param index [String]
|
495
555
|
# @param schema [String]
|
496
556
|
# @param [Hash] opts the optional parameters
|
497
|
-
# @option opts [String] :sort_by
|
498
557
|
# @return [Array<(IndexMeta, Integer, Hash)>] IndexMeta data, response status code and response headers
|
499
558
|
def v1_indexes_index_post_with_http_info(index, schema, opts = {})
|
500
559
|
if @api_client.config.debugging
|
@@ -514,7 +573,6 @@ module Cheminee
|
|
514
573
|
# query parameters
|
515
574
|
query_params = opts[:query_params] || {}
|
516
575
|
query_params[:'schema'] = schema
|
517
|
-
query_params[:'sort_by'] = opts[:'sort_by'] if !opts[:'sort_by'].nil?
|
518
576
|
|
519
577
|
# header parameters
|
520
578
|
header_params = opts[:header_params] || {}
|
data/lib/cheminee/api_client.rb
CHANGED
@@ -15,7 +15,9 @@ require 'json'
|
|
15
15
|
require 'logger'
|
16
16
|
require 'tempfile'
|
17
17
|
require 'time'
|
18
|
-
require '
|
18
|
+
require 'faraday'
|
19
|
+
require 'faraday/multipart' if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
|
20
|
+
require 'marcel'
|
19
21
|
|
20
22
|
|
21
23
|
module Cheminee
|
@@ -46,39 +48,45 @@ module Cheminee
|
|
46
48
|
# Call an API with given options.
|
47
49
|
#
|
48
50
|
# @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
|
49
|
-
# the data deserialized from response body (
|
51
|
+
# the data deserialized from response body (could be nil), response status code and response headers.
|
50
52
|
def call_api(http_method, path, opts = {})
|
51
|
-
|
52
|
-
|
53
|
-
|
53
|
+
stream = nil
|
54
|
+
begin
|
55
|
+
response = connection(opts).public_send(http_method.to_sym.downcase) do |req|
|
56
|
+
request = build_request(http_method, path, req, opts)
|
57
|
+
stream = download_file(request) if opts[:return_type] == 'File' || opts[:return_type] == 'Binary'
|
58
|
+
end
|
54
59
|
|
55
|
-
|
56
|
-
|
57
|
-
|
60
|
+
if config.debugging
|
61
|
+
config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
|
62
|
+
end
|
58
63
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
response.status_message
|
64
|
+
unless response.success?
|
65
|
+
if response.status == 0 && response.respond_to?(:return_message)
|
66
|
+
# Errors from libcurl will be made visible here
|
67
|
+
fail ApiError.new(code: 0,
|
68
|
+
message: response.return_message)
|
69
|
+
else
|
70
|
+
fail ApiError.new(code: response.status,
|
71
|
+
response_headers: response.headers,
|
72
|
+
response_body: response.body),
|
73
|
+
response.reason_phrase
|
74
|
+
end
|
71
75
|
end
|
76
|
+
rescue Faraday::TimeoutError
|
77
|
+
fail ApiError.new('Connection timed out')
|
78
|
+
rescue Faraday::ConnectionFailed
|
79
|
+
fail ApiError.new('Connection failed')
|
72
80
|
end
|
73
81
|
|
74
|
-
if opts[:return_type] == 'File'
|
75
|
-
data =
|
82
|
+
if opts[:return_type] == 'File' || opts[:return_type] == 'Binary'
|
83
|
+
data = deserialize_file(response, stream)
|
76
84
|
elsif opts[:return_type]
|
77
85
|
data = deserialize(response, opts[:return_type])
|
78
86
|
else
|
79
87
|
data = nil
|
80
88
|
end
|
81
|
-
return data, response.
|
89
|
+
return data, response.status, response.headers
|
82
90
|
end
|
83
91
|
|
84
92
|
# Builds the HTTP request
|
@@ -89,46 +97,33 @@ module Cheminee
|
|
89
97
|
# @option opts [Hash] :query_params Query parameters
|
90
98
|
# @option opts [Hash] :form_params Query parameters
|
91
99
|
# @option opts [Object] :body HTTP body (JSON/XML)
|
92
|
-
# @return [
|
93
|
-
def build_request(http_method, path, opts = {})
|
100
|
+
# @return [Faraday::Request] A Faraday Request
|
101
|
+
def build_request(http_method, path, request, opts = {})
|
94
102
|
url = build_request_url(path, opts)
|
95
103
|
http_method = http_method.to_sym.downcase
|
96
104
|
|
97
105
|
header_params = @default_headers.merge(opts[:header_params] || {})
|
98
106
|
query_params = opts[:query_params] || {}
|
99
107
|
form_params = opts[:form_params] || {}
|
100
|
-
follow_location = opts[:follow_location] || true
|
101
|
-
|
102
|
-
|
103
|
-
# set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
|
104
|
-
_verify_ssl_host = @config.verify_ssl_host ? 2 : 0
|
105
|
-
|
106
|
-
req_opts = {
|
107
|
-
:method => http_method,
|
108
|
-
:headers => header_params,
|
109
|
-
:params => query_params,
|
110
|
-
:params_encoding => @config.params_encoding,
|
111
|
-
:timeout => @config.timeout,
|
112
|
-
:ssl_verifypeer => @config.verify_ssl,
|
113
|
-
:ssl_verifyhost => _verify_ssl_host,
|
114
|
-
:sslcert => @config.cert_file,
|
115
|
-
:sslkey => @config.key_file,
|
116
|
-
:verbose => @config.debugging,
|
117
|
-
:followlocation => follow_location
|
118
|
-
}
|
119
108
|
|
120
|
-
|
121
|
-
req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
|
109
|
+
update_params_for_auth! header_params, query_params, opts[:auth_names]
|
122
110
|
|
123
111
|
if [:post, :patch, :put, :delete].include?(http_method)
|
124
112
|
req_body = build_request_body(header_params, form_params, opts[:body])
|
125
|
-
|
126
|
-
|
127
|
-
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
113
|
+
if config.debugging
|
114
|
+
config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
128
115
|
end
|
129
116
|
end
|
117
|
+
request.headers = header_params
|
118
|
+
request.body = req_body
|
130
119
|
|
131
|
-
|
120
|
+
# Overload default options only if provided
|
121
|
+
request.options.params_encoder = config.params_encoder if config.params_encoder
|
122
|
+
request.options.timeout = config.timeout if config.timeout
|
123
|
+
|
124
|
+
request.url url
|
125
|
+
request.params = query_params
|
126
|
+
request
|
132
127
|
end
|
133
128
|
|
134
129
|
# Builds the HTTP request body
|
@@ -139,13 +134,16 @@ module Cheminee
|
|
139
134
|
# @return [String] HTTP body data in the form of string
|
140
135
|
def build_request_body(header_params, form_params, body)
|
141
136
|
# http form
|
142
|
-
if header_params['Content-Type'] == 'application/x-www-form-urlencoded'
|
143
|
-
|
137
|
+
if header_params['Content-Type'] == 'application/x-www-form-urlencoded'
|
138
|
+
data = URI.encode_www_form(form_params)
|
139
|
+
elsif header_params['Content-Type'] == 'multipart/form-data'
|
144
140
|
data = {}
|
145
141
|
form_params.each do |key, value|
|
146
142
|
case value
|
147
|
-
when ::File, ::
|
148
|
-
|
143
|
+
when ::File, ::Tempfile
|
144
|
+
data[key] = Faraday::FilePart.new(value.path, Marcel::MimeType.for(Pathname.new(value.path)))
|
145
|
+
when ::Array, nil
|
146
|
+
# let Faraday handle Array and nil parameters
|
149
147
|
data[key] = value
|
150
148
|
else
|
151
149
|
data[key] = value.to_s
|
@@ -159,49 +157,95 @@ module Cheminee
|
|
159
157
|
data
|
160
158
|
end
|
161
159
|
|
162
|
-
# Save response body into a file in (the defined) temporary folder, using the filename
|
163
|
-
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
164
|
-
# The response body is written to the file in chunks in order to handle files which
|
165
|
-
# size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
|
166
|
-
# process can use.
|
167
|
-
#
|
168
|
-
# @see Configuration#temp_folder_path
|
169
|
-
#
|
170
|
-
# @return [Tempfile] the tempfile generated
|
171
160
|
def download_file(request)
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
178
|
-
prefix = sanitize_filename(filename)
|
179
|
-
else
|
180
|
-
prefix = 'download-'
|
181
|
-
end
|
182
|
-
prefix = prefix + '-' unless prefix.end_with?('-')
|
183
|
-
encoding = response.body.encoding
|
184
|
-
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
185
|
-
end
|
186
|
-
request.on_body do |chunk|
|
187
|
-
chunk.force_encoding(encoding)
|
188
|
-
tempfile.write(chunk)
|
161
|
+
stream = []
|
162
|
+
|
163
|
+
# handle streaming Responses
|
164
|
+
request.options.on_data = Proc.new do |chunk, overall_received_bytes|
|
165
|
+
stream << chunk
|
189
166
|
end
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
167
|
+
|
168
|
+
stream
|
169
|
+
end
|
170
|
+
|
171
|
+
def deserialize_file(response, stream)
|
172
|
+
body = response.body
|
173
|
+
encoding = body.encoding
|
174
|
+
|
175
|
+
# reconstruct content
|
176
|
+
content = stream.join
|
177
|
+
content = content.unpack('m').join if response.headers['Content-Transfer-Encoding'] == 'binary'
|
178
|
+
content = content.force_encoding(encoding)
|
179
|
+
|
180
|
+
# return byte stream
|
181
|
+
return content if @config.return_binary_data == true
|
182
|
+
|
183
|
+
# return file instead of binary data
|
184
|
+
content_disposition = response.headers['Content-Disposition']
|
185
|
+
if content_disposition && content_disposition =~ /filename=/i
|
186
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
187
|
+
prefix = sanitize_filename(filename)
|
198
188
|
else
|
199
|
-
|
189
|
+
prefix = 'download-'
|
200
190
|
end
|
191
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
192
|
+
|
193
|
+
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
194
|
+
tempfile.write(content)
|
195
|
+
tempfile.close
|
201
196
|
|
197
|
+
config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
198
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
199
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
200
|
+
"explicitly with `tempfile.delete`"
|
202
201
|
tempfile
|
203
202
|
end
|
204
203
|
|
204
|
+
def connection(opts)
|
205
|
+
opts[:header_params]['Content-Type'] == 'multipart/form-data' ? connection_multipart : connection_regular
|
206
|
+
end
|
207
|
+
|
208
|
+
def connection_multipart
|
209
|
+
@connection_multipart ||= build_connection do |conn|
|
210
|
+
conn.request :multipart
|
211
|
+
conn.request :url_encoded
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
def connection_regular
|
216
|
+
@connection_regular ||= build_connection
|
217
|
+
end
|
218
|
+
|
219
|
+
def build_connection
|
220
|
+
Faraday.new(url: config.base_url, ssl: ssl_options, proxy: config.proxy) do |conn|
|
221
|
+
basic_auth(conn)
|
222
|
+
config.configure_middleware(conn)
|
223
|
+
yield(conn) if block_given?
|
224
|
+
conn.adapter(Faraday.default_adapter)
|
225
|
+
config.configure_connection(conn)
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
def ssl_options
|
230
|
+
{
|
231
|
+
ca_file: config.ssl_ca_file,
|
232
|
+
verify: config.ssl_verify,
|
233
|
+
verify_mode: config.ssl_verify_mode,
|
234
|
+
client_cert: config.ssl_client_cert,
|
235
|
+
client_key: config.ssl_client_key
|
236
|
+
}
|
237
|
+
end
|
238
|
+
|
239
|
+
def basic_auth(conn)
|
240
|
+
if config.username && config.password
|
241
|
+
if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
|
242
|
+
conn.request(:authorization, :basic, config.username, config.password)
|
243
|
+
else
|
244
|
+
conn.request(:basic_auth, config.username, config.password)
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
205
249
|
# Check if the given MIME is a JSON MIME.
|
206
250
|
# JSON MIME examples:
|
207
251
|
# application/json
|
@@ -116,40 +116,39 @@ module Cheminee
|
|
116
116
|
# @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
|
117
117
|
#
|
118
118
|
# @return [true, false]
|
119
|
-
attr_accessor :
|
119
|
+
attr_accessor :ssl_verify
|
120
120
|
|
121
121
|
### TLS/SSL setting
|
122
|
-
#
|
123
|
-
# Default to true.
|
122
|
+
# Any `OpenSSL::SSL::` constant (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html)
|
124
123
|
#
|
125
124
|
# @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
|
126
125
|
#
|
127
|
-
|
128
|
-
attr_accessor :verify_ssl_host
|
126
|
+
attr_accessor :ssl_verify_mode
|
129
127
|
|
130
128
|
### TLS/SSL setting
|
131
129
|
# Set this to customize the certificate file to verify the peer.
|
132
130
|
#
|
133
131
|
# @return [String] the path to the certificate file
|
134
|
-
|
135
|
-
# @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
|
136
|
-
# https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
|
137
|
-
attr_accessor :ssl_ca_cert
|
132
|
+
attr_accessor :ssl_ca_file
|
138
133
|
|
139
134
|
### TLS/SSL setting
|
140
135
|
# Client certificate file (for client certificate)
|
141
|
-
attr_accessor :
|
136
|
+
attr_accessor :ssl_client_cert
|
142
137
|
|
143
138
|
### TLS/SSL setting
|
144
139
|
# Client private key file (for client certificate)
|
145
|
-
attr_accessor :
|
140
|
+
attr_accessor :ssl_client_key
|
141
|
+
|
142
|
+
### Proxy setting
|
143
|
+
# HTTP Proxy settings
|
144
|
+
attr_accessor :proxy
|
146
145
|
|
147
|
-
# Set this to customize parameters
|
148
|
-
# Default to nil.
|
146
|
+
# Set this to customize parameters encoder of array parameter.
|
147
|
+
# Default to nil. Faraday uses NestedParamsEncoder when nil.
|
149
148
|
#
|
150
|
-
# @see The
|
151
|
-
# https://github.com/
|
152
|
-
attr_accessor :
|
149
|
+
# @see The params_encoder option of Faraday. Related source code:
|
150
|
+
# https://github.com/lostisland/faraday/tree/main/lib/faraday/encoders
|
151
|
+
attr_accessor :params_encoder
|
153
152
|
|
154
153
|
|
155
154
|
attr_accessor :inject_format
|
@@ -167,12 +166,17 @@ module Cheminee
|
|
167
166
|
@api_key = {}
|
168
167
|
@api_key_prefix = {}
|
169
168
|
@client_side_validation = true
|
170
|
-
@
|
171
|
-
@
|
172
|
-
@
|
173
|
-
@
|
174
|
-
@
|
175
|
-
@
|
169
|
+
@ssl_verify = true
|
170
|
+
@ssl_verify_mode = nil
|
171
|
+
@ssl_ca_file = nil
|
172
|
+
@ssl_client_cert = nil
|
173
|
+
@ssl_client_key = nil
|
174
|
+
@middlewares = Hash.new { |h, k| h[k] = [] }
|
175
|
+
@configure_connection_blocks = []
|
176
|
+
@timeout = 60
|
177
|
+
# return data as binary instead of file
|
178
|
+
@return_binary_data = false
|
179
|
+
@params_encoder = nil
|
176
180
|
@debugging = false
|
177
181
|
@ignore_operation_servers = false
|
178
182
|
@inject_format = false
|
@@ -296,6 +300,86 @@ module Cheminee
|
|
296
300
|
url
|
297
301
|
end
|
298
302
|
|
303
|
+
# Configure Faraday connection directly.
|
304
|
+
#
|
305
|
+
# ```
|
306
|
+
# c.configure_faraday_connection do |conn|
|
307
|
+
# conn.use Faraday::HttpCache, shared_cache: false, logger: logger
|
308
|
+
# conn.response :logger, nil, headers: true, bodies: true, log_level: :debug do |logger|
|
309
|
+
# logger.filter(/(Authorization: )(.*)/, '\1[REDACTED]')
|
310
|
+
# end
|
311
|
+
# end
|
312
|
+
#
|
313
|
+
# c.configure_faraday_connection do |conn|
|
314
|
+
# conn.adapter :typhoeus
|
315
|
+
# end
|
316
|
+
# ```
|
317
|
+
#
|
318
|
+
# @param block [Proc] `#call`able object that takes one arg, the connection
|
319
|
+
def configure_faraday_connection(&block)
|
320
|
+
@configure_connection_blocks << block
|
321
|
+
end
|
322
|
+
|
323
|
+
def configure_connection(conn)
|
324
|
+
@configure_connection_blocks.each do |block|
|
325
|
+
block.call(conn)
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
# Adds middleware to the stack
|
330
|
+
def use(*middleware)
|
331
|
+
set_faraday_middleware(:use, *middleware)
|
332
|
+
end
|
333
|
+
|
334
|
+
# Adds request middleware to the stack
|
335
|
+
def request(*middleware)
|
336
|
+
set_faraday_middleware(:request, *middleware)
|
337
|
+
end
|
338
|
+
|
339
|
+
# Adds response middleware to the stack
|
340
|
+
def response(*middleware)
|
341
|
+
set_faraday_middleware(:response, *middleware)
|
342
|
+
end
|
343
|
+
|
344
|
+
# Adds Faraday middleware setting information to the stack
|
345
|
+
#
|
346
|
+
# @example Use the `set_faraday_middleware` method to set middleware information
|
347
|
+
# config.set_faraday_middleware(:request, :retry, max: 3, methods: [:get, :post], retry_statuses: [503])
|
348
|
+
# config.set_faraday_middleware(:response, :logger, nil, { bodies: true, log_level: :debug })
|
349
|
+
# config.set_faraday_middleware(:use, Faraday::HttpCache, store: Rails.cache, shared_cache: false)
|
350
|
+
# config.set_faraday_middleware(:insert, 0, FaradayMiddleware::FollowRedirects, { standards_compliant: true, limit: 1 })
|
351
|
+
# config.set_faraday_middleware(:swap, 0, Faraday::Response::Logger)
|
352
|
+
# config.set_faraday_middleware(:delete, Faraday::Multipart::Middleware)
|
353
|
+
#
|
354
|
+
# @see https://github.com/lostisland/faraday/blob/v2.3.0/lib/faraday/rack_builder.rb#L92-L143
|
355
|
+
def set_faraday_middleware(operation, key, *args, &block)
|
356
|
+
unless [:request, :response, :use, :insert, :insert_before, :insert_after, :swap, :delete].include?(operation)
|
357
|
+
fail ArgumentError, "Invalid faraday middleware operation #{operation}. Must be" \
|
358
|
+
" :request, :response, :use, :insert, :insert_before, :insert_after, :swap or :delete."
|
359
|
+
end
|
360
|
+
|
361
|
+
@middlewares[operation] << [key, args, block]
|
362
|
+
end
|
363
|
+
ruby2_keywords(:set_faraday_middleware) if respond_to?(:ruby2_keywords, true)
|
364
|
+
|
365
|
+
# Set up middleware on the connection
|
366
|
+
def configure_middleware(connection)
|
367
|
+
return if @middlewares.empty?
|
368
|
+
|
369
|
+
[:request, :response, :use, :insert, :insert_before, :insert_after, :swap].each do |operation|
|
370
|
+
next unless @middlewares.key?(operation)
|
371
|
+
|
372
|
+
@middlewares[operation].each do |key, args, block|
|
373
|
+
connection.builder.send(operation, key, *args, &block)
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
if @middlewares.key?(:delete)
|
378
|
+
@middlewares[:delete].each do |key, _args, _block|
|
379
|
+
connection.builder.delete(key)
|
380
|
+
end
|
381
|
+
end
|
382
|
+
end
|
299
383
|
|
300
384
|
end
|
301
385
|
end
|
data/lib/cheminee/version.rb
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,35 +1,63 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cheminee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.36
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xavier Lange
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: faraday
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.1
|
20
|
+
- - "<"
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
22
|
+
version: '3.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
20
27
|
- - ">="
|
21
28
|
- !ruby/object:Gem::Version
|
22
29
|
version: 1.0.1
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: faraday-multipart
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
23
40
|
type: :runtime
|
24
41
|
prerelease: false
|
25
42
|
version_requirements: !ruby/object:Gem::Requirement
|
26
43
|
requirements:
|
27
|
-
- - "
|
44
|
+
- - ">="
|
28
45
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: marcel
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
30
51
|
- - ">="
|
31
52
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
33
61
|
- !ruby/object:Gem::Dependency
|
34
62
|
name: rspec
|
35
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,7 +154,7 @@ files:
|
|
126
154
|
- lib/cheminee/version.rb
|
127
155
|
- openapi-generator-config.json
|
128
156
|
- openapi.json
|
129
|
-
- pkg/cheminee-0.1.
|
157
|
+
- pkg/cheminee-0.1.36.gem
|
130
158
|
- spec/api/default_api_spec.rb
|
131
159
|
- spec/api_client_spec.rb
|
132
160
|
- spec/configuration_spec.rb
|
data/pkg/cheminee-0.1.34.gem
DELETED
Binary file
|