paxful_engine-rails 0.2.0 → 0.6.0

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: d817baab866145e535dc28f7cc9a8031448e08ba21f4a9acfc36e0c179106cf9
4
- data.tar.gz: eb31ac85370223ea2d1236587209da31decd596ade63fb85f9e4d292a34b4be6
3
+ metadata.gz: 0a8eb298ea0c209e4536008d41eaea8d8f8290ebe238bf4c4788d2fcb79dc81a
4
+ data.tar.gz: d1875e3a006fed12babdc0c60d1bd88601de09358067def092511f2853beb7a1
5
5
  SHA512:
6
- metadata.gz: 804eea2db930ac5c49c68c8c874543c15330423f3465b0cd94542d57e3ad64fbc7d044ec88e3c62b7d128d02369bd5a719d488ed18d86a0e8550efc48c262baf
7
- data.tar.gz: 7e0b5ce157c1a3f0c0e39946af73e71c8606327ade9c8760f11f6e8fdf7eebfd3c0ad78cddeb24754d7e8f762d022886027207fa6abb8354f4257631754f20f6
6
+ metadata.gz: 4300ebed063c0ea02f589c79014dcab945eb0b626b307a375c5c7579661f6824ebdd9f4dea60b6bd457342018e9bd2ca0ccdb90a7a3d0410971c2e29b18d2ab5
7
+ data.tar.gz: ed060a7c6d0ef44422186eb219bba05ba8c2abd605d3511205caea16add0b7c5ba9bc9c9da76e1b280cdde969f791bbe3b0cbfb8cf37b25d46230aec761e4929
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,10 +55,28 @@ 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:
60
-
61
80
  ```
62
81
  # sidekiq_cron.yml
63
82
  refresh_paxful_order_book:
@@ -65,6 +84,10 @@ refresh_paxful_order_book:
65
84
  class: "PaxfulEngine::SyncOrderBookJob"
66
85
  ```
67
86
 
87
+ From the host app:
88
+ - Check list of trades at `/paxful_engine/trades`.
89
+ - Details per trade at `/paxful_engine/trades/:id`.
90
+
68
91
  ### Development
69
92
 
70
93
  ```
@@ -1,4 +1,10 @@
1
1
  module PaxfulEngine
2
2
  module ApplicationHelper
3
+
4
+ def highlight_status(trade)
5
+ status = trade.status.downcase
6
+ status == "successful" ? "text-success" : "text-danger"
7
+ end
8
+
3
9
  end
4
10
  end
@@ -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
@@ -1,3 +1,6 @@
1
+ <span class="font-weight-bold"> Found <%= pluralize(@trades.count, "trade") %></span>
2
+ <hr />
3
+
1
4
  <div class="table-responsive">
2
5
  <table class="table table-striped table-bordered">
3
6
  <thead>
@@ -12,12 +15,20 @@
12
15
  </tr>
13
16
  </thead>
14
17
  <tbody>
18
+ <% if @trades.empty? %>
19
+ <tr>
20
+ <td colspan="7"> No trades found </td>
21
+ </tr>
22
+ <% end %>
23
+
15
24
  <% @trades.each do |trade| %>
16
25
  <tr scope="row">
17
26
  <td> <%= trade.created_at.strftime("%m/%d/%Y %I:%M%p") %> </td>
18
27
  <td> <%= trade.trade_hash %> </td>
19
28
  <td> <%= trade.offer_type.upcase %> </td>
20
- <td> <%= trade.status.upcase %> </td>
29
+ <td>
30
+ <span class="<%= highlight_status(trade) %>"> <%= trade.status.upcase %> </span>
31
+ </td>
21
32
  <td> <%= trade.seller %> </td>
22
33
  <td> <%= trade.buyer %> </td>
23
34
  <td> <%= link_to "Check trade details", paxful_engine.trade_path(trade) %> </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.2.0'
2
+ VERSION = '0.6.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.2.0
4
+ version: 0.6.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-23 00:00:00.000000000 Z
11
+ date: 2020-11-04 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