-
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathevent.rb
More file actions
67 lines (60 loc) · 2.22 KB
/
event.rb
File metadata and controls
67 lines (60 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# frozen_string_literal: true
module Strava
module Webhooks
module Models
#
# Represents a webhook event from Strava.
#
# After successfully creating a webhook subscription, Strava will send POST
# requests to your callback URL when activity events occur. Events include
# activity creation, updates, and deletions.
#
# @example Handle webhook event in Rails
# def webhook
# if request.post?
# event = Strava::Webhooks::Models::Event.new(JSON.parse(request.body.read))
#
# case event.object_type
# when 'activity'
# case event.aspect_type
# when 'create'
# # Fetch and process the new activity
# activity = client.activity(event.id)
# process_new_activity(activity)
# when 'update'
# # Handle activity update
# puts "Activity #{event.id} updated: #{event.updates.inspect}"
# when 'delete'
# # Handle activity deletion
# delete_activity(event.id)
# end
# when 'athlete'
# # Handle athlete updates (authorization revoked, etc.)
# end
#
# head :ok
# end
# end
#
# @see Strava::Webhooks::Client#create_push_subscription
# @see https://developers.strava.com/docs/webhooks/
#
class Event < Hashie::Trash
# @return [String] Type of object (e.g., "activity", "athlete")
property 'object_type'
# @return [Integer] ID of the object (activity ID, athlete ID, etc.)
property 'id', from: 'object_id'
# @return [String] Type of event: "create", "update", or "delete"
property 'aspect_type'
# @return [Hash] Map of updated properties (only for update events)
property 'updates'
# @return [Integer] Athlete ID who owns the object
property 'owner_id'
# @return [Integer] ID of the webhook subscription
property 'subscription_id'
# @return [Time] Timestamp when the event occurred
property 'event_time', transform_with: ->(v) { Time.at(v) }
end
end
end
end