Sha256: a3018b5429412fc51753c6b1a4c847985ee7c78c4f48f7228e4fd43265c905c3

Contents?: true

Size: 691 Bytes

Versions: 2

Compression:

Stored size: 691 Bytes

Contents

# coding: utf-8

module Ugigi
  class Parser
    def initialize
      @agent = Mechanize.new
      @agent.user_agent = "Ugigi Ruby #{Ugigi::VERSION}"
    end

    def fetch(args)
      params = Ugigi.serialize_parameter(args)
      page = @agent.get(URI.join(BASE_URL, params))
      data = JSON.parse(page.body)
      indexes = []
      data.each do |e|
        index = Index.new(e)
        indexes << index
      end
      return indexes
    end
    
    def total_count(args)
      params = Ugigi.serialize_parameter(args)
      page = @agent.get(URI.join(BASE_URL_NOAPI, params))
      return page.search(%{div[@class="info"]}).children[0].text.strip.split("/")[1].to_i
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ugigi-0.2 lib/ugigi/parser.rb
ugigi-0.1 lib/ugigi/parser.rb