mobius-client 0.2.0 → 0.2.1

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
  SHA1:
3
- metadata.gz: '089ee5fff823168d94b6f2f1cd79dd9b6090e0a2'
4
- data.tar.gz: 5ac58a65df84e1685a580d08606190ff043ec821
3
+ metadata.gz: aa4d61727ba66679c6a5089ec75012d4c87e1d24
4
+ data.tar.gz: a2418ab7d25c6f54e3f8e9a36800f8b929be5913
5
5
  SHA512:
6
- metadata.gz: 40edc08773d4849fb6d16a0c1c40311040df841b5e9d639c3960394c687a709294b6ac66bdabe69aea8f8a12ff55a763b32c3c57ef75bfaebe307dab4facd309
7
- data.tar.gz: 75981e88dfe7a15ab203bc90e712364643ff96091abf35fedb1e249d075f9f844705a2aa37a60d9dc03c8a7fdf2df9769aca0cd9825ad0a5ada62cdc2e1c37bb
6
+ metadata.gz: fbf295dd5c30ae4decfddad11da7f071a4b9840a648a1fd5a9ad190af01058e63e6db0d53c40fe2c38e90001c739f5081bbd48fa1542cb0c42b381211ab4930b
7
+ data.tar.gz: a89f53e9a33aba413fe7e53b0e71b737acdd7954315de9283f7876ca3c5f41358597f00a58ba9f5c151f308d9a2b10ce18cdfa6ee8f40197e2d8693263bc2fcd
@@ -31,6 +31,7 @@ class Mobius::Client::App
31
31
  # Makes payment.
32
32
  # @param amount [Float] Payment amount.
33
33
  # @param target_address [String] Optional: third party receiver address.
34
+ # rubocop:disable Metrics/AbcSize
34
35
  def pay(amount, target_address: nil)
35
36
  current_balance = balance
36
37
  raise Mobius::Client::Error::InsufficientFunds if current_balance < amount.to_f
@@ -38,11 +39,15 @@ class Mobius::Client::App
38
39
  post_tx(envelope_base64).tap do
39
40
  [app_account, user_account].each(&:reload!)
40
41
  end
42
+ rescue Faraday::ClientError => err
43
+ handle(err)
41
44
  end
45
+ # rubocop:enable Metrics/AbcSize
42
46
 
43
47
  # Sends money from application account to third party.
44
48
  # @param amount [Float] Payment amount.
45
49
  # @param address [String] Target address.
50
+ # rubocop:disable Metrics/AbcSize
46
51
  def transfer(amount, address)
47
52
  current_balance = app_balance
48
53
  raise Mobius::Client::Error::InsufficientFunds if current_balance < amount.to_f
@@ -50,7 +55,10 @@ class Mobius::Client::App
50
55
  post_tx(envelope_base64).tap do
51
56
  [app_account, user_account].each(&:reload!)
52
57
  end
58
+ rescue Faraday::ClientError => err
59
+ handle(err)
53
60
  end
61
+ # rubocop:enable Metrics/AbcSize
54
62
 
55
63
  private
56
64
 
@@ -132,5 +140,12 @@ class Mobius::Client::App
132
140
  @user_account ||= Mobius::Client::Blockchain::Account.new(user_keypair)
133
141
  end
134
142
 
143
+ def handle(err)
144
+ ops = err.response.dig(:body, "extras", "result_codes", "operations")
145
+ raise Mobius::Client::Error::AccountMissing if ops.include?("op_no_destination")
146
+ raise Mobius::Client::Error::TrustlineMissing if ops.include?("op_no_trust")
147
+ raise err
148
+ end
149
+
135
150
  FEE = 100
136
151
  end
@@ -1,5 +1,5 @@
1
1
  module Mobius
2
2
  module Client
3
- VERSION = "0.2.0".freeze
3
+ VERSION = "0.2.1".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobius-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Viktor Sokolov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-23 00:00:00.000000000 Z
11
+ date: 2018-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler