move oauth token response parsing to QLineParser

This commit is contained in:
stve 2015-02-16 00:40:13 -05:00
parent c259665346
commit 1bd5ce1728
2 changed files with 12 additions and 4 deletions

View file

@ -1,3 +1,5 @@
require 'instapaper/http/qline_parser'
module Instapaper
module API
# Defines methods related to OAuth
@ -5,10 +7,7 @@ module Instapaper
# Gets an OAuth access token for a user.
def token(username, password)
response = perform_post_with_unparsed_response('/api/1/oauth/access_token', x_auth_username: username, x_auth_password: password, x_auth_mode: 'client_auth')
params = response.split('&')
values = params.map { |part| part.split('=') }.flatten
values.unshift('error') if values.length == 1
Hash[*values]
QLineParser.parse(response)
end
end
end

View file

@ -0,0 +1,9 @@
module Instapaper
class QLineParser
def self.parse(response)
values = response.split('&').map { |part| part.split('=') }.flatten
values.unshift('error') if values.length == 1
Hash[*values]
end
end
end