horoshop 0.1.2 → 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 +4 -4
- data/LICENSE +1 -1
- data/README.md +5 -2
- data/lib/horoshop/authorization.rb +1 -6
- data/lib/horoshop/base.rb +16 -0
- data/lib/horoshop/connection.rb +7 -1
- data/lib/horoshop/import_residues.rb +24 -0
- data/lib/horoshop.rb +6 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 04c4a172c11c73f0e5caa19d2314cdc1d3f93b49a812d1255b7ca10a76fdf34d
|
|
4
|
+
data.tar.gz: 1e3f2a461d69956a7e0512eeac5ee669e40df78be7d6d81785c29311fd231550
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0d644c98743e064bddc5963192b260a9bea92cc8b75698f8cf617d1c69285348a2d3f871e7ee2d3253c89985a3d0e54c1c8a7907ce617d30500fc64684c6f214
|
|
7
|
+
data.tar.gz: 8b9dcafc84a9a7f5920ff7679008bba22d93aec6586a0b19b1f2efca06c60af23ab08af228ad935532e15cc7ee272efb3be9d04d796e954f13c8b7f9dd18bdf4
|
data/LICENSE
CHANGED
data/README.md
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
This is gem used for exchange data with horoshop.ua internet shop constructor
|
|
2
2
|
|
|
3
3
|
Authorization usage, at first you must create instance of class Horoshop with valid params to connect
|
|
4
|
+
After that you just use instance horoshop for all next requests.
|
|
4
5
|
|
|
5
|
-
horoshop = Horoshop::Client.new(url: 'http://somesite.org', username: 'jhon', password: 'piterson')
|
|
6
|
+
horoshop = Horoshop::Client.new(url: URI.parse('http://somesite.org'), username: 'jhon', password: 'piterson')
|
|
7
|
+
|
|
6
8
|
Horoshop::Authotization.new(horoshop).authorize
|
|
9
|
+
Horoshop::ImportResidues.new(horoshop).import(hash)
|
|
7
10
|
|
|
8
|
-
|
|
11
|
+
*ImportResidues* returns all log data without OK status.
|
|
@@ -4,15 +4,10 @@ require_relative 'connection'
|
|
|
4
4
|
|
|
5
5
|
module Horoshop
|
|
6
6
|
# Class for user authorization
|
|
7
|
-
class Authorization
|
|
8
|
-
include Connection
|
|
7
|
+
class Authorization < ::Horoshop::Base
|
|
9
8
|
AUTH_URL = '/api/auth/'
|
|
10
9
|
EXPIRATION_TIME = 600
|
|
11
10
|
|
|
12
|
-
def initialize(horoshop)
|
|
13
|
-
@horoshop = horoshop
|
|
14
|
-
end
|
|
15
|
-
|
|
16
11
|
def authorize
|
|
17
12
|
response = post(horoshop: horoshop, url: AUTH_URL, body: body)
|
|
18
13
|
return response unless response['status'] == 'OK'
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'connection'
|
|
4
|
+
|
|
5
|
+
module Horoshop
|
|
6
|
+
# base class for all methods used in others classes
|
|
7
|
+
class Base
|
|
8
|
+
include Connection
|
|
9
|
+
attr_reader :horoshop
|
|
10
|
+
|
|
11
|
+
# @param {Horoshop::client}
|
|
12
|
+
def initialize(horoshop)
|
|
13
|
+
@horoshop = horoshop
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
data/lib/horoshop/connection.rb
CHANGED
|
@@ -6,7 +6,8 @@ module Horoshop
|
|
|
6
6
|
module Connection
|
|
7
7
|
ERROR = { 'status' => 'HTTP_ERROR', 'message' => 'UNKNOWN SERVER ERROR' }.freeze
|
|
8
8
|
|
|
9
|
-
def post(horoshop:, url:, body:)
|
|
9
|
+
def post(horoshop:, url:, body:, add_token: false)
|
|
10
|
+
mixin_token!(horoshop, body) if add_token
|
|
10
11
|
connection(horoshop).post(url, body).body
|
|
11
12
|
rescue Faraday::Error
|
|
12
13
|
ERROR
|
|
@@ -20,5 +21,10 @@ module Horoshop
|
|
|
20
21
|
faraday.adapter Faraday.default_adapter
|
|
21
22
|
end
|
|
22
23
|
end
|
|
24
|
+
|
|
25
|
+
def mixin_token!(horoshop, body)
|
|
26
|
+
horoshop.refresh_token! unless horoshop.token_valid?
|
|
27
|
+
body[:token] = horoshop.token
|
|
28
|
+
end
|
|
23
29
|
end
|
|
24
30
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Horoshop
|
|
4
|
+
# import_residues to the horoshop
|
|
5
|
+
class ImportResiduences < ::Horoshop::Base
|
|
6
|
+
URL = 'api/catalog/importResidues/'
|
|
7
|
+
STATUS_OK = 'OK'
|
|
8
|
+
|
|
9
|
+
# @param {Hash}
|
|
10
|
+
def call(body)
|
|
11
|
+
body = post(horoshop: horoshop, 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/horoshop.rb
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative 'horoshop/base'
|
|
4
|
+
require_relative 'horoshop/connection'
|
|
3
5
|
require_relative 'horoshop/authorization'
|
|
6
|
+
require_relative 'horoshop/import_residues'
|
|
4
7
|
|
|
5
8
|
module Horoshop
|
|
6
9
|
# Base class used to store data about authentication
|
|
7
10
|
class Client
|
|
8
11
|
attr_accessor :url, :login, :password, :token, :expiration_timestamp
|
|
9
12
|
|
|
13
|
+
# @param {URI} url
|
|
14
|
+
# @param {String} login
|
|
15
|
+
# @param {String}
|
|
10
16
|
def initialize(url:, login:, password:)
|
|
11
17
|
@url = url
|
|
12
18
|
@login = login
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: horoshop
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Denys Krupenov
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2024-02-
|
|
12
|
+
date: 2024-02-28 00:00:00.000000000 Z
|
|
13
13
|
dependencies: []
|
|
14
14
|
description: Gem for exchangedata with the internet shop constructor
|
|
15
15
|
email: dkru84@gmail.com
|
|
@@ -21,7 +21,9 @@ files:
|
|
|
21
21
|
- README.md
|
|
22
22
|
- lib/horoshop.rb
|
|
23
23
|
- lib/horoshop/authorization.rb
|
|
24
|
+
- lib/horoshop/base.rb
|
|
24
25
|
- lib/horoshop/connection.rb
|
|
26
|
+
- lib/horoshop/import_residues.rb
|
|
25
27
|
homepage: https://github.com/dkru/horoshop
|
|
26
28
|
licenses:
|
|
27
29
|
- MIT
|