mirror of
https://github.com/samsonjs/instapaper.git
synced 2026-04-27 14:57:44 +00:00
move oauth token response parsing to QLineParser
This commit is contained in:
parent
c259665346
commit
1bd5ce1728
2 changed files with 12 additions and 4 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
require 'instapaper/http/qline_parser'
|
||||||
|
|
||||||
module Instapaper
|
module Instapaper
|
||||||
module API
|
module API
|
||||||
# Defines methods related to OAuth
|
# Defines methods related to OAuth
|
||||||
|
|
@ -5,10 +7,7 @@ module Instapaper
|
||||||
# Gets an OAuth access token for a user.
|
# Gets an OAuth access token for a user.
|
||||||
def token(username, password)
|
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')
|
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('&')
|
QLineParser.parse(response)
|
||||||
values = params.map { |part| part.split('=') }.flatten
|
|
||||||
values.unshift('error') if values.length == 1
|
|
||||||
Hash[*values]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
9
lib/instapaper/http/qline_parser.rb
Normal file
9
lib/instapaper/http/qline_parser.rb
Normal 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
|
||||||
Loading…
Reference in a new issue