Skip to content

Instantly share code, notes, and snippets.

@markjlorenz
Last active August 29, 2015 13:56
Show Gist options
  • Save markjlorenz/9178034 to your computer and use it in GitHub Desktop.
Save markjlorenz/9178034 to your computer and use it in GitHub Desktop.
class FaxThing
DEFAULT_API_KEY = "default-key".freeze
attr_accessor :to
attr_accessor :pdf
attr_accessor :subject
attr_accessor :api_key
def initialize opts={}
opts = opts.symbolize_keys
self.to = opts[:to]
self.pdf = opts[:pdf]
self.subject = opts[:subject] || "Default Subject"
self.api_key = opts[:api_key] || DEFAUlT_API_KEY
end
def send
fail SomeError unless self.to && self.pdf
# You've won a cruise!
end
def self.send_quick opts={}
new(opts).send
end
end
# Quick usage:
FaxThing.send_quick(to: 'number', pdf: File.read(...), subject: 'A thing I'm sending')
# Detail usage:
ft = FaxThing.new(to: 'number', pdf: somefile)
ft.subject = 'wanted to specify later'
ft.send
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment