aitu-wallet 0.0.3 → 0.0.6

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: 50f56be2eb2c5b736bfcf67261c4116162fa34dd421ac6bed2845d319010005d
4
- data.tar.gz: 7808f737f9fca6d7dfb8aa5b06ba0daf5c21571154555f319f99e6c8b21d923d
3
+ metadata.gz: 0a05c48c83f742e5510565e5ab662f58930016c7a9c0bb4598766e3bd4ac9ae4
4
+ data.tar.gz: 6e74d51fb7cb7e519ce211012655c6deadbc88df290aa62e6f250a8a2892b2b7
5
5
  SHA512:
6
- metadata.gz: 917169696555a3d7e3301e77dfe5347b6cb071f27be0b19b7a269bc2ee0a287de52eabcb4b94a61e0f5bcdcdaa30ebc4727f961db0758a0d23fb94862ef41b7f
7
- data.tar.gz: 69695e6dfb8582baff1521f05d95919ef246d54c82a750b31535574116228e9226af99750fd3acbf866e912a0453f56810d624eaddeb3afd667a6ca62f152381
6
+ metadata.gz: 8e5a886ca5006211cbf6b2824c27db62196d76db6ba040ff7a7c92874fda3d92f1e55029c27ff20433ac914238afd7fca5a9ea0661895f3d84faffbef1f295d1
7
+ data.tar.gz: f190786dfcebfc36ada95f41e41d6907182ca9354da91c63eb3fb7785ca496c20446f063aa90d105beb6ee341df4a9fe306a5f7c557b4f48248d609c19a09d5f
@@ -12,22 +12,47 @@ 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
18
  attr_accessor :handler, :auth_headers
18
19
 
19
- # creates connection to Aitu Wallet endpoints and sets basic auth headers
20
+ # Creates connection to Aitu Wallet endpoints and sets basic auth headers
21
+ #
22
+ # @param [String] login
23
+ # @param [String] password
20
24
  def initialize(login, password)
21
- @handler = Faraday.new(BASE_URL)
22
- @handler.basic_auth(login, password)
25
+ @handler = Faraday.new(BASE_URL) do |connection|
26
+ connection.request :authorization, :basic, login, password
27
+ end
23
28
  end
24
29
 
30
+ # Gets info about user's account
31
+ #
32
+ # @param [String] phone
33
+ # @return [Hash, NilClass]
25
34
  def get_user_info(phone)
26
35
  get_request(ENDPOINTS[:user] + "/#{phone}")
27
36
  end
28
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
+ )
48
+ end
49
+
29
50
  private
30
51
 
52
+ # Executes GET request to specified url
53
+ #
54
+ # @param [String] url
55
+ # @return [NilClass, Hash]
31
56
  def get_request(url)
32
57
  response = @handler.get(url)
33
58
 
@@ -38,5 +63,36 @@ module AituWallet
38
63
  nil
39
64
  end
40
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) do |request|
74
+ request.body = body.to_json
75
+ end
76
+
77
+ begin
78
+ JSON.parse(response.body) if response
79
+ rescue JSON::ParserError
80
+ puts "Not JSON body returned"
81
+ nil
82
+ end
83
+ end
84
+
85
+ # generates GetLinkRequest data for passport link building routines
86
+ #
87
+ # @param [String] phone
88
+ # @param [String] back_url
89
+ # @return [Hash]
90
+ def get_link_request_data(phone, back_url)
91
+ {
92
+ phone: phone,
93
+ partnerUrl: back_url,
94
+ scope: 0
95
+ }
96
+ end
41
97
  end
42
98
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AituWallet
4
- VERSION = '0.0.3'
4
+ VERSION = '0.0.6'
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.3
4
+ version: 0.0.6
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-27 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