paxful_engine-rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +72 -0
- data/Rakefile +22 -0
- data/app/assets/config/paxful_engine_manifest.js +1 -0
- data/app/assets/stylesheets/paxful_engine/application.css +15 -0
- data/app/controllers/paxful_engine/application_controller.rb +5 -0
- data/app/helpers/paxful_engine/application_helper.rb +4 -0
- data/app/jobs/paxful_engine/application_job.rb +7 -0
- data/app/jobs/paxful_engine/enqueue_create_trade_job.rb +11 -0
- data/app/jobs/paxful_engine/sync_order_book_job.rb +24 -0
- data/app/mailers/paxful_engine/application_mailer.rb +6 -0
- data/app/models/paxful_engine/application_record.rb +5 -0
- data/app/models/paxful_engine/trade.rb +21 -0
- data/app/services/paxful_engine/create_trade.rb +30 -0
- data/app/views/layouts/paxful_engine/application.html.erb +15 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20201018043517_create_paxful_engine_trades.rb +24 -0
- data/lib/paxful_engine-rails.rb +1 -0
- data/lib/paxful_engine.rb +17 -0
- data/lib/paxful_engine/engine.rb +5 -0
- data/lib/paxful_engine/version.rb +3 -0
- data/lib/tasks/paxful_engine_tasks.rake +4 -0
- metadata +207 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6e703f7e6fbaf90b7f85cdb26beaf05aa92590fb7f42145c3177870ddffae27c
|
4
|
+
data.tar.gz: e6029b79a03f1acfee4310b6ae788710836c995dfb0a6a9a51bd2c2ebf448174
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 65344157341d2356b8efde3f789a0a2561cbf4283c252888bd826465d7b64df2e92587061913ef2c302ed5d5e0131b9031f9752caa70031b5cce9fc901f22791
|
7
|
+
data.tar.gz: bed2766b448c783a849a78f6fc069c8f1c0d3822981bbf63a0aa7ffad78ed4c179cc84b0a82e6a84ad57c70605aa55fa1cba5ba30110b1191dadb1e1a5ce517f
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2020 Mark Chavez
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# PaxfulEngine
|
2
|
+
|
3
|
+
A mountable Rails engine that saves completed trades from [paxful](https://paxful.com/)
|
4
|
+
marketplace and lets you do anything with it.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'paxful_engine-rails'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
```bash
|
17
|
+
$ bundle
|
18
|
+
$ rails paxful_engine:install:migrations
|
19
|
+
$ rails db:migrate
|
20
|
+
```
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
```bash
|
24
|
+
$ gem install paxful_engine-rails
|
25
|
+
```
|
26
|
+
|
27
|
+
### Configuration
|
28
|
+
|
29
|
+
Create an initializer in your Rails application:
|
30
|
+
|
31
|
+
```
|
32
|
+
# config/initializers/paxful_engine-rails.rb
|
33
|
+
|
34
|
+
PaxfulEngine.configure do |c|
|
35
|
+
c.paxful_key = "your paxful key"
|
36
|
+
c.paxful_secret = "your paxful secret"
|
37
|
+
c.on_sync_callback = "YourCallback"
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
#### c.on_sync_callback
|
42
|
+
|
43
|
+
An object that responds to `call` that gets executed after a trade is (re)processed.
|
44
|
+
It accepts a `Trade` as its only argument.
|
45
|
+
|
46
|
+
```
|
47
|
+
# example
|
48
|
+
class YourCallback
|
49
|
+
|
50
|
+
def self.call(trade)
|
51
|
+
# do anything you want with this record
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
### Development
|
58
|
+
|
59
|
+
```
|
60
|
+
$ rails db:migrate
|
61
|
+
$ rails db:migrate db:test:prepare
|
62
|
+
```
|
63
|
+
|
64
|
+
### Testing
|
65
|
+
|
66
|
+
```
|
67
|
+
$ bundle exec rspec spec
|
68
|
+
```
|
69
|
+
|
70
|
+
## License
|
71
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
72
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'PaxfulEngine'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
load 'rails/tasks/statistics.rake'
|
21
|
+
|
22
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1 @@
|
|
1
|
+
//= link_directory ../stylesheets/paxful_engine .css
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module PaxfulEngine
|
2
|
+
class SyncOrderBookJob < ApplicationJob
|
3
|
+
|
4
|
+
HOST = "https://paxful.com/api".freeze
|
5
|
+
|
6
|
+
def perform
|
7
|
+
client = PaxfulClient.new(
|
8
|
+
host: HOST,
|
9
|
+
key: PaxfulEngine.configuration.paxful_key,
|
10
|
+
secret: PaxfulEngine.configuration.paxful_secret,
|
11
|
+
)
|
12
|
+
|
13
|
+
response = client.get_completed_trades
|
14
|
+
return unless response.success?
|
15
|
+
|
16
|
+
trades = response.parsed_body["data"]["trades"]
|
17
|
+
|
18
|
+
trades.each do |payload|
|
19
|
+
EnqueueCreateTradeJob.perform_async(payload)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module PaxfulEngine
|
2
|
+
class Trade < ApplicationRecord
|
3
|
+
|
4
|
+
validates(
|
5
|
+
:trade_hash,
|
6
|
+
:offer_hash,
|
7
|
+
:offer_type,
|
8
|
+
:fiat_amount_requested,
|
9
|
+
:fiat_currency_code,
|
10
|
+
:crypto_amount_requested,
|
11
|
+
:crypto_currency_code,
|
12
|
+
:started_at,
|
13
|
+
:ended_at,
|
14
|
+
:seller,
|
15
|
+
:buyer,
|
16
|
+
:status,
|
17
|
+
presence: true
|
18
|
+
)
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module PaxfulEngine
|
2
|
+
class CreateTrade
|
3
|
+
|
4
|
+
def self.call(payload)
|
5
|
+
trade = Trade.where(trade_hash: payload["trade_hash"]).first_or_create! do |paxful_trade|
|
6
|
+
paxful_trade.offer_hash = payload["offer_hash"]
|
7
|
+
paxful_trade.offer_type = payload["offer_type"]
|
8
|
+
paxful_trade.fiat_amount_requested = BigDecimal(payload["fiat_amount_requested"])
|
9
|
+
paxful_trade.fiat_currency_code = payload["fiat_currency_code"]
|
10
|
+
paxful_trade.crypto_amount_requested = BigDecimal(payload["crypto_amount_requested"])
|
11
|
+
paxful_trade.crypto_currency_code = payload["crypto_currency_code"]
|
12
|
+
paxful_trade.payment_method_name = payload["payment_method_name"]
|
13
|
+
paxful_trade.started_at = payload["started_at"]
|
14
|
+
paxful_trade.ended_at = payload["ended_at"]
|
15
|
+
paxful_trade.seller = payload["seller"]
|
16
|
+
paxful_trade.buyer = payload["buyer"]
|
17
|
+
paxful_trade.completed_at = payload["completed_at"]
|
18
|
+
paxful_trade.status = payload["status"]
|
19
|
+
end
|
20
|
+
|
21
|
+
if PaxfulEngine.configuration.on_sync_callback.present?
|
22
|
+
callback = PaxfulEngine.configuration.on_sync_callback
|
23
|
+
callback.constantize.(trade)
|
24
|
+
end
|
25
|
+
|
26
|
+
trade
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
class CreatePaxfulEngineTrades < ActiveRecord::Migration[5.2]
|
2
|
+
def change
|
3
|
+
create_table :paxful_engine_trades do |t|
|
4
|
+
t.column :trade_hash, :string, null: false
|
5
|
+
t.column :offer_hash, :string, null: false
|
6
|
+
t.column :offer_type, :string, null: false
|
7
|
+
t.column :fiat_amount_requested, :decimal, null: false
|
8
|
+
t.column :fiat_currency_code, :string, null: false
|
9
|
+
t.column :crypto_amount_requested, :decimal, null: false
|
10
|
+
t.column :crypto_currency_code, :string, null: false
|
11
|
+
t.column :started_at, :datetime, null: false
|
12
|
+
t.column :ended_at, :datetime, null: false
|
13
|
+
t.column :completed_at, :datetime
|
14
|
+
t.column :seller, :string, null: false
|
15
|
+
t.column :buyer, :string, null: false
|
16
|
+
t.column :status, :string, null: false
|
17
|
+
t.column :payment_method_name, :string
|
18
|
+
|
19
|
+
t.timestamps
|
20
|
+
end
|
21
|
+
|
22
|
+
add_index :paxful_engine_trades, :trade_hash, unique: true
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "paxful_engine"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "gem_config"
|
2
|
+
require "paxful_client"
|
3
|
+
require "sidekiq"
|
4
|
+
|
5
|
+
require "paxful_engine/engine"
|
6
|
+
|
7
|
+
module PaxfulEngine
|
8
|
+
|
9
|
+
include GemConfig::Base
|
10
|
+
|
11
|
+
with_configuration do
|
12
|
+
has :paxful_key, classes: [NilClass, String]
|
13
|
+
has :paxful_secret, classes: [NilClass, String]
|
14
|
+
has :on_sync_callback
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,207 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paxful_engine-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mark Chavez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-10-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: gem_config
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.3.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.3.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: paxful_client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.3.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.3.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sidekiq
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: dotenv
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.5'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.5'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
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'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec-rails
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: sqlite3
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: vcr
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: webmock
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
description: Mountable engine that fetches completed paxful trades.
|
154
|
+
email:
|
155
|
+
- mjfchavez@gmail.com
|
156
|
+
executables: []
|
157
|
+
extensions: []
|
158
|
+
extra_rdoc_files: []
|
159
|
+
files:
|
160
|
+
- MIT-LICENSE
|
161
|
+
- README.md
|
162
|
+
- Rakefile
|
163
|
+
- app/assets/config/paxful_engine_manifest.js
|
164
|
+
- app/assets/stylesheets/paxful_engine/application.css
|
165
|
+
- app/controllers/paxful_engine/application_controller.rb
|
166
|
+
- app/helpers/paxful_engine/application_helper.rb
|
167
|
+
- app/jobs/paxful_engine/application_job.rb
|
168
|
+
- app/jobs/paxful_engine/enqueue_create_trade_job.rb
|
169
|
+
- app/jobs/paxful_engine/sync_order_book_job.rb
|
170
|
+
- app/mailers/paxful_engine/application_mailer.rb
|
171
|
+
- app/models/paxful_engine/application_record.rb
|
172
|
+
- app/models/paxful_engine/trade.rb
|
173
|
+
- app/services/paxful_engine/create_trade.rb
|
174
|
+
- app/views/layouts/paxful_engine/application.html.erb
|
175
|
+
- config/routes.rb
|
176
|
+
- db/migrate/20201018043517_create_paxful_engine_trades.rb
|
177
|
+
- lib/paxful_engine-rails.rb
|
178
|
+
- lib/paxful_engine.rb
|
179
|
+
- lib/paxful_engine/engine.rb
|
180
|
+
- lib/paxful_engine/version.rb
|
181
|
+
- lib/tasks/paxful_engine_tasks.rake
|
182
|
+
homepage: https://github.com/bloom-solutions/paxful_engine-rails
|
183
|
+
licenses:
|
184
|
+
- MIT
|
185
|
+
metadata:
|
186
|
+
allowed_push_host: https://rubygems.org
|
187
|
+
post_install_message:
|
188
|
+
rdoc_options: []
|
189
|
+
require_paths:
|
190
|
+
- lib
|
191
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
192
|
+
requirements:
|
193
|
+
- - ">="
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: '0'
|
196
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
197
|
+
requirements:
|
198
|
+
- - ">="
|
199
|
+
- !ruby/object:Gem::Version
|
200
|
+
version: '0'
|
201
|
+
requirements: []
|
202
|
+
rubyforge_project:
|
203
|
+
rubygems_version: 2.7.6
|
204
|
+
signing_key:
|
205
|
+
specification_version: 4
|
206
|
+
summary: Mountable engine that fetches completed paxful trades.
|
207
|
+
test_files: []
|