Skip to content

Instantly share code, notes, and snippets.

@jkamenik
Created June 25, 2013 19:06
Show Gist options
  • Select an option

  • Save jkamenik/5861400 to your computer and use it in GitHub Desktop.

Select an option

Save jkamenik/5861400 to your computer and use it in GitHub Desktop.

Revisions

  1. jkamenik created this gist Jun 25, 2013.
    28 changes: 28 additions & 0 deletions gattica_engine.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    # put this in /lib/autoload
    # Make sure /config/application.rb has a line `config.autoload_paths` which has /lib/autoload in it

    module Gattica
    class Engine

    def do_http_get(query_string)
    # fixes 1.9 compatibility with http
    response = @http.get(query_string, @headers)
    data = response.body

    # error checking
    if response.code != '200'
    case response.code
    when '400'
    raise GatticaError::AnalyticsError, response.body + " (status code: #{response.code})"
    when '401'
    raise GatticaError::InvalidToken, "Your authorization token is invalid or has expired (status code: #{response.code})"
    else # some other unknown error
    raise GatticaError::UnknownAnalyticsError, response.body + " (status code: #{response.code})"
    end
    end

    return data
    end

    end
    end