Class: YahooParseApi::Parse
- Inherits:
-
Object
- Object
- YahooParseApi::Parse
- Defined in:
- lib/yahoo_parse_api.rb
Overview
parse ex. YahooParseApi::Parse.extract
Instance Method Summary collapse
-
#initialize(appid = YahooParseApi::Config.app_id) ⇒ Parse
constructor
initializer if creating a new Yahoo parse API client.
-
#parse(sentence = '', option = {}, method = :GET) ⇒ Object
execute parse.
Constructor Details
#initialize(appid = YahooParseApi::Config.app_id) ⇒ Parse
initializer if creating a new Yahoo parse API client
27 28 29 30 |
# 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 |
Instance Method Details
#parse(sentence = '', option = {}, method = :GET) ⇒ Object
execute parse
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# 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.) if response.code == 413 response.parsed_response else # invalid arguments raise YahooParseApiError.new('invalid request method') end end |