Sha256: b393cbb8f23f3f33b1b59c7bad699cf46712963e63b8acabdba93481743ecf94

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

module Stocktwits
  module Dispatcher
    module Shared
      
      # def post!(status)
      #   self.post('/statuses/update.json', :status => status)
      # end

      def append_extension_to(path)
        path, query_string = *(path.split("?"))
        path << '.json' unless path.match(/\.(:?xml|json)\z/i)
        "#{path}#{"?#{query_string}" if query_string}"
      end

      def handle_response(response)
        case response
        when Net::HTTPOK 
          begin
            JSON.parse(response.body)
          rescue JSON::ParserError
            response.body
          end
        when Net::HTTPUnauthorized
          raise Stocktwits::Dispatcher::Unauthorized, 'The credentials provided did not authorize the user.'
        else
          message = begin
            JSON.parse(response.body)['error']
          rescue JSON::ParserError
            if match = response.body.match(/<error>(.*)<\/error>/)
              match[1]
            else
              raise response.body
              'An error occurred processing your Stocktwits request. '
            end
          end

          raise Stocktwits::Dispatcher::Error, message
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stocktwits-1.0.0 lib/stocktwits/dispatcher/shared.rb