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

Cleaned up examples and added documentation #1470

Merged
merged 2 commits into from
Oct 10, 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
9 changes: 7 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
From the examples folder, run:
`RUBYLIB=../lib ruby your_example.rb`

e.g.

`RUBYLIB=../lib ruby thinevent_webhook_handler.rb`

## Adding a new example

1. Clone new_example.rb
2. Implement your example
3. Run it (as per above)
4. 👍
3. Fill out the file comment. Include a description and key steps that are being demonstrated.
4. Run it (as per above)
5. 👍
36 changes: 36 additions & 0 deletions examples/example_template.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

# example_template.py - This is a template for defining new examples. It is not intended to be used directly.
#
# <describe what this example does>
#
# In this example, we:
# - <key step 1>
# - <key step 2
# - ...
#
# <describe assumptions about the user's stripe account, environment, or configuration;
# or things to watch out for when running>

require "stripe"
require "date"

class ExampleTemplate
attr_accessor :api_key

def initialize(api_key)
@api_key = api_key
end

def do_something_great
puts "Hello World"
# client = Stripe::StripeClient.new(api_key)
# client.v1
end
end

# Send meter events
api_key = "{{API_KEY}}"

example = ExampleTemplate.new(api_key)
example.do_something_great
10 changes: 10 additions & 0 deletions examples/meter_event_stream.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# frozen_string_literal: true

# meter_event_stream.py - use the high-throughput meter event stream to report create billing meter events.
#
# In this example, we:
# - create a meter event session and store the session's authentication token
# - define an event with a payload
# - use the meter_event_stream service accessor in StripeClient to create an event stream that reports this event
#
# This example expects a billing meter with an event_name of 'alpaca_ai_tokens'. If you have
# a different meter event name, you can change it before running this example.

require "stripe"
require "date"

Expand Down
24 changes: 0 additions & 24 deletions examples/new_example.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# frozen_string_literal: true
# typed: false

# thinevent_webhook_handler.rb - receive and process thin events like the
# v1.billing.meter.error_report_triggered event.
#
# In this example, we:
# - create a StripeClient called client
# - use client.parse_thin_event to parse the received thin event webhook body
# - call client.v2.core.events.retrieve to retrieve the full event object
# - if it is a V1BillingMeterErrorReportTriggeredEvent event type, call
# event.fetchRelatedObject to retrieve the Billing Meter object associated
# with the event.

require "stripe"
require "sinatra"

Expand Down
Loading