aitu-wallet 0.0.2 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c2c064589dc9130d7efb2d4329766c8759abce83f9f038dd942f7cbfaa23898
4
- data.tar.gz: 14ec7ef585fee3ec24ee6740f4d3dc3e919a7bb223e90c24766b7e52bc791341
3
+ metadata.gz: 0c86fb8879482891aaa720e0b6674b333ffadcd7be30141971668a0d4bf25ffa
4
+ data.tar.gz: 5f0ea08c0041aaa95e133504f1ea3fe1c5e91c6df53fb760a353c341e3f3ab5e
5
5
  SHA512:
6
- metadata.gz: 014a02cdefad449074e47c4d2f401bc1c73d99a007277846611ab528e4c0b1a61dcb2fc74881555ba30ea78bfe2afc3bab47093c784306554db07080940d5c16
7
- data.tar.gz: a635643c35a042c022d92dd6ae7a65fd0f9768ceeb61e59abe77028aae46e93c397dd3dadb26dd058fe81ce8312f19100f16f605aefd4de740e8de4f054203c0
6
+ metadata.gz: e4386f0c655eb277d3a8669dab0263207e2264601fa56a610049ae39fdb4c3f1ffd92062e79a1bf691ce83f2f10998b63b541d1071c39c5dfa79628d006e223e
7
+ data.tar.gz: a834a403a5266e2f01a8fc8126bc54ba35b40a4c9fa4d56d4c4f0a8f8fcf9c5ae32d43efa70c2c4c14bfa7b83cd8f74417be343dc8e69565b04fe62877e0f183
@@ -12,27 +12,85 @@ module AituWallet
12
12
  passport: '/passport',
13
13
  service: '/ems/service'
14
14
  }
15
+
15
16
  # Client to send Aitu Wallet requests
16
17
  class Client
17
- attr_accessor :handler, :headers
18
+ attr_accessor :handler, :auth_headers
18
19
 
19
- def initialize(auth_token)
20
- @handler = Faraday.new
21
- @headers = { 'Authorization': "Basic #{auth_token}" }
20
+ # Creates connection to Aitu Wallet endpoints and sets basic auth headers
21
+ #
22
+ # @param [String] login
23
+ # @param [String] password
24
+ def initialize(login, password)
25
+ @handler = Faraday.new(BASE_URL) do |connection|
26
+ connection.request :authorization, :basic, login, password
27
+ end
22
28
  end
23
29
 
30
+ # Gets info about user's account
31
+ #
32
+ # @param [String] phone
33
+ # @return [Hash, NilClass]
24
34
  def get_user_info(phone)
25
- url = build_request_url(:user) + "/#{phone}"
26
- response = @handler.get(url, headers: @headers)
27
- JSON.parse(response) if response
35
+ get_request(ENDPOINTS[:user] + "/#{phone}")
36
+ end
37
+
38
+ # Builds link to crete Aitu Passport account
39
+ #
40
+ # @param [String] phone
41
+ # @param [String] back_url
42
+ # @return [Hash, NilClass]
43
+ def build_passport_link(phone, back_url)
44
+ post_request(
45
+ ENDPOINTS[:passport],
46
+ get_link_request_data(phone, back_url)
47
+ )
28
48
  end
29
49
 
30
50
  private
31
51
 
32
- def build_request_url(endpoint)
33
- raise StandardError, "No such endpoint: #{endpoint}" unless ENDPOINTS[endpoint]
52
+ # Executes GET request to specified url
53
+ #
54
+ # @param [String] url
55
+ # @return [NilClass, Hash]
56
+ def get_request(url)
57
+ response = @handler.get(url)
58
+
59
+ begin
60
+ JSON.parse(response.body) if response
61
+ rescue JSON::ParserError
62
+ puts "Not JSON body returned"
63
+ nil
64
+ end
65
+ end
66
+
67
+ # Performs POST request to specified URL with specified BODY payload
68
+ #
69
+ # @param [String] url
70
+ # @param [Hash] body
71
+ # @return [Hash, nil]
72
+ def post_request(url, body)
73
+ response = @handler.post(url, body: body)
74
+
75
+ begin
76
+ JSON.parse(response.body) if response
77
+ rescue JSON::ParserError
78
+ puts "Not JSON body returned"
79
+ nil
80
+ end
81
+ end
34
82
 
35
- BASE_URL + ENDPOINTS[endpoint]
83
+ # generates GetLinkRequest data for passport link building routines
84
+ #
85
+ # @param [String] phone
86
+ # @param [String] back_url
87
+ # @return [Hash]
88
+ def get_link_request_data(phone, back_url)
89
+ {
90
+ phone: phone,
91
+ partnerUrl: back_url,
92
+ scope: 0
93
+ }
36
94
  end
37
95
  end
38
96
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AituWallet
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.5'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aitu-wallet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yaroslav Shevchenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-25 00:00:00.000000000 Z
11
+ date: 2022-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake