From 09f39c271518525c841c15ea7888b4e476a64ced Mon Sep 17 00:00:00 2001 From: stve Date: Sun, 30 Aug 2015 22:44:34 -0400 Subject: [PATCH] keys don't need to be symbolized --- lib/instapaper/api/oauth.rb | 2 +- lib/instapaper/http/qline_parser.rb | 6 +----- lib/instapaper/http/request.rb | 10 ++++------ lib/instapaper/utils.rb | 18 ------------------ 4 files changed, 6 insertions(+), 30 deletions(-) delete mode 100644 lib/instapaper/utils.rb diff --git a/lib/instapaper/api/oauth.rb b/lib/instapaper/api/oauth.rb index 0eeacc5..995eee8 100644 --- a/lib/instapaper/api/oauth.rb +++ b/lib/instapaper/api/oauth.rb @@ -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 diff --git a/lib/instapaper/http/qline_parser.rb b/lib/instapaper/http/qline_parser.rb index 557967f..6c7181c 100644 --- a/lib/instapaper/http/qline_parser.rb +++ b/lib/instapaper/http/qline_parser.rb @@ -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 diff --git a/lib/instapaper/http/request.rb b/lib/instapaper/http/request.rb index e318809..a5d8f73 100644 --- a/lib/instapaper/http/request.rb +++ b/lib/instapaper/http/request.rb @@ -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 diff --git a/lib/instapaper/utils.rb b/lib/instapaper/utils.rb deleted file mode 100644 index 617f6d9..0000000 --- a/lib/instapaper/utils.rb +++ /dev/null @@ -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