-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a41a633
commit f32894c
Showing
7 changed files
with
110 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class PatreonPledge < ApplicationRecord | ||
def tier_name | ||
# decide tier name from pledge_amount_cents | ||
"pineapple master" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
class PatreonWebhookHandler | ||
def self.perform | ||
Notification.create! notification_type: "patreon_sub", send_to_chat: true, send_to_user: false | ||
def self.perform data | ||
pledge_amount_cents = data["attributes"]["pledge_amount_cents"] | ||
name = data["attributes"]["full_name"].split(" ").first | ||
pledge = PatreonPledge.create! json_blob: data, name: name, pledge_amount_cents: pledge_amount_cents | ||
Notification.create! notification_type: "patreon_sub", send_to_chat: true, send_to_user: false, source: pledge, user_id: 1 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreatePatreonPledges < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :patreon_pledges do |t| | ||
t.string :json_blob | ||
t.string :name | ||
t.integer :pledge_amount_cents | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'rails_helper' | ||
|
||
describe PatreonWebhookHandler do | ||
it 'saves the pledge to the db and sends a notification' do | ||
data = {"attributes"=> {"access_expires_at"=>nil, "campaign_currency"=>"USD", "campaign_lifetime_support_cents"=>12345, "campaign_pledge_amount_cents"=>50, "full_name"=>"Anthony Allen Miller", "is_follower"=>false, "is_free_member"=>nil, "is_free_trial"=>nil, "last_charge_date"=>"2014-04-01T00:00:00.000+00:00", "last_charge_status"=>"Paid", "lifetime_support_cents"=>12345, "patron_status"=>"active_patron", "pledge_amount_cents"=>50, "pledge_relationship_start"=>"2014-03-14T00:00:00.000+00:00"} , "id"=>nil, "relationships"=>{"address"=>{"data"=>{"id"=>"826453", "type"=>"address"}, "links"=>{"related"=>"https://www.patreon.com/api/addresses/826453"}}, "campaign"=>{"data"=>{"id"=>"205222", "type"=>"campaign"}, "links"=>{"related"=>"https://www.patreon.com/api/campaigns/205222"}}, "user"=>{"data"=>{"id"=>"1018897", "type"=>"user"}, "links"=>{"related"=>"https://www.patreon.com/api/user/1018897"}}}, "type"=>"member"} | ||
PatreonWebhookHandler.perform data | ||
expect(Notification.count).to eq 1 | ||
expect(Notification.last.notification_type).to eq "patreon_sub" | ||
end | ||
end |