paxful_engine-rails 0.3.1 → 0.8.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: 8df44a5546d1ad6fbc96a2c30e4eced34ece59789f990ec20312437cb7455475
4
- data.tar.gz: 291d93352b25277afd38aeb9c688b18a3275056193d0f71a6431ffb336f0a595
3
+ metadata.gz: 35b73b52c9292bc8440a16c5782d38f4a54be438f351c2c843887709d1561f24
4
+ data.tar.gz: dda35af7b33c326dccc2c56debf738ed65042b5d27eb55d7081599fb65ed41eb
5
5
  SHA512:
6
- metadata.gz: 81c7904bf5619df3167c3c7b146a63a1cb206b0a36ef57d117a1b3ae30a6728cebf22fd2fb9fe67ef951146e924d7491abfecc549415a2b1a8ab009889142f0e
7
- data.tar.gz: 8286ffba3c9c6bca34758d4ad47ac871b272115fd302ec76261323e8bfb892568ab949f50330c8f5dae2e4e1e90680729bffe48e37c8bdb7d1de9fdf534283dc
6
+ metadata.gz: d92645049bc6ec45b265d0e1575a959bf385dad892e3118bd2e46f38778a2df92d5843bc31847f3cb38d52949e1bb4722c03e06322f9501f978170ce515fd44a
7
+ data.tar.gz: 63213435b8c2ec813a332804845a939ed31d1fc30e4791b32eb38483a7aafe81a198e2e7ed2d59d39370e2755e06e37a29df5a6f8ea0558ae792f3a7c923ebbe
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,11 @@ 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
+
7
+ if params[:q] != "all"
8
+ @trades = @trades.where.not(completed_at: :nil)
9
+ end
6
10
  end
7
11
 
8
12
  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
@@ -1,4 +1,13 @@
1
- <span class="font-weight-bold"> Found <%= pluralize(@trades.count, "trade") %></span>
1
+ <span class="font-weight-bold"> Found <%= pluralize(@trades.count, "trade") %>.</span>
2
+
3
+ <div>
4
+ <% if params[:q] == "all" %>
5
+ <%= link_to "👀 Only show successful trades", trades_path %>
6
+ <% else %>
7
+ <%= link_to "👀 Include non-successful trades", trades_path(q: :all) %>
8
+ <% end %>
9
+ </div>
10
+
2
11
  <hr />
3
12
 
4
13
  <div class="table-responsive">
@@ -6,6 +15,7 @@
6
15
  <thead>
7
16
  <tr>
8
17
  <th scope="col">Created</th>
18
+ <th scope="col">Completed</th>
9
19
  <th scope="col">Trade hash</th>
10
20
  <th scope="col">Type</th>
11
21
  <th scope="col">Status</th>
@@ -24,6 +34,7 @@
24
34
  <% @trades.each do |trade| %>
25
35
  <tr scope="row">
26
36
  <td> <%= trade.created_at.strftime("%m/%d/%Y %I:%M%p") %> </td>
37
+ <td> <%= trade.completed_at&.strftime("%m/%d/%Y %I:%M%p") || "-" %> </td>
27
38
  <td> <%= trade.trade_hash %> </td>
28
39
  <td> <%= trade.offer_type.upcase %> </td>
29
40
  <td>
@@ -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.1'
2
+ VERSION = '0.8.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.1
4
+ version: 0.8.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-10 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