shop_express 0.0.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 +7 -0
- data/LICENSE +21 -0
- data/README.md +11 -0
- data/lib/shop_express/authorization.rb +28 -0
- data/lib/shop_express/base.rb +16 -0
- data/lib/shop_express/connection.rb +30 -0
- data/lib/shop_express/import_residues.rb +24 -0
- data/lib/shop_express.rb +34 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0f4f893058662a1ecae75107bb0e5aeadb98a6bf0e42f438c530654e0b5380e8
|
4
|
+
data.tar.gz: a3ceabf6340410701d8c83a32d03852951ebd91fa571d2e3e3c6b2c573f545bd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 05f5bac4f5e2c110aff3ec6a3096f4606783b15117a201adf5ef6f9ddf016d369766cfa5a59c0a9446da374db54dcb7b614f5cd461935b54f5eefdaaba3e3fb1
|
7
|
+
data.tar.gz: f5e9de20dbd3ae3cb2e219d324fb8fc365d7cfe80814ee2835723e7691f703d33489457ed9f5fb7a69e9276bed32fbd2e36fb822a65b8e9644a31c51e3b04b4a
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Denys Krupenov
|
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,11 @@
|
|
1
|
+
This is gem used for exchange data with shop-express.ua internet shop constructor
|
2
|
+
|
3
|
+
Authorization usage, at first you must create instance of class ShopExpress with valid params to connect
|
4
|
+
After that you just use instance shop_express for all next requests.
|
5
|
+
|
6
|
+
shop_express = ShopExpress::Client.new(url: URI.parse('http://somesite.org'), username: 'jhon', password: 'piterson')
|
7
|
+
|
8
|
+
ShopExpress::Authotization.new(shop_express).authorize
|
9
|
+
ShopExpress::ImportResidues.new(shop_express).import(hash)
|
10
|
+
|
11
|
+
*ImportResidues* returns all log data without OK status.
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'connection'
|
4
|
+
|
5
|
+
module ShopExpress
|
6
|
+
# Class for user authorization
|
7
|
+
class Authorization < ::ShopExpress::Base
|
8
|
+
AUTH_URL = '/api/auth/'
|
9
|
+
EXPIRATION_TIME = 600
|
10
|
+
|
11
|
+
def authorize
|
12
|
+
response = post(shop_express: shop_express, url: AUTH_URL, body: body)
|
13
|
+
return response unless response['status'] == 'OK'
|
14
|
+
|
15
|
+
shop_express.token = response.dig('response', 'token')
|
16
|
+
shop_express.expiration_timestamp = Time.now + EXPIRATION_TIME
|
17
|
+
response
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_reader :shop_express
|
23
|
+
|
24
|
+
def body
|
25
|
+
{ login: shop_express.login, password: shop_express.password }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'connection'
|
4
|
+
|
5
|
+
module ShopExpress
|
6
|
+
# base class for all methods used in others classes
|
7
|
+
class Base
|
8
|
+
include Connection
|
9
|
+
attr_reader :shop_express
|
10
|
+
|
11
|
+
# @param shop_express [ShopExpress::Client]
|
12
|
+
def initialize(shop_express)
|
13
|
+
@shop_express = shop_express
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
module ShopExpress
|
5
|
+
# Module for check connection
|
6
|
+
module Connection
|
7
|
+
ERROR = { 'status' => 'HTTP_ERROR', 'response' => { 'message' => 'UNKNOWN SERVER ERROR' } }.freeze
|
8
|
+
|
9
|
+
def post(shop_express:, url:, body:, add_token: false)
|
10
|
+
mixin_token!(shop_express, body) if add_token
|
11
|
+
connection(shop_express).post(url, body).body
|
12
|
+
rescue Faraday::Error
|
13
|
+
ERROR
|
14
|
+
end
|
15
|
+
|
16
|
+
def connection(shop_express)
|
17
|
+
@connection ||= Faraday.new(url: shop_express.url) do |faraday|
|
18
|
+
faraday.request :json
|
19
|
+
faraday.response :raise_error
|
20
|
+
faraday.response :json
|
21
|
+
faraday.adapter Faraday.default_adapter
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def mixin_token!(shop_express, body)
|
26
|
+
shop_express.refresh_token! unless shop_express.token_valid?
|
27
|
+
body[:token] = shop_express.token
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShopExpress
|
4
|
+
# import_residues to the shop_express
|
5
|
+
class ImportResiduences < ::ShopExpress::Base
|
6
|
+
URL = 'api/catalog/importResidues/'
|
7
|
+
STATUS_OK = 'OK'
|
8
|
+
|
9
|
+
# @param body [Hash]
|
10
|
+
def call(body)
|
11
|
+
body = post(shop_express: shop_express, url: URL, body: body, add_token: true)
|
12
|
+
parse_response(body)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def parse_response(body)
|
18
|
+
log = body.dig('response', 'log')
|
19
|
+
return [] unless log
|
20
|
+
|
21
|
+
log.filter { |el| el['status'] != STATUS_OK }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/shop_express.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'shop_express/base'
|
4
|
+
require_relative 'shop_express/connection'
|
5
|
+
require_relative 'shop_express/authorization'
|
6
|
+
require_relative 'shop_express/import_residues'
|
7
|
+
|
8
|
+
module ShopExpress
|
9
|
+
# Base class used to store data about authentication
|
10
|
+
class Client
|
11
|
+
attr_accessor :url, :login, :password, :token, :expiration_timestamp
|
12
|
+
|
13
|
+
# @param url [URI]
|
14
|
+
# @param login [String]
|
15
|
+
# @param password [String]
|
16
|
+
def initialize(url:, login:, password:)
|
17
|
+
@url = url
|
18
|
+
@login = login
|
19
|
+
@password = password
|
20
|
+
@token = nil
|
21
|
+
@expiration_timestamp = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def token_valid?
|
25
|
+
return false if token.nil?
|
26
|
+
|
27
|
+
expiration_timestamp < Time.now
|
28
|
+
end
|
29
|
+
|
30
|
+
def refresh_token!
|
31
|
+
ShopExpress::Authorization.new(self).authorize
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shop_express
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Denys Krupenov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-02-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.8'
|
27
|
+
description: Gem for exchange data with the internet shop CMS
|
28
|
+
email: dkru84@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- LICENSE
|
34
|
+
- README.md
|
35
|
+
- lib/shop_express.rb
|
36
|
+
- lib/shop_express/authorization.rb
|
37
|
+
- lib/shop_express/base.rb
|
38
|
+
- lib/shop_express/connection.rb
|
39
|
+
- lib/shop_express/import_residues.rb
|
40
|
+
homepage: https://github.com/dkru/shop_express
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata:
|
44
|
+
rubygems_mfa_required: 'true'
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.6.1
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubygems_version: 3.0.1
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: ShopExpress API interface
|
64
|
+
test_files: []
|