horoshop 0.1.0 → 0.1.2

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: a64a6410feb2bb998f34680aa0768fc75ea6e26c366bd6054912e9d37a3a27ab
4
- data.tar.gz: 42c5e3a7472d214181d7d728f0a66f3c840e57912272a28424b9e908b4cbd27c
3
+ metadata.gz: 2ccce93ac87e708256eb5c4b41d76300722cad6e4b4a45c35fe5bcbed4003764
4
+ data.tar.gz: d54aa725d46d2ef85d92d75c92787314071a9d7e628028d71d84f38c7b72bd6a
5
5
  SHA512:
6
- metadata.gz: 92bc03964277af1d198374f2850749c06f3b3329608dec8f8cd1df58545599e5c942f18ef0f9c0e544c6b27a00da597ca479fd4211d40b951726126f9e7c18bb
7
- data.tar.gz: 996143c53d82147bb31375f12b9608644f4e86729994789be94679e3501da0067e549ffc56cea0d9dcdd07ff70b380467b7bd6e373cc452abbd2dd2b688b80e7
6
+ metadata.gz: a7cff6a480c2b438bebe4dba6a97d908399c8d0abaeace43c1d51a25fede0265d2641a966a286f607fec04f2008d218f533cb5cc8b5d44714cbc7eeb3294dbed
7
+ data.tar.gz: 78fa16046734b3ceadd5d92ebbc6ef79b318ed99cfbc31c9c8d79df00f3e22574d06f0f602e14c300c49b8f915468c614d6656cf2a3bf7a668e235bcf8cc9d9b
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Denis
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,8 @@
1
+ This is gem used for exchange data with horoshop.ua internet shop constructor
2
+
3
+ Authorization usage, at first you must create instance of class Horoshop with valid params to connect
4
+
5
+ horoshop = Horoshop::Client.new(url: 'http://somesite.org', username: 'jhon', password: 'piterson')
6
+ Horoshop::Authotization.new(horoshop).authorize
7
+
8
+ After that you just use instance horoshop for all next requests.
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'connection'
4
+
5
+ module Horoshop
6
+ # Class for user authorization
7
+ class Authorization
8
+ include Connection
9
+ AUTH_URL = '/api/auth/'
10
+ EXPIRATION_TIME = 600
11
+
12
+ def initialize(horoshop)
13
+ @horoshop = horoshop
14
+ end
15
+
16
+ def authorize
17
+ response = post(horoshop: horoshop, url: AUTH_URL, body: body)
18
+ return response unless response['status'] == 'OK'
19
+
20
+ horoshop.token = response.dig('response', 'token')
21
+ horoshop.expiration_timestamp = Time.now + EXPIRATION_TIME
22
+ response
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :horoshop
28
+
29
+ def body
30
+ { login: horoshop.login, password: horoshop.password }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ module Horoshop
5
+ # Module for check connection
6
+ module Connection
7
+ ERROR = { 'status' => 'HTTP_ERROR', 'message' => 'UNKNOWN SERVER ERROR' }.freeze
8
+
9
+ def post(horoshop:, url:, body:)
10
+ connection(horoshop).post(url, body).body
11
+ rescue Faraday::Error
12
+ ERROR
13
+ end
14
+
15
+ def connection(horoshop)
16
+ @connection ||= Faraday.new(url: horoshop.url) do |faraday|
17
+ faraday.request :json
18
+ faraday.response :raise_error
19
+ faraday.response :json
20
+ faraday.adapter Faraday.default_adapter
21
+ end
22
+ end
23
+ end
24
+ end
data/lib/horoshop.rb CHANGED
@@ -2,25 +2,27 @@
2
2
 
3
3
  require_relative 'horoshop/authorization'
4
4
 
5
- # Base class used to store data about authentication
6
- class Horoshop
7
- attr_accessor :url, :login, :password, :token, :expiration_timestamp
5
+ module Horoshop
6
+ # Base class used to store data about authentication
7
+ class Client
8
+ attr_accessor :url, :login, :password, :token, :expiration_timestamp
8
9
 
9
- def initialize(url:, login:, password:)
10
- @url = url
11
- @login = login
12
- @password = password
13
- @token = nil
14
- @expiration_timestamp = nil
15
- end
10
+ def initialize(url:, login:, password:)
11
+ @url = url
12
+ @login = login
13
+ @password = password
14
+ @token = nil
15
+ @expiration_timestamp = nil
16
+ end
16
17
 
17
- def token_valid?
18
- return false if token.nil?
18
+ def token_valid?
19
+ return false if token.nil?
19
20
 
20
- expiration_timestamp < Time.now
21
- end
21
+ expiration_timestamp < Time.now
22
+ end
22
23
 
23
- def refresh_token!
24
- Horoshop::Authorization.new(self).authorize
24
+ def refresh_token!
25
+ Horoshop::Authorization.new(self).authorize
26
+ end
25
27
  end
26
28
  end
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.0
4
+ version: 0.1.2
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-22 00:00:00.000000000 Z
12
+ date: 2024-02-26 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
@@ -17,7 +17,11 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - LICENSE
21
+ - README.md
20
22
  - lib/horoshop.rb
23
+ - lib/horoshop/authorization.rb
24
+ - lib/horoshop/connection.rb
21
25
  homepage: https://github.com/dkru/horoshop
22
26
  licenses:
23
27
  - MIT