class YahooKeyphraseApi::KeyPhrase
Public Class Methods
new(appid = YahooKeyphraseApi::Config.app_id)
click to toggle source
initializer if creating a new Yahoo Keyphrase API client @param appid Yahoo APP id
# File lib/yahoo_keyphrase_api.rb, line 28 def initialize(appid = YahooKeyphraseApi::Config.app_id) @app_key = appid raise YahooKeyPhraseApiError.new('please set app key before use') unless @app_key end
Public Instance Methods
extract(sentence='', method=:POST)
click to toggle source
Retrieve a keyphrase @param sentence @param method :GET or :POST @return hash
# File lib/yahoo_keyphrase_api.rb, line 37 def extract(sentence='', method=:POST) if method == :GET response = HTTParty.get("#{SITE_URL}?appid=#{@app_key}&sentence=#{URI.escape(sentence)}&output=json") response.body elsif method == :POST response = HTTParty.post("#{SITE_URL}", { body: { appid: @app_key, sentence: sentence, output: 'json' } }) # 413 Request Entity Too Large raise YahooKeyPhraseApiError.new(response.message) if response.code == 413 Hashie::Mash.new MultiJson.decode(response.body) else # invalid arguments raise YahooKeyPhraseApiError.new('invalid request method') end end