Module: TwitterAuth::Dispatcher::Shared

Included in:
Basic, Oauth
Defined in:
lib/twitter_auth/dispatcher/shared.rb

Instance Method Summary collapse

Instance Method Details

#append_extension_to(path) ⇒ Object



4
5
6
7
8
# File 'lib/twitter_auth/dispatcher/shared.rb', line 4

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

#handle_response(response) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/twitter_auth/dispatcher/shared.rb', line 10

def handle_response(response)
  case response
  when Net::HTTPOK 
    begin
      JSON.parse(response.body)
    rescue JSON::ParserError
      response.body
    end
  else
    message = begin
      JSON.parse(response.body)['error']
    rescue JSON::ParserError
      if match = response.body.match(/<error>(.*)<\/error>/)
        match[1]
      else
        'An error occurred processing your Twitter request.'
      end
    end

    raise TwitterAuth::Dispatcher::Error, message
  end
end