Created
February 12, 2013 01:44
-
-
Save brianknapp/4759403 to your computer and use it in GitHub Desktop.
This is sample code for a CreateRequest object. I don't know exactly what this is supposed to do, so I'm going to make this up as I go. Hopefully it is helpful to show multiple jacks on one action.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreateRequest | |
def initialize request_jack, notification_jack, payment_jack | |
@request_jack = request_jack | |
@notification_jack = notification_jack | |
@payment_jack = payment_jack | |
end | |
def execute input | |
unless input.has_shape? user_id: Fixnum, text: String, amount: Float, who_to_notify: Fixnum | |
raise ArgumentError.new 'invalid input format' | |
end | |
# Create a Request entity an save it to some jack (so, DB) | |
data = { user_id: input[:user_id], text: input[:text] } | |
request = Request.new | |
request.populate data | |
request_data = @request_jack.save request.to_hash #returns a hash of the request data persisted | |
# Notify some one that a new Request exists (so, let's say email...also might create a notification object) | |
data = { who_to_notify: input[:who_to_notify], user_id: request_data[:user_id], text: request_data[:text] } | |
notification = Notification.new | |
notification.populate data | |
notification_data = @notification_jack.push notification.to_hash | |
# Handle payment for the Request (so, some payment processor stuff) | |
data = { amount: input[:amount], user_id: input[:user_id] } | |
payment = Payment.new | |
payment.populate data | |
payment_data = @payment_jack.purchase payment.to_hash | |
# I don't know what you want to return here, so return everything I guess | |
{ request_info: request_data, notification_info: notification_data, payment_info: payment_data } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment