module FaradayMiddleware::Reddit::ModhashHelpers

Public Class Methods

included(base) click to toggle source
# File lib/faraday_middleware/reddit/helpers/modhash.rb, line 6
def self.included(base)
  base.dependency do
    require 'json' unless defined?(::JSON)
  end
end

Public Instance Methods

extract_modhash(env) click to toggle source
# File lib/faraday_middleware/reddit/helpers/modhash.rb, line 12
def extract_modhash(env)
  return unless env[:body].include?('modhash')

  body = env[:body]
  body = JSON.parse(body) if body.is_a?(String) && !body.strip.empty?
  body = body['json'] if body.is_a?(Hash) && body['json']
  body['data']['modhash'] if body.is_a?(Hash) && body['data']
end