class Wykop::Operations::Top

Public Class Methods

new(client) click to toggle source

Documentation: www.wykop.pl/dla-programistow/dokumentacja/#info6_8

# File lib/wykop/operations/top.rb, line 7
def initialize(client)
  @client = client
  @request = Wykop::Operations::Request.new(@client)
end

Public Instance Methods

replace_url( p = {} ) click to toggle source
# File lib/wykop/operations/top.rb, line 34
def replace_url( p = {} )
# def replace_url(banana = nil, potato = nil, year = nil, month = nil)
  standard_url = "#{@client.configuration.api_host}/banana/potato/param1/param2/appkey,#{@client.configuration.app_user_key}/userkey,#{@client.user_info['userkey']}"
  # Checking parameters existence and removing them from url, just in case
  if p.has_key?(:year)
    standard_url = standard_url.gsub(/param1/, p[:year].to_s)
  else
    standard_url = standard_url.gsub(/\/param1/, '')
  end
  if p.has_key?(:month)
    standard_url = standard_url.gsub(/param2/, p[:month].to_s)
  else
    standard_url = standard_url.gsub(/\/param2/, '')
  end
  return standard_url.gsub(/banana/, p[:banana]).gsub(/potato/, p[:potato])
end
top_date( p = {} ) click to toggle source
# File lib/wykop/operations/top.rb, line 19
def top_date( p = {} )
  if ! p.has_key?(:page); p[:page] = 0; end
  if ! p.has_key?(:month); p[:month] = 1; end
  if ! p.has_key?(:year); p[:year] = Chronic.parse('last year').strftime("%Y"); end
  q_url = replace_url({ :banana => 'top', :potato => 'date' }.merge(p))
  q_body = {'page' => p[:page]}
  @request.execute(q_url, q_body)
end
top_hits() click to toggle source
# File lib/wykop/operations/top.rb, line 28
def top_hits
  q_url = replace_url({ :banana => 'top', :potato => 'hits'})
  q_body = Hash.new
  @request.execute(q_url, q_body)
end
top_index( p = {} ) click to toggle source
# File lib/wykop/operations/top.rb, line 12
def top_index( p = {} )
  if ! p.has_key?(:year); p[:year] = Chronic.parse('last year').strftime("%Y"); end
  q_url = replace_url({ :banana => 'top', :potato => 'index', :year => p[:year]})
  q_body = Hash.new
  @request.execute(q_url, q_body)
end