Class: OAuth::Consumer

Inherits:
Object
  • Object
show all
Defined in:
lib/muck_oauth/services/yahoo_token.rb

Instance Method Summary collapse

Instance Method Details

#token_request(http_method, path, token = nil, request_options = {}, *arguments) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/muck_oauth/services/yahoo_token.rb', line 85

def token_request(http_method, path, token = nil, request_options = {}, *arguments)
  response = request(http_method, path, token, request_options, *arguments)

  case response.code.to_i

  when (200..299)
    # symbolize keys
    # TODO this could be considered unexpected behavior; symbols or not?
    # TODO this also drops subsequent values from multi-valued keys

    CGI.parse(response.body.strip).inject({}) do |h,(k,v)|
      h[k.to_sym] = v.first
      h[k]        = v.first
      h
    end
  when (300..399)
    # this is a redirect
    response.error!
  when (400..499)
    raise OAuth::Unauthorized, response
  else
    response.error!
  end
end