Thanks for the quick reply Ilya. So basically I should try to keep everything in the API classes/sub-classes directly?
I ask because in our case, this class is shared across multiple endpoints. For example, we have a Call.create, and a Call.hangup which are accessed through separate goliath endpoints currently. Something like this for creation:
def response(env)
call = Call.create({
originator: env.params['originator'],
destination: env.params['destination'],
}, config, logger)
[200, {'Content-Type' => 'text/javascript'}, [{id:
call.id}.to_json]]
end
... and for hangup:
def response(env)
call = Call.find(env.params['id'], config, logger)
call.hangup!
[200, {'Content-Type' => 'text/javascript'}, []]
end
... notice that I pass in the config and logger vars so that I can access them from within the class.
I'm wrapping up functionality in this "Call" class because Call.create will create a call, send an api request to a freeswitch server, save the response, handle errors from freeswitch, etc. I also have several endpoints that use this same class to create different types of calls. TestCall, for example inherits from Call. I'm trying to keep from duplicating a lot of this functionality across endpoints.
I suppose I can make the Call class subclass Goliath::API directly. It just seemed a bit strange that my "model" class would inherit from the Goliath API class.
Am I just thinking about this wrong? Is Goliath::API intended for subclassing in this way?