mirror of
https://github.com/samsonjs/instapaper.git
synced 2026-03-25 08:55:49 +00:00
keys don't need to be symbolized
This commit is contained in:
parent
4c9319b67c
commit
09f39c2715
4 changed files with 6 additions and 30 deletions
|
|
@ -9,7 +9,7 @@ module Instapaper
|
|||
def access_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')
|
||||
parsed_response = QLineParser.parse(response)
|
||||
fail Instapaper::Error::OAuthError, parsed_response[:error] if parsed_response.key?(:error)
|
||||
fail Instapaper::Error::OAuthError, parsed_response['error'] if parsed_response.key?('error')
|
||||
Instapaper::Credentials.new(parsed_response)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,13 +1,9 @@
|
|||
require 'instapaper/utils'
|
||||
|
||||
module Instapaper
|
||||
class QLineParser
|
||||
extend Instapaper::Utils
|
||||
|
||||
def self.parse(response)
|
||||
values = response.split('&').map { |part| part.split('=') }.flatten
|
||||
values.unshift('error') if values.length == 1
|
||||
symbolize_keys!(Hash[*values])
|
||||
Hash[*values]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,12 +5,10 @@ require 'net/https'
|
|||
require 'openssl'
|
||||
require 'instapaper/error'
|
||||
require 'instapaper/http/headers'
|
||||
require 'instapaper/utils'
|
||||
|
||||
module Instapaper
|
||||
module HTTP
|
||||
class Request
|
||||
include Instapaper::Utils
|
||||
BASE_URL = 'https://www.instapaper.com'
|
||||
attr_accessor :client, :headers, :multipart, :options, :path,
|
||||
:rate_limit, :request_method, :uri
|
||||
|
|
@ -69,16 +67,16 @@ module Instapaper
|
|||
def error(response)
|
||||
return unless response.is_a?(Array)
|
||||
return unless response.size > 0
|
||||
return unless response.first[:type] == 'error'
|
||||
return unless response.first['type'] == 'error'
|
||||
|
||||
Instapaper::Error.from_response(response.first[:error_code], @path)
|
||||
Instapaper::Error.from_response(response.first['error_code'], @path)
|
||||
end
|
||||
|
||||
def parsed_response(response)
|
||||
@parsed_response ||= begin
|
||||
symbolize_keys!(response.parse)
|
||||
response.parse
|
||||
rescue
|
||||
response.to_s
|
||||
response.body
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,18 +0,0 @@
|
|||
module Instapaper
|
||||
module Utils
|
||||
private
|
||||
|
||||
def symbolize_keys!(object)
|
||||
if object.is_a?(Array)
|
||||
object.each_with_index do |val, index|
|
||||
object[index] = symbolize_keys!(val)
|
||||
end
|
||||
elsif object.is_a?(Hash)
|
||||
object.keys.each do |key|
|
||||
object[key.to_sym] = symbolize_keys!(object.delete(key))
|
||||
end
|
||||
end
|
||||
object
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue