Skip to content

Instantly share code, notes, and snippets.

@prsanjay
Created April 12, 2019 05:01
Show Gist options
  • Save prsanjay/da4f4a20961df86fe2b75d041bc55064 to your computer and use it in GitHub Desktop.
Save prsanjay/da4f4a20961df86fe2b75d041bc55064 to your computer and use it in GitHub Desktop.
class ApplicationMailbox < ActionMailbox::Base
routing ->(inbound_email) { with_sku?(inbound_email) } => :price_finder
def self.with_sku?(inbound_email)
inbound_email.mail.subject.include?('SKU') || inbound_email.mail.body.include?('SKU')
end
end
class PriceFinderMailbox < ApplicationMailbox
def process
# Extract product_id and quantities
# Call API to get the price of the product
# total price = quantities * price
# Draft email and send this price to sender via email.
Quotation.with_price(mail.to.first).deliver_now
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment