class KSToken

Public Class Methods

new(app) click to toggle source
# File lib/kickscraper/connection.rb, line 6
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/kickscraper/connection.rb, line 10
def call(env)
  # replace '+' symbols in the query params with their original spaces, because there
  # seems to be a bug in the way some versions of Fararay escape parameters with spaces
  env[:url].query_params.each { |key, value|
    env[:url].query_params[key] = value.tr('+', ' ')
  }
  
  # add format=json to all public search requests, or add the oauth_token to all api requests once we have it
  if env[:url].to_s.index('https://api.kickstarter.com').nil?
    env[:url].query_params['format'] = 'json'
  else
    env[:url].query_params['oauth_token'] = Kickscraper.token unless Kickscraper.token.nil?
  end
  
  # make the call
  @app.call(env)
end