class YahooParseApi::Parse
parse ex. YahooParseApi::Parse.extract
Public Class Methods
new(appid = YahooParseApi::Config.app_id)
click to toggle source
initializer if creating a new Yahoo parse API client @param appid Yahoo APP id
# File lib/yahoo_parse_api.rb, line 27 def initialize(appid = YahooParseApi::Config.app_id) @app_key = appid raise YahooParseApiError.new('please set app key before use') unless @app_key end
Public Instance Methods
parse(sentence='', option={}, method=:GET)
click to toggle source
execute parse
@param [String] sentence @param [Hash] option yahoo parse api option see: developer.yahoo.co.jp/webapi/jlp/ma/v1/parse.html @param [Symbol] method :GET or :POST @return
# File lib/yahoo_parse_api.rb, line 38 def parse(sentence='', option={}, method=:GET) params = { appid: @app_key, sentence: sentence }.merge! option if method == :GET url = "#{SITE_URL}?" url << parameterize(params) HTTParty.get(url).parsed_response elsif method == :POST response = HTTParty.post("#{SITE_URL}", {body: params}) raise YahooParseApiError.new(response.message) if response.code == 413 response.parsed_response else # invalid arguments raise YahooParseApiError.new('invalid request method') end end
Private Instance Methods
parameterize(params)
click to toggle source
# File lib/yahoo_parse_api.rb, line 59 def parameterize(params) URI.escape(params.collect { |k, v| "#{k}=#{v}" }.join('&')) end