vesremont-api 0.2.0
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 +7 -0
- data/LICENSE +21 -0
- data/README.md +39 -0
- data/lib/vesremont_api.rb +108 -0
- metadata +52 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: e07ced12c291d62c82ec63a10fa8c7f52230f62bca85208f7915cc17752e7eff
|
|
4
|
+
data.tar.gz: e60ba737b7dcbe5351bd3fdf936dc50e0a2a05a060e8409e7ba948fb3d5a8fba
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 3d17a0c4bfdc0107b7e1a8367d43684898a27b699d6d8fe8904b48e5689fde570e06e0c0bbbc296e3d299f813f823cc7b4d03bbb51aa58527e969f204b23dac1
|
|
7
|
+
data.tar.gz: f334266d48d8739000855bfb170c144965d762f6846044d1eeec4701b75ea63319d3bd559eaa27972a5a3b5ab36bee03da1d25716a3ee7fc67fd416514de92a9
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vesremont
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Vesremont Ruby SDK 0.2.0
|
|
2
|
+
|
|
3
|
+
Ruby 3.3+, MIT, без сторонних runtime-зависимостей. Официальные исходники:
|
|
4
|
+
https://github.com/oooafganec-dev/vesremont-sdk/tree/main/ruby.
|
|
5
|
+
Команда установки опубликованного релиза из RubyGems:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
gem install vesremont-api --version 0.2.0
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Альтернатива — прямой gem с сайта Vesremont:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
curl -fLO https://vesremont.com/developers/downloads/vesremont-api-0.2.0.gem
|
|
15
|
+
gem install ./vesremont-api-0.2.0.gem --local
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```ruby
|
|
19
|
+
require 'vesremont_api'
|
|
20
|
+
api = Vesremont::Client.new
|
|
21
|
+
products = api.search('труборез', per_page: 10)
|
|
22
|
+
product = api.product(375094)
|
|
23
|
+
draft = api.cart_draft(375094, 1)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`status`, `search`, `product`, `cart`, `cart_draft` и общий
|
|
27
|
+
`request(method, path, query: {}, body: nil, idempotency_key: nil)`.
|
|
28
|
+
Путь относительно `/api/v1`, GET без body; JSON body — Hash.
|
|
29
|
+
Личные операции: `Vesremont::Client.new(token: token)` с уже полученным REST
|
|
30
|
+
OAuth token и минимальными scopes. OAuth мастер не дублируется (есть в Node CLI).
|
|
31
|
+
Схемы сервера: https://vesremont.com/openapi.json.
|
|
32
|
+
|
|
33
|
+
TLS проверяется; host фиксирован, redirects/автоматические повторы запрещены.
|
|
34
|
+
Timeout 15 секунд по умолчанию, максимум 60; тело до 64 KiB, ответ до 2 MiB.
|
|
35
|
+
`Vesremont::ApiError` содержит `status`, `code`, `request_id`, `retry_after` без
|
|
36
|
+
raw response. Не логируйте token, share_url и личные ответы. Для submit нужны
|
|
37
|
+
prepare, подтверждение покупателя и стабильный ключ; при сетевой ошибке сначала
|
|
38
|
+
перечитайте состояние. Это production API, не sandbox. Запускать с внешнего ПК,
|
|
39
|
+
не с сервера Vesremont. SDK не включает выключенные серверные интерфейсы.
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'net/http'
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'openssl'
|
|
5
|
+
require 'timeout'
|
|
6
|
+
|
|
7
|
+
module Vesremont
|
|
8
|
+
class ApiError < StandardError
|
|
9
|
+
attr_reader :status, :code, :request_id, :retry_after
|
|
10
|
+
def initialize(status, code, request_id = nil, retry_after = nil)
|
|
11
|
+
@status, @code, @request_id, @retry_after = status, code, request_id, retry_after
|
|
12
|
+
super("Vesremont: #{code} (HTTP #{status})")
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class Client
|
|
17
|
+
ORIGIN = 'https://vesremont.com/api/v1'
|
|
18
|
+
MAX_REPLY = 2 * 1024 * 1024
|
|
19
|
+
|
|
20
|
+
def initialize(token: '', timeout: 15)
|
|
21
|
+
raise ArgumentError, 'Invalid access token' unless token.is_a?(String) && (token.empty? || token.match?(/\A[A-Za-z0-9_.~-]{1,8192}\z/))
|
|
22
|
+
raise ArgumentError, 'Timeout must be 0..60 seconds' unless timeout.is_a?(Numeric) && timeout.positive? && timeout <= 60
|
|
23
|
+
@token, @timeout = token.dup.freeze, timeout
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def request(method, path, query: {}, body: nil, idempotency_key: nil)
|
|
27
|
+
raise ArgumentError, 'Invalid API method/path' unless %w[GET POST PATCH DELETE].include?(method) && path.is_a?(String) && path.match?(/\A\/[A-Za-z0-9_-]+(?:\/[A-Za-z0-9_-]+)*\/?\z/)
|
|
28
|
+
raise ArgumentError, 'JSON object required; GET body not supported' if !body.nil? && (method == 'GET' || !body.is_a?(Hash))
|
|
29
|
+
raise ArgumentError, 'Idempotency-Key is required' if method == 'POST' && path.delete_suffix('/') == '/orders/submit' && idempotency_key.nil?
|
|
30
|
+
if !idempotency_key.nil? && !(idempotency_key.is_a?(String) && idempotency_key.match?(/\A[A-Za-z0-9._:-]{16,128}\z/))
|
|
31
|
+
raise ArgumentError, 'Invalid idempotency key'
|
|
32
|
+
end
|
|
33
|
+
raise ArgumentError, 'Query must be a Hash' unless query.is_a?(Hash)
|
|
34
|
+
params = query.map do |name, value|
|
|
35
|
+
raise ArgumentError, 'Query values must be scalar' unless name.to_s.match?(/\A[a-z_]{1,40}\z/) && [String, Integer, Float, TrueClass, FalseClass].any? { |type| value.is_a?(type) }
|
|
36
|
+
[name.to_s, value.to_s]
|
|
37
|
+
end
|
|
38
|
+
encoded = URI.encode_www_form(params)
|
|
39
|
+
raise ArgumentError, 'Query exceeds 8192 characters' if encoded.bytesize > 8192
|
|
40
|
+
uri = URI(ORIGIN + path + (encoded.empty? ? '' : '?' + encoded))
|
|
41
|
+
payload = body.nil? ? nil : JSON.generate(body)
|
|
42
|
+
raise ArgumentError, 'Request body exceeds 64 KiB' if payload && payload.bytesize > 65536
|
|
43
|
+
req = Net::HTTPGenericRequest.new(method, !payload.nil?, true, uri.request_uri)
|
|
44
|
+
req['Accept'], req['User-Agent'] = 'application/json', 'Vesremont-Ruby/0.2.0'
|
|
45
|
+
req['Authorization'] = 'Bearer ' + @token unless @token.empty?
|
|
46
|
+
req['Idempotency-Key'] = idempotency_key unless idempotency_key.nil?
|
|
47
|
+
if payload
|
|
48
|
+
req['Content-Type'] = 'application/json'
|
|
49
|
+
req.body = payload
|
|
50
|
+
end
|
|
51
|
+
status, headers, raw = perform(uri, req)
|
|
52
|
+
begin
|
|
53
|
+
data = raw.empty? ? nil : JSON.parse(raw)
|
|
54
|
+
rescue JSON::ParserError
|
|
55
|
+
raise ApiError.new(status, 'invalid_json')
|
|
56
|
+
end
|
|
57
|
+
unless status.between?(200, 299)
|
|
58
|
+
problem = data.is_a?(Hash) ? data : {}
|
|
59
|
+
raise ApiError.new(status, safe(problem['code']) || 'http_error', safe(problem['request_id']), safe(headers['retry-after']))
|
|
60
|
+
end
|
|
61
|
+
data
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def status = request('GET', '/status')
|
|
65
|
+
def cart = request('GET', '/cart')
|
|
66
|
+
def search(q, **query) = request('GET', '/products', query: query.merge(q: q))
|
|
67
|
+
def product(id) = request('GET', "/products/#{product_id(id)}")
|
|
68
|
+
def cart_draft(id, quantity = 1, draft: nil)
|
|
69
|
+
raise ArgumentError, 'Quantity must be 1..99' unless quantity.is_a?(Integer) && quantity.between?(1, 99)
|
|
70
|
+
query = { product_id: product_id(id), quantity: quantity }
|
|
71
|
+
query[:draft] = draft unless draft.nil?
|
|
72
|
+
request('GET', '/cart-drafts/', query: query)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
private
|
|
76
|
+
|
|
77
|
+
def product_id(value)
|
|
78
|
+
raise ArgumentError, 'Positive product ID required' unless value.is_a?(Integer) && value.between?(1, 2_147_483_647)
|
|
79
|
+
value
|
|
80
|
+
end
|
|
81
|
+
def safe(value) = value.is_a?(String) && value.match?(/\A[A-Za-z0-9_.:-]{1,128}\z/) ? value : nil
|
|
82
|
+
|
|
83
|
+
def perform(uri, req)
|
|
84
|
+
http = Net::HTTP.new(uri.host, uri.port, nil)
|
|
85
|
+
http.use_ssl = true
|
|
86
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
87
|
+
http.open_timeout = http.read_timeout = http.write_timeout = @timeout
|
|
88
|
+
http.max_retries = 0
|
|
89
|
+
raw = +''
|
|
90
|
+
status = 0
|
|
91
|
+
headers = {}
|
|
92
|
+
Timeout.timeout(@timeout) do
|
|
93
|
+
http.start do |session|
|
|
94
|
+
session.request(req) do |response|
|
|
95
|
+
status, headers = response.code.to_i, response.to_hash.transform_values(&:first)
|
|
96
|
+
response.read_body do |chunk|
|
|
97
|
+
raise ApiError.new(status, 'response_too_large') if raw.bytesize + chunk.bytesize > MAX_REPLY
|
|
98
|
+
raw << chunk
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
[status, headers, raw]
|
|
104
|
+
rescue Timeout::Error, IOError, SystemCallError, SocketError, OpenSSL::SSL::SSLError, EOFError, Net::HTTPBadResponse, Net::ProtocolError
|
|
105
|
+
raise ApiError.new(0, 'transport_error')
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: vesremont-api
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.2.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Vesremont
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-10-05 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Vesremont catalog and buyer-authorized REST operations with verified
|
|
14
|
+
TLS and no redirects.
|
|
15
|
+
email:
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- LICENSE
|
|
21
|
+
- README.md
|
|
22
|
+
- lib/vesremont_api.rb
|
|
23
|
+
homepage: https://vesremont.com/developers/
|
|
24
|
+
licenses:
|
|
25
|
+
- MIT
|
|
26
|
+
metadata:
|
|
27
|
+
homepage_uri: https://vesremont.com/developers/
|
|
28
|
+
documentation_uri: https://vesremont.com/for_ai/api_ai/
|
|
29
|
+
source_code_uri: https://github.com/oooafganec-dev/vesremont-sdk/tree/main/ruby
|
|
30
|
+
bug_tracker_uri: https://github.com/oooafganec-dev/vesremont-sdk/issues
|
|
31
|
+
allowed_push_host: https://rubygems.org
|
|
32
|
+
rubygems_mfa_required: 'true'
|
|
33
|
+
post_install_message:
|
|
34
|
+
rdoc_options: []
|
|
35
|
+
require_paths:
|
|
36
|
+
- lib
|
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '3.3'
|
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
requirements: []
|
|
48
|
+
rubygems_version: 3.5.22
|
|
49
|
+
signing_key:
|
|
50
|
+
specification_version: 4
|
|
51
|
+
summary: Bounded REST client for the Vesremont public API
|
|
52
|
+
test_files: []
|