Skip to content

Instantly share code, notes, and snippets.

@thdaraujo
Last active March 11, 2021 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thdaraujo/e3282390dd1a1af5deaed60829b12558 to your computer and use it in GitHub Desktop.
Save thdaraujo/e3282390dd1a1af5deaed60829b12558 to your computer and use it in GitHub Desktop.
Carbon-neutral Rails

Carbon-Neutral Rails

# Gemfile
gem 'patch_ruby'
require 'patch_ruby'

Patch.configure do |config|
  # get your API key on dashboard.patch.io
  config.access_token = '<API KEY>'
end
grams_of_co2 = 1_000
Patch::Order.create_order(mass_g: grams_of_co2)
order_total_cents_usd = 100_00

Patch::Order.create_order(
  total_price_cents_usd: order_total_cents_usd * 0.01
)
distance_in_meters = 100_000
package_mass_in_grams = 10_000

Patch::Estimate.create_shipping_estimate(
  distance_m: distance_in_meters,
  transportation_method: "air",
  package_mass_g: package_mass_in_grams
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment