diff --git a/lib/instapaper/api/oauth.rb b/lib/instapaper/api/oauth.rb index d79a667..ec90793 100644 --- a/lib/instapaper/api/oauth.rb +++ b/lib/instapaper/api/oauth.rb @@ -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 diff --git a/lib/instapaper/http/qline_parser.rb b/lib/instapaper/http/qline_parser.rb new file mode 100644 index 0000000..6c7181c --- /dev/null +++ b/lib/instapaper/http/qline_parser.rb @@ -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