Class: YahooKeyphraseApi::KeyPhrase
- Inherits:
-
Object
- Object
- YahooKeyphraseApi::KeyPhrase
- Defined in:
- lib/yahoo_keyphrase_api.rb
Instance Method Summary collapse
-
#extract(sentence = '', method = :POST) ⇒ Object
Retrieve a keyphrase.
-
#initialize(appid = YahooKeyphraseApi::Config.app_id) ⇒ KeyPhrase
constructor
initializer if creating a new Yahoo Keyphrase API client.
Constructor Details
#initialize(appid = YahooKeyphraseApi::Config.app_id) ⇒ KeyPhrase
initializer if creating a new Yahoo Keyphrase API client
28 29 30 31 |
# 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 |
Instance Method Details
#extract(sentence = '', method = :POST) ⇒ Object
Retrieve a keyphrase
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# 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.) if response.code == 413 Hashie::Mash.new MultiJson.decode(response.body) else # invalid arguments raise YahooKeyPhraseApiError.new('invalid request method') end end |