paxful_rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3d83bcacafbece339d1b8239f73b4dd44069d4cf6ac0c63f870ec78937d69f70
4
+ data.tar.gz: 609d51e4e639b922954fd6b451e187c756486a9af22991d78e2e2ed934f9472f
5
+ SHA512:
6
+ metadata.gz: 11c4231d8e486fb715d4a5d741752914a8ff620c521ed943dea9e4c78bc5418d1e72e295f79e08d9899bfccc355c8b9966ba73c1ee5a0ba3ec17e04ba0d60397
7
+ data.tar.gz: 8a382c3ce1e697d4d71065c754752fd0a0b48d0c4939c024bc7413732de5d0f0aa578a8e68818cd52169824922e034b94b2871a3312f066252243bb306a2cf0a
@@ -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.
@@ -0,0 +1,72 @@
1
+ # PaxfulRails
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_rails'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ ```bash
17
+ $ bundle
18
+ $ rails paxful_rails:install:migrations
19
+ $ rails db:migrate
20
+ ```
21
+
22
+ Or install it yourself as:
23
+ ```bash
24
+ $ gem install paxful_rails
25
+ ```
26
+
27
+ ### Configuration
28
+
29
+ Create an initializer in your Rails application:
30
+
31
+ ```
32
+ # config/initializers/paxful_rails.rb
33
+
34
+ PaxfulRails.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
+
@@ -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 = 'PaxfulRails'
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_rails .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,5 @@
1
+ module PaxfulRails
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module PaxfulRails
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,7 @@
1
+ module PaxfulRails
2
+ class ApplicationJob
3
+
4
+ include Sidekiq::Worker
5
+
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module PaxfulRails
2
+ class EnqueueCreateTradeJob < ApplicationJob
3
+
4
+ sidekiq_options retry: false
5
+
6
+ def perform(payload)
7
+ CreateTrade.(payload)
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+ module PaxfulRails
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: PaxfulRails.configuration.paxful_key,
10
+ secret: PaxfulRails.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,6 @@
1
+ module PaxfulRails
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module PaxfulRails
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ module PaxfulRails
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 PaxfulRails
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 PaxfulRails.configuration.on_sync_callback.present?
22
+ callback = PaxfulRails.configuration.on_sync_callback
23
+ callback.constantize.(trade)
24
+ end
25
+
26
+ trade
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Paxful rails</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= stylesheet_link_tag "paxful_rails/application", media: "all" %>
9
+ </head>
10
+ <body>
11
+
12
+ <%= yield %>
13
+
14
+ </body>
15
+ </html>
@@ -0,0 +1,2 @@
1
+ PaxfulRails::Engine.routes.draw do
2
+ end
@@ -0,0 +1,24 @@
1
+ class CreatePaxfulRailsTrades < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :paxful_rails_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_rails_trades, :trade_hash, unique: true
23
+ end
24
+ end
@@ -0,0 +1,17 @@
1
+ require "gem_config"
2
+ require "paxful_client"
3
+ require "sidekiq"
4
+
5
+ require "paxful_rails/engine"
6
+
7
+ module PaxfulRails
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
@@ -0,0 +1,5 @@
1
+ module PaxfulRails
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace PaxfulRails
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module PaxfulRails
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :paxful_rails do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,206 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paxful_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-19 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_rails_manifest.js
164
+ - app/assets/stylesheets/paxful_rails/application.css
165
+ - app/controllers/paxful_rails/application_controller.rb
166
+ - app/helpers/paxful_rails/application_helper.rb
167
+ - app/jobs/paxful_rails/application_job.rb
168
+ - app/jobs/paxful_rails/enqueue_create_trade_job.rb
169
+ - app/jobs/paxful_rails/sync_order_book_job.rb
170
+ - app/mailers/paxful_rails/application_mailer.rb
171
+ - app/models/paxful_rails/application_record.rb
172
+ - app/models/paxful_rails/trade.rb
173
+ - app/services/paxful_rails/create_trade.rb
174
+ - app/views/layouts/paxful_rails/application.html.erb
175
+ - config/routes.rb
176
+ - db/migrate/20201018043517_create_paxful_rails_trades.rb
177
+ - lib/paxful_rails.rb
178
+ - lib/paxful_rails/engine.rb
179
+ - lib/paxful_rails/version.rb
180
+ - lib/tasks/paxful_rails_tasks.rake
181
+ homepage: https://github.com/bloom-solutions/paxful_rails
182
+ licenses:
183
+ - MIT
184
+ metadata:
185
+ allowed_push_host: https://rubygems.org
186
+ post_install_message:
187
+ rdoc_options: []
188
+ require_paths:
189
+ - lib
190
+ required_ruby_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ required_rubygems_version: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - ">="
198
+ - !ruby/object:Gem::Version
199
+ version: '0'
200
+ requirements: []
201
+ rubyforge_project:
202
+ rubygems_version: 2.7.6
203
+ signing_key:
204
+ specification_version: 4
205
+ summary: Mountable engine that fetches completed paxful trades.
206
+ test_files: []