Skip to content

Instantly share code, notes, and snippets.

@electron0zero
Created June 16, 2020 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save electron0zero/ffe4a29e6ec93016237ef8a2cce26878 to your computer and use it in GitHub Desktop.
Save electron0zero/ffe4a29e6ec93016237ef8a2cce26878 to your computer and use it in GitHub Desktop.
Playing Around with httparty request logger and debug feature
# https://frontdeveloper.pl/2018/10/how-to-log-httparty-requests/#easy-footnote-3-298
require 'httparty'
require 'rails'
# Or wrap things up in your own class
class StackExchange
include HTTParty
# make sure logger is at info for HTTParty Logger to work
Rails.logger.level = 0
logger Rails.logger, :info, :logstash
# dumps extensive details
# debug_output Rails.logger
base_uri 'api.stackexchange.com'
def initialize(service, page)
@options = { query: { site: service, page: page } }
end
def questions
self.class.get("/2.2/questions", @options)
end
def users
self.class.get("/2.2/users", @options)
end
end
stack_exchange = StackExchange.new("stackoverflow", 1)
puts stack_exchange.questions
puts stack_exchange.users
require 'httparty'
stdout_logger = Logger.new(STDOUT)
stdout_logger.level = Logger::INFO
HTTParty::Logger(stdout_logger, :info, :logstash)
HTTParty.debug_output
response = HTTParty.get('http://api.stackexchange.com/2.2/questions?site=stackoverflow')
puts response.code, response.message, response.headers.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment