diff --git a/lib/se/api.rb b/lib/se/api.rb index 6e1b0bc..c2bb3a7 100644 --- a/lib/se/api.rb +++ b/lib/se/api.rb @@ -18,6 +18,8 @@ def initialize(key, **params) @params = params @quota = nil @quota_used = 0 + @logger_raw = Logger.new 'api_raw.log' + @logger_json = Logger.new 'api_json.log' end def posts(ids = "", **params) @@ -34,7 +36,9 @@ def json(uri, **params) params = @params.merge(params).merge({key: @key}).map { |k,v| "#{k}=#{v}" }.join('&') puts "Posting to https://api.stackexchange.com/#{API_VERSION}/#{uri}?#{params}" resp_raw = Net::HTTP.get_response(URI("https://api.stackexchange.com/#{API_VERSION}/#{uri}?#{params}")).body + @logger_raw.info "https://api.stackexchange.com/#{API_VERSION}/#{uri}?#{params} => #{resp_raw}" resp = JSON.parse(resp_raw) + @logger_raw.info "https://api.stackexchange.com/#{API_VERSION}/#{uri}?#{params} => #{resp}" @quota = resp["quota_remaining"] @quota_used += 1 resp["items"]