Class: SentimentAnalysis::Client
- Inherits:
-
Object
- Object
- SentimentAnalysis::Client
- Includes:
- HTTParty
- Defined in:
- lib/sentiment_analysis/client.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
- #quota(options = {}) ⇒ Object
- #review(options) ⇒ Object
- #train(options) ⇒ Object
Constructor Details
#initialize(options) ⇒ Client
Returns a new instance of Client.
9 10 11 |
# File 'lib/sentiment_analysis/client.rb', line 9 def initialize() @api_key = [:api_key] end |
Instance Method Details
#quota(options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/sentiment_analysis/client.rb', line 14 def quota(={}) query = {:api_key => @api_key} case [:format] when nil then self.class.get('/quota.json', :query => query)['quota_remaining'] when :json then self.class.get('/quota.json', :query => query) when :xml then self.class.get('/quota.xml', :query => query).body else raise SentimentAnalysis::FormatError.new("Invalid format : #{[:format]}") end end |
#review(options) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/sentiment_analysis/client.rb', line 41 def review() raise ArgumentError.new(":text parameter is missing") unless [:text] query = {:api_key => @api_key, :text => [:text]} case [:format] when nil, :json then self.class.get('/review.json', :query => query) when :xml then self.class.get('/review.xml', :query => query).body else raise SentimentAnalysis::FormatError.new("Invalid format : #{[:format]}") end end |
#train(options) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sentiment_analysis/client.rb', line 27 def train() raise ArgumentError.new(":text parameter is missing") unless [:text] raise ArgumentError.new(":mood parameter is missing") unless [:mood] query = {:api_key => @api_key, :text => [:text], :mood => [:mood] } case [:format] when nil, :json then self.class.get('/train.json', :query => query) when :xml then self.class.get('/train.xml', :query => query).body else raise SentimentAnalysis::FormatError.new("Invalid format : #{[:format]}") end end |