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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ccce93ac87e708256eb5c4b41d76300722cad6e4b4a45c35fe5bcbed4003764
4
- data.tar.gz: d54aa725d46d2ef85d92d75c92787314071a9d7e628028d71d84f38c7b72bd6a
3
+ metadata.gz: 04c4a172c11c73f0e5caa19d2314cdc1d3f93b49a812d1255b7ca10a76fdf34d
4
+ data.tar.gz: 1e3f2a461d69956a7e0512eeac5ee669e40df78be7d6d81785c29311fd231550
5
5
  SHA512:
6
- metadata.gz: a7cff6a480c2b438bebe4dba6a97d908399c8d0abaeace43c1d51a25fede0265d2641a966a286f607fec04f2008d218f533cb5cc8b5d44714cbc7eeb3294dbed
7
- data.tar.gz: 78fa16046734b3ceadd5d92ebbc6ef79b318ed99cfbc31c9c8d79df00f3e22574d06f0f602e14c300c49b8f915468c614d6656cf2a3bf7a668e235bcf8cc9d9b
6
+ metadata.gz: 0d644c98743e064bddc5963192b260a9bea92cc8b75698f8cf617d1c69285348a2d3f871e7ee2d3253c89985a3d0e54c1c8a7907ce617d30500fc64684c6f214
7
+ data.tar.gz: 8b9dcafc84a9a7f5920ff7679008bba22d93aec6586a0b19b1f2efca06c60af23ab08af228ad935532e15cc7ee272efb3be9d04d796e954f13c8b7f9dd18bdf4
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Denis
3
+ Copyright (c) 2024 Denys Krupenov
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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
- After that you just use instance horoshop for all next requests.
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
@@ -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.1.2
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-26 00:00:00.000000000 Z
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