lib/valnzbn/lookup.rb in valnzbn-0.1.2 vs lib/valnzbn/lookup.rb in valnzbn-0.1.3

- old
+ new

@@ -1,6 +1,7 @@ require 'httparty' +require 'json' require 'redis-namespace' require_relative 'utils' class Valnzbn class Lookup @@ -40,19 +41,20 @@ if Valnzbn::Utils.valid_format?(number) cache = if @@cache_port && @@cache_host redis_client = Redis.new(host: @@cache_host, port: @@cache_port, db: 15) namespaced_redis = Redis::Namespace.new(:valnzbn_cache, redis: redis_client) - JSON.parse(namespaced_redis.get(number) || '{}') + JSON.parse(namespaced_redis.get(number) || '{}', symbolize_names: true) else {} end if cache.any? && Time.at(cache['expires_at']) > Time.now cache else begin response = HTTParty.get("#{url}#{number}", headers: { 'Authorization' => "Bearer #{@@access_token}" }).parsed_response + response = JSON.parse(response.to_json, symbolize_names: true) response[:expires_at] = (Time.now + 7200).to_i namespaced_redis.set(number, response.to_json) if @@cache_port && @@cache_host response rescue \ No newline at end of file