Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Christmas jumpers #430

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/static_pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def webfinger
# GET /cron.json
# GET /cron.xml
def cron
ChristmasJumperDonation.update
Track.update
BbcTwitter.update
PringlesPrice.update
Expand Down
31 changes: 28 additions & 3 deletions app/models/christmas_jumper_donation.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
class ChristmasJumperDonation
class ChristmasJumperDonation < ApplicationRecord

PROJECT = "pub-tracker-live"
BASE_URL = "https://firestore.googleapis.com/v1/projects/#{PROJECT}/databases/(default)/documents"
DONATIONS_URL = "https://api.justgiving.com/904af047/v1/fundraising/pages/cjd240033091/donations"


def self.get_donations
begin
response = JSON.parse(RestClient.get(DONATIONS_URL, accept: "application/json").body)
Expand All @@ -16,7 +17,19 @@ def self.get_donations


def self.set_christmas_jumper_hat user_id
puts "Give hat to #{user_id}"
data = {
"fields": {
"equipped": {
"mapValue": {
"fields": {
"hat": { "stringValue": "https://dyl.anjon.es/images/jumper.png" }
}
}
}
}
}
url = "#{BASE_URL}/profiles/#{user_id}?mask.fieldPaths=equipped.hat&updateMask.fieldPaths=equipped.hat"
response = RestClient.patch(url, data.to_json, content_type: :json)
end


Expand All @@ -34,8 +47,20 @@ def self.update_pub_thursday_user justgiving_name

def self.update
self.get_donations().each do |donation|
justgiving_id = donation["id"].to_s
justgiving_name = donation["donorDisplayName"]
self.update_pub_thursday_user(justgiving_name)
next if ChristmasJumperDonation.exists?(donation_id: justgiving_id)

begin
self.update_pub_thursday_user(justgiving_name)
rescue => e
logger.info "Failed to update pub thursday_user #{justgiving_name}: " + e.message
end

ChristmasJumperDonation.create({
donation_id: justgiving_id,
name: justgiving_name
})
end
return
end
Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20241211230936_create_christmas_jumper_donations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateChristmasJumperDonations < ActiveRecord::Migration[7.0]
def change
create_table :christmas_jumper_donations do |t|
t.string :donation_id
t.string :name

t.timestamps
end
end
end
30 changes: 29 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_08_07_225945) do
ActiveRecord::Schema[7.0].define(version: 2024_12_11_230936) do
create_table "accounts", id: :integer, charset: "utf8mb3", force: :cascade do |t|
t.string "number"
t.string "name"
Expand Down Expand Up @@ -154,6 +154,13 @@
t.index ["naptan_code"], name: "index_bus_stops_on_naptan_code"
end

create_table "christmas_jumper_donations", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t|
t.string "donation_id"
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "credentials", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t|
t.integer "user_id"
t.string "external_id"
Expand Down Expand Up @@ -191,6 +198,27 @@
t.datetime "updated_at", precision: nil
end

create_table "duo_leaderboards", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t|
t.string "name"
t.string "url"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["url"], name: "index_duo_leaderboards_on_url", unique: true
end

create_table "duo_leaderboards_participants", id: false, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t|
t.bigint "duo_participant_id", null: false
t.bigint "duo_leaderboard_id", null: false
t.index ["duo_participant_id", "duo_leaderboard_id"], name: "index_duo"
end

create_table "duo_participants", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t|
t.string "name"
t.string "photo"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "episodes", id: :integer, charset: "utf8mb3", force: :cascade do |t|
t.string "pid", null: false
t.string "title", null: false
Expand Down
Binary file modified public/images/jumper.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading