paxful_engine-rails 0.3.0 → 0.7.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: d152498f075ac905b808122006bc8049bc7f9f1dc3557aa28bef97adf27829b3
4
- data.tar.gz: 9ca59758c13c5228c5dc9a32b8e831df3281be2078679be82caf0d0627a198e1
3
+ metadata.gz: e1b07c79152a0e9d297bd7bd4e6895f3e594cd4b308028a4bc0a67ffe685075f
4
+ data.tar.gz: 880e805c345090fccc40d0555f4b07254d8375977693ff2f1228ffe79795e190
5
5
  SHA512:
6
- metadata.gz: 8f800fec47aea83992830ab7c1ae70eff5fa14a4810daee4328479bc489b12d2b0e5d1e899d0359da2dc7dfbf8e73a8237c9771c06c1576cf765cbd3a3c3ef7c
7
- data.tar.gz: 223f46864b93dce3fc966f9f15b12aa7a6e6aad550e62a1c104d5503313698f21a03eff66ebf1af3c3aba2b0e0d9ad4ac32abd5759420f4e4e8fe1f016f908d0
6
+ metadata.gz: 5a8cafa05d39f5b146b5220032498c67cda837844653a47f5c649eca38e0011b01a8098b822d62b02cda45fb8c517e06c01e54a17a3177b96de04e8063dfc383
7
+ data.tar.gz: 1faf67ac478fc2b17a0b257be6486c3389749c867cc003de0ba37aff4abee9f08a4cc2dabb7fee60b9d48adce9336777b45c78391dae1cf41488fe08a468e56d
data/README.md CHANGED
@@ -34,7 +34,8 @@ Create an initializer in your Rails application:
34
34
  PaxfulEngine.configure do |c|
35
35
  c.paxful_key = "your paxful key"
36
36
  c.paxful_secret = "your paxful secret"
37
- c.on_sync_callback = "YourCallback"
37
+ c.on_sync_callback = "SyncCallback"
38
+ c.on_failure_callback = "FailureCallback"
38
39
  end
39
40
  ```
40
41
 
@@ -45,7 +46,7 @@ It accepts a `Trade` as its only argument.
45
46
 
46
47
  ```
47
48
  # example
48
- class YourCallback
49
+ class SyncCallback
49
50
 
50
51
  def self.call(trade)
51
52
  # do anything you want with this record
@@ -54,6 +55,25 @@ class YourCallback
54
55
  end
55
56
  ```
56
57
 
58
+ #### c.on_failure_callback
59
+
60
+ An object that responds to `call` that gets executed when a trade cannot be created.
61
+
62
+ It accepts two arguments:
63
+ - exception
64
+ - payload
65
+
66
+ ```
67
+ # example
68
+ class FailureCallback
69
+
70
+ def self.call(e, payload)
71
+ # log somewhere...
72
+ end
73
+
74
+ end
75
+ ```
76
+
57
77
  ### Usage
58
78
 
59
79
  Add this to your scheduler somewhere:
@@ -2,7 +2,7 @@ module PaxfulEngine
2
2
  class TradesController < ApplicationController
3
3
 
4
4
  def index
5
- @trades = Trade.all
5
+ @trades = Trade.order("completed_at DESC, created_at DESC")
6
6
  end
7
7
 
8
8
  def show
@@ -17,5 +17,17 @@ module PaxfulEngine
17
17
  presence: true
18
18
  )
19
19
 
20
+ def successful?
21
+ status.downcase == "successful"
22
+ end
23
+
24
+ def buy?
25
+ offer_type.downcase == "buy"
26
+ end
27
+
28
+ def sell?
29
+ offer_type.downcase == "sell"
30
+ end
31
+
20
32
  end
21
33
  end
@@ -24,6 +24,12 @@ module PaxfulEngine
24
24
  end
25
25
 
26
26
  trade
27
+
28
+ rescue => exception
29
+ if PaxfulEngine.configuration.on_failure_callback.present?
30
+ callback = PaxfulEngine.configuration.on_failure_callback
31
+ callback.constantize.(exception, payload)
32
+ end
27
33
  end
28
34
 
29
35
  end
@@ -6,6 +6,7 @@
6
6
  <thead>
7
7
  <tr>
8
8
  <th scope="col">Created</th>
9
+ <th scope="col">Completed</th>
9
10
  <th scope="col">Trade hash</th>
10
11
  <th scope="col">Type</th>
11
12
  <th scope="col">Status</th>
@@ -24,6 +25,7 @@
24
25
  <% @trades.each do |trade| %>
25
26
  <tr scope="row">
26
27
  <td> <%= trade.created_at.strftime("%m/%d/%Y %I:%M%p") %> </td>
28
+ <td> <%= trade.completed_at&.strftime("%m/%d/%Y %I:%M%p") || "-" %> </td>
27
29
  <td> <%= trade.trade_hash %> </td>
28
30
  <td> <%= trade.offer_type.upcase %> </td>
29
31
  <td>
@@ -35,7 +35,10 @@
35
35
 
36
36
  <hr />
37
37
 
38
- <div> <strong>Status:</strong> <%= @trade.status.upcase %> </div>
38
+ <div>
39
+ <strong>Status:</strong>
40
+ <span class="<%= highlight_status(@trade) %>"> <%= @trade.status.upcase %> </span>
41
+ </div>
39
42
  <div> <strong>Payment Method:</strong> <%= @trade.payment_method_name %> </div>
40
43
  </div>
41
44
  </div>
@@ -12,6 +12,7 @@ module PaxfulEngine
12
12
  has :paxful_key, classes: [NilClass, String]
13
13
  has :paxful_secret, classes: [NilClass, String]
14
14
  has :on_sync_callback
15
+ has :on_failure_callback
15
16
  end
16
17
 
17
18
  end
@@ -0,0 +1,16 @@
1
+ FactoryBot.define do
2
+
3
+ factory :paxful_engine_trade, class: "PaxfulEngine::Trade" do
4
+ trade_hash { "trade-hash" }
5
+ offer_hash { "offer-hash" }
6
+ offer_type { "buy" }
7
+ crypto_amount_requested { 0.05 }
8
+ crypto_currency_code { "BTC" }
9
+ fiat_amount_requested { 1_000 }
10
+ fiat_currency_code { "PHP" }
11
+ started_at { Time.current }
12
+ ended_at { Time.current + 2.days }
13
+ status { "successful" }
14
+ end
15
+
16
+ end
@@ -1,3 +1,3 @@
1
1
  module PaxfulEngine
2
- VERSION = '0.3.0'
2
+ VERSION = '0.7.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paxful_engine-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Chavez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-24 00:00:00.000000000 Z
11
+ date: 2020-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_config
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '2.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: factory_bot_rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: pry
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -180,6 +194,7 @@ files:
180
194
  - lib/paxful_engine-rails.rb
181
195
  - lib/paxful_engine.rb
182
196
  - lib/paxful_engine/engine.rb
197
+ - lib/paxful_engine/factories.rb
183
198
  - lib/paxful_engine/version.rb
184
199
  - lib/tasks/paxful_engine_tasks.rake
185
200
  homepage: https://github.com/bloom-solutions/paxful_engine-rails