       when Giphy.HelpName then @getHelp state
       else @error state.msg, "Unrecognized Endpoint: #{state.endpoint}"
 
+  handleResponse: (state, err, uriCreator) ->
+    if err
+      @error state.msg, err
+    else
+      state.uri = uriCreator.call this
+      @sendResponse state
+
   sendResponse: (state) ->
-    @log "sendResponse:", state
+    @log 'sendResponse:', state
     if state.uri
       @sendMessage state.msg, state.uri
     else

        rating: process.env.HUBOT_GIPHY_DEFAULT_RATING
      }, state.options
      @api.search options, (err, res) =>
        if err
          @error state.msg, err
        else
          state.uri = @getRandomResult(res.data, (result) -> result.images.original.url)
          @sendResponse state
    else
      @getRandomUri state

  getIdUri: (state) ->
  getTranslateUri: (state) ->
  getRandomUri: (state) ->
  getTrendingUri: (state) ->
  getHelp: (state) ->

  getUri: (state) ->
    @log "getUri:", state
    switch state.endpoint
      when Giphy.SearchEndpointName then @getSearchUri state
      when Giphy.IdEndpointName then @getIdUri state

    if data and callback and data.length > 0
      callback(if data.length == 1 then data[0] else data[Math.floor(Math.random() * data.length)])

  getUriFromResult: (result) ->
    result.images.original.url

  getSearchUri: (state) ->
    @log 'getSearchUri:', state
    if state.args and state.args.length > 0
      options = merge {
        q: state.args,
