Sha256: 4e01a2444d543b72d45c504e14e6e6e0fd3a867fac1a5c18b9d8083a9f524df7
Contents?: true
Size: 1.46 KB
Versions: 2
Compression:
Stored size: 1.46 KB
Contents
# coding: utf-8 require "kconv" require "nokogiri" require "net/http" require "time" require "uri" $LOAD_PATH.unshift(File.expand_path("../", __FILE__)) require "sosowa/version" require "sosowa/scheme" require "sosowa/parser" module Sosowa BASE_URL = URI.parse("http://coolier.sytes.net:8080/sosowa/ssw_l/") protected # @param [Hash] parameter # @return [String] URL Serialized parameters def self.serialize_parameter(parameter, add_prefix=true) return "" unless parameter.class == Hash ant = Hash.new parameter.each do |key, value| ant[key.to_sym] = value.to_s end param = ant.inject(""){|k,v|k+"&#{v[0]}=#{URI.escape(v[1])}"} if add_prefix param.sub!(/^&/,"?") else param.sub!(/^&/,"") end return param ? param : "" end def self.send_req(args) params = serialize_parameter(args) path = File.join(BASE_URL.path, params) pp path Net::HTTP.version_1_2 Net::HTTP.start(BASE_URL.host, BASE_URL.port) do |http| response = http.get(path, 'User-Agent' => "Sosowa Ruby Wrapper #{Sosowa::VERSION}") return Nokogiri::HTML(response.body.toutf8) end return false end public def self.get(args={}) args[:log] ||= 0 parser = Parser.new if args.has_key?(:key) parser.fetch_novel(args[:log], args[:key]) else parser.fetch_index(args[:log]) end end def self.search(query, args={}) parser = Parser.new parser.search(query, args) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sosowa-1.1.1 | lib/sosowa.rb |
sosowa-1.1 | lib/sosowa.rb |