sentiment_analysis 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. data/.gitignore +6 -0
  2. data/Gemfile +7 -0
  3. data/Gemfile.lock +28 -0
  4. data/Rakefile +22 -0
  5. data/Readme.markdown +55 -0
  6. data/doc/development.txt +27 -0
  7. data/lib/sentiment_analysis.rb +9 -0
  8. data/lib/sentiment_analysis/client.rb +54 -0
  9. data/lib/sentiment_analysis/version.rb +3 -0
  10. data/sentiment_analysis.gemspec +27 -0
  11. data/spec/config.yml.example +1 -0
  12. data/spec/error_invalid_api_key_spec.rb +53 -0
  13. data/spec/fixtures/quota_success.xml +4 -0
  14. data/spec/fixtures/review_success.xml +6 -0
  15. data/spec/fixtures/train_success.xml +4 -0
  16. data/spec/quota_spec.rb +49 -0
  17. data/spec/review_spec.rb +61 -0
  18. data/spec/spec.opts +1 -0
  19. data/spec/spec_helper.rb +16 -0
  20. data/spec/support/vcr.rb +18 -0
  21. data/spec/support/xml.rb +6 -0
  22. data/spec/train_spec.rb +75 -0
  23. data/spec/vcr_cassette_library/errors/quota_with_an_invalid_api_key.yml +30 -0
  24. data/spec/vcr_cassette_library/errors/review_with_an_invalid_api_key.yml +96 -0
  25. data/spec/vcr_cassette_library/errors/train_with_an_invalid_api_key.yml +30 -0
  26. data/spec/vcr_cassette_library/quota_with_json_format_parameter.yml +30 -0
  27. data/spec/vcr_cassette_library/quota_with_parameter.yml +30 -0
  28. data/spec/vcr_cassette_library/quota_with_xml_format_parameter.yml +30 -0
  29. data/spec/vcr_cassette_library/quota_without_parameter.yml +30 -0
  30. data/spec/vcr_cassette_library/review.yml +30 -0
  31. data/spec/vcr_cassette_library/review_with_json_format_parameter.yml +30 -0
  32. data/spec/vcr_cassette_library/review_with_xml_format_parameter.yml +31 -0
  33. data/spec/vcr_cassette_library/train_with_a_negative_mood.yml +59 -0
  34. metadata +176 -0
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+
6
+ /spec/config.yml
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rake'
4
+ gem 'rspec', '1.3.2'
5
+
6
+ # Specify your gem's dependencies in sentiment_analysis.gemspec
7
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sentiment_analysis (0.0.1)
5
+ httparty
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ crack (0.1.8)
11
+ fakeweb (1.3.0)
12
+ httparty (0.7.8)
13
+ crack (= 0.1.8)
14
+ rake (0.9.2)
15
+ rdoc (3.9.4)
16
+ rspec (1.3.2)
17
+ vcr (1.11.3)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ fakeweb
24
+ rake
25
+ rdoc
26
+ rspec (= 1.3.2)
27
+ sentiment_analysis!
28
+ vcr
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ # encoding: UTF-8
2
+ require 'bundler'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ require 'rake'
6
+
7
+ require 'spec/rake/spectask'
8
+ Spec::Rake::SpecTask.new(:spec) do |spec|
9
+ spec.libs << 'lib' << 'spec'
10
+ spec.spec_files = FileList['spec/**/*_spec.rb']
11
+ end
12
+ task :default => :spec
13
+
14
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
15
+ spec.libs << 'lib' << 'spec'
16
+ spec.pattern = 'spec/**/*_spec.rb'
17
+ spec.rcov = true
18
+ end
19
+
20
+ require 'rdoc/task'
21
+ RDoc::Task.new do |rdoc|
22
+ end
data/Readme.markdown ADDED
@@ -0,0 +1,55 @@
1
+ # The SentimentAnalysis Ruby gem
2
+ A Ruby wrapper for the SentimentAnalysis API
3
+
4
+ see : [http://viralheat.com/developer/sentiment_api](http://viralheat.com/developer/sentiment_api)
5
+
6
+ ## <a name="installation">Installation</a>
7
+
8
+ gem install sentiment_analysis
9
+
10
+ ## <a name="how to use">How to use</a>
11
+
12
+
13
+ Simple way
14
+
15
+ require 'sentiment_analysis'
16
+ sa = SentimentAnalysis::Client.new(:api_key => '0123456789')
17
+
18
+ puts sa.quota
19
+ # => 5000
20
+
21
+ puts as.review("i don't like this")
22
+ # => {"prob":0.732603741199471,"mood":"negative","text":"i don't like this"}
23
+
24
+ puts as.train(:text => "I don't like coffee'",:mood => 'negative')
25
+ # => {"status":"ok"}
26
+
27
+
28
+ Choose the format - :json
29
+
30
+ puts sa.quota(:format => :json)
31
+ # => {"quota_remaining":5000}
32
+
33
+
34
+ Choose the format - :xml
35
+
36
+ puts sa.quota(:format => :xml)
37
+ # => <?xml version="1.0" encoding="UTF-8"?>
38
+ <result>
39
+ <quota_remaining>4976</quota_remaining>
40
+ </result>
41
+
42
+ puts as.review("i don't like this", :format => :xml)
43
+ # => <?xml version="1.0" encoding="UTF-8"?>
44
+ <result>
45
+ <text>I don't like coffee</text>
46
+ <mood>negative</mood>
47
+ <prob>0.55865964876338</prob>
48
+ </result>
49
+
50
+ puts as.train(:text => "I don't like coffee'",:mood => 'negative', :format => :xml)
51
+ # => <?xml version="1.0" encoding="UTF-8"?>
52
+ <result>
53
+ <status>ok</status>
54
+ </result>
55
+
@@ -0,0 +1,27 @@
1
+ How to install the gem from the source code
2
+ ===========
3
+
4
+ $ git clone git://github.com/viralheat/sentiment_analysis.git
5
+ $ cd sentiment_analysis
6
+ $ bundle
7
+ $ rake install
8
+
9
+
10
+ API_KEY :
11
+ =========
12
+ To run the test, you need to a personal api key (see http://viralheat.com/developer
13
+
14
+ Once you have an api_key
15
+ $ cd <project_root>
16
+ $ cp spec/config.yml.example spec/config.yml
17
+ $ (edit config.yml and add your api_key)
18
+
19
+
20
+
21
+ How to test
22
+ ===========
23
+
24
+ $ cd <project_root>
25
+ $ bundle
26
+ $ rake
27
+
@@ -0,0 +1,9 @@
1
+ require "sentiment_analysis/version"
2
+ require "sentiment_analysis/client"
3
+
4
+ module SentimentAnalysis
5
+
6
+ class InvalidApiKeyError < StandardError ; end
7
+ class FormatError < StandardError ; end
8
+
9
+ end
@@ -0,0 +1,54 @@
1
+ require 'httparty'
2
+
3
+ module SentimentAnalysis
4
+ class Client
5
+ include ::HTTParty
6
+
7
+ base_uri 'viralheat.com/api/sentiment'
8
+
9
+ def initialize(options)
10
+ @api_key = options[:api_key]
11
+ end
12
+
13
+
14
+ def quota(options={})
15
+ query = {:api_key => @api_key}
16
+
17
+ case options[:format]
18
+ when nil then self.class.get('/quota.json', :query => query)['quota_remaining']
19
+ when :json then self.class.get('/quota.json', :query => query)
20
+ when :xml then self.class.get('/quota.xml', :query => query).body
21
+ else
22
+ raise SentimentAnalysis::FormatError.new("Invalid format : #{options[:format]}")
23
+ end
24
+ end
25
+
26
+
27
+ def train(options)
28
+ raise ArgumentError.new(":text parameter is missing") unless options[:text]
29
+ raise ArgumentError.new(":mood parameter is missing") unless options[:mood]
30
+ query = {:api_key => @api_key, :text => options[:text], :mood => options[:mood] }
31
+
32
+ case options[:format]
33
+ when nil, :json then self.class.get('/train.json', :query => query)
34
+ when :xml then self.class.get('/train.xml', :query => query).body
35
+ else
36
+ raise SentimentAnalysis::FormatError.new("Invalid format : #{options[:format]}")
37
+ end
38
+ end
39
+
40
+
41
+ def review(options)
42
+ raise ArgumentError.new(":text parameter is missing") unless options[:text]
43
+ query = {:api_key => @api_key, :text => options[:text]}
44
+
45
+ case options[:format]
46
+ when nil, :json then self.class.get('/review.json', :query => query)
47
+ when :xml then self.class.get('/review.xml', :query => query).body
48
+ else
49
+ raise SentimentAnalysis::FormatError.new("Invalid format : #{options[:format]}")
50
+ end
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,3 @@
1
+ module SentimentAnalysis
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "sentiment_analysis/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "sentiment_analysis"
7
+ s.version = SentimentAnalysis::VERSION
8
+ s.authors = ["Alain Ravet"]
9
+ s.email = ["alain.ravet@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Client for the SentimentAnalysis API}
12
+ s.description = %q{Client for the SentimentAnalysis API}
13
+
14
+ s.rubyforge_project = "sentiment_analysis"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_runtime_dependency "httparty"
22
+
23
+ s.add_development_dependency "rspec"
24
+ s.add_development_dependency "rdoc"
25
+ s.add_development_dependency "vcr"
26
+ s.add_development_dependency "fakeweb"
27
+ end
@@ -0,0 +1 @@
1
+ api_key: <replace with your real api key obtained from http://viralheat.com/developer>
@@ -0,0 +1,53 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+
4
+ context 'when the API key is invalid' do
5
+
6
+ let(:as) {SentimentAnalysis::Client.new(:api_key => 'AN-invalid-API-key')}
7
+
8
+
9
+ #--------
10
+ # quota
11
+ #--------
12
+
13
+ example 'calling quota() raises as InvalidApiKeyError ' do
14
+ VCR.use_cassette "errors/quota with an invalid api key", :record => :new_episodes do
15
+ pending "update the API service to return a 401 when the API is invalid" do
16
+ expect{
17
+ as.quota
18
+ }.to raise_error(SentimentAnalysis::InvalidApiKeyError)
19
+ end
20
+ end
21
+ end
22
+
23
+
24
+ #--------
25
+ # train
26
+ #--------
27
+
28
+ example 'calling train() raises as InvalidApiKeyError ' do
29
+ VCR.use_cassette "errors/train with an invalid api key", :record => :new_episodes do
30
+ pending "update the API service to return a 401 when the API is invalid" do
31
+ expect{
32
+ as.train(:text => "I don't like coffee'",:mood => 'negative')
33
+ }.to raise_error(SentimentAnalysis::InvalidApiKeyError)
34
+ end
35
+ end
36
+ end
37
+
38
+
39
+ #--------
40
+ # review
41
+ #--------
42
+
43
+ example 'calling review() raises as InvalidApiKeyError ' do
44
+ VCR.use_cassette "errors/review with an invalid api key", :record => :new_episodes do
45
+ pending "update the API service to return a 401 when the API is invalid" do
46
+ expect{
47
+ as.review(:text => "I don't like coffee")
48
+ }.to raise_error(SentimentAnalysis::InvalidApiKeyError)
49
+ end
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <result>
3
+ <quota_remaining>4976</quota_remaining>
4
+ </result>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <result>
3
+ <text>I don't like coffee</text>
4
+ <mood>negative</mood>
5
+ <prob>0.55865964876338</prob>
6
+ </result>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <result>
3
+ <status>ok</status>
4
+ </result>
@@ -0,0 +1,49 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe ".quota" do
4
+
5
+ let(:as) {SentimentAnalysis::Client.new(:api_key => API_KEY)}
6
+
7
+
8
+ context "without parameter" do
9
+ use_vcr_cassette "quota_without_parameter", :record => :new_episodes
10
+ let(:quota) {as.quota}
11
+
12
+ it 'returns the number of remaining API calls in a Hash-like object' do
13
+ quota.should == 1234
14
+ end
15
+ end
16
+
17
+
18
+ context "with (:format => :json)" do
19
+ use_vcr_cassette "quota_with_json_format_parameter", :record => :new_episodes
20
+ let(:quota) {as.quota(:format => :json)}
21
+
22
+ it('fetches JSON data') { quota.response.content_type.should == 'application/json' }
23
+
24
+ it 'returns the number of remaining API calls in a Hash-like object' do
25
+ quota.should == {"quota_remaining"=>4976}
26
+ quota["quota_remaining"].should == 4976
27
+ end
28
+ end
29
+
30
+
31
+ context "with (:format => :xml)" do
32
+ use_vcr_cassette "quota_with_xml_format_parameter", :record => :new_episodes
33
+
34
+ it 'returns the number of remaining API calls in an XML string' do
35
+ as.quota(:format => :xml).should == xml_fixture('quota_success.xml')
36
+ end
37
+ end
38
+
39
+
40
+ # Error handling
41
+ #----------------
42
+
43
+ example "with (:format => :invalid-format raises a FormatError)" do
44
+ expect{
45
+ as.quota(:format => :invalid_format)
46
+ }.to raise_error(SentimentAnalysis::FormatError)
47
+ end
48
+
49
+ end
@@ -0,0 +1,61 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe '.review' do
4
+
5
+ let(:as) {SentimentAnalysis::Client.new(:api_key => API_KEY)}
6
+
7
+
8
+ context "without a format parameter" do
9
+ use_vcr_cassette "review", :record => :new_episodes
10
+
11
+ before() do
12
+ @result = as.review(:text => "I don't like coffee")
13
+ end
14
+
15
+ it 'returns the OK status in a Hash-like object' do
16
+ @result.should == {"prob"=>0.55865964876338, "mood"=>"negative", "text"=>"I don't like coffee"}
17
+ @result['prob'].should == 0.55865964876338
18
+ end
19
+ end
20
+
21
+
22
+ context "with (:format => :json)" do
23
+ use_vcr_cassette "review with :json format parameter", :record => :new_episodes
24
+
25
+ before() do
26
+ @result = as.review(:text => "I don't like coffee", :format => :json)
27
+ end
28
+
29
+ it 'returns the OK status in a Hash-like object' do
30
+ @result.should == {"prob"=>0.55865964876338, "mood"=>"negative", "text"=>"I don't like coffee"}
31
+ @result['prob'].should == 0.55865964876338
32
+ end
33
+ end
34
+
35
+
36
+ context "with (:format => :xml)" do
37
+ use_vcr_cassette "review with :xml format parameter", :record => :new_episodes
38
+
39
+ it 'returns the OK status in a XML String' do
40
+ result = as.review(:text => "I don't like coffee", :format => :xml)
41
+ result.should == xml_fixture('review_success.xml')
42
+ end
43
+ end
44
+
45
+
46
+ # Error handling
47
+ #----------------
48
+
49
+ example ".review(:format => :invalid-format raises a FormatError)" do
50
+ expect{
51
+ as.review(:text => "I don't like coffee", :format => :invalid_format)
52
+ }.to raise_error(SentimentAnalysis::FormatError)
53
+ end
54
+
55
+ example ".review without a :text parameter raises an ArgumentError" do
56
+ expect{
57
+ as.review({})
58
+ }.to raise_error(ArgumentError)
59
+ end
60
+
61
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'sentiment_analysis'
3
+
4
+ require 'spec'
5
+
6
+ Spec::Runner.configure do |config|
7
+ config.before(:each) do
8
+ end
9
+ end
10
+
11
+ SPECS_DIR = File.expand_path(File.dirname(__FILE__))
12
+
13
+ Dir[File.join(SPECS_DIR, 'support/**/*.rb')].each {|f| require f}
14
+
15
+ OPTIONS = YAML::load(File.open(File.join(SPECS_DIR, 'config.yml')))
16
+ API_KEY = OPTIONS['api_key']
@@ -0,0 +1,18 @@
1
+ require 'vcr'
2
+ require 'fakeweb'
3
+
4
+
5
+ VCR_CASSETTES_DIR = File.join(SPECS_DIR, 'vcr_cassette_library')
6
+
7
+ VCR.config do |c|
8
+ c.cassette_library_dir = VCR_CASSETTES_DIR
9
+ c.stub_with :fakeweb
10
+ c.ignore_localhost = true
11
+ c.default_cassette_options = { :record => :none }
12
+ c.allow_http_connections_when_no_cassette = true
13
+ end
14
+
15
+
16
+ Spec::Runner.configure do |c|
17
+ c.extend VCR::RSpec::Macros
18
+ end
@@ -0,0 +1,6 @@
1
+ XML_FIXTURES_DIR = SPECS_DIR + '/fixtures'
2
+
3
+ def xml_fixture(filename)
4
+ filepath = "#{XML_FIXTURES_DIR}/#{filename}"
5
+ File.read(filepath)
6
+ end
@@ -0,0 +1,75 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe '.train' do
4
+
5
+ let(:as) {SentimentAnalysis::Client.new(:api_key => API_KEY)}
6
+
7
+
8
+ context "without a format parameter" do
9
+ use_vcr_cassette "train with a negative mood", :record => :new_episodes
10
+
11
+ before() do
12
+ @result = as.train(:text => "I don't like coffee'",:mood => 'negative')
13
+ end
14
+
15
+ it('fetches JSON data') { @result.response.content_type.should == 'application/json' }
16
+
17
+ it 'returns the OK status in a Hash-like object' do
18
+ @result.should == {"status"=> 'ok'}
19
+ @result['status'].should == 'ok'
20
+ end
21
+ end
22
+
23
+
24
+ context "with (:format => :json)" do
25
+ use_vcr_cassette "train with a negative mood", :record => :new_episodes
26
+
27
+ before() do
28
+ @result = as.train(:text => "I don't like coffee'",:mood => 'negative', :format => :json)
29
+ end
30
+
31
+ it('fetches JSON data') { @result.response.content_type.should == 'application/json' }
32
+
33
+ it 'returns the OK status in a Hash-like object' do
34
+ @result.should == {"status"=> 'ok'}
35
+ @result['status'].should == 'ok'
36
+ end
37
+ end
38
+
39
+
40
+ context "with (:format => :xml)" do
41
+ use_vcr_cassette "train with a negative mood", :record => :new_episodes
42
+
43
+ before() do
44
+
45
+ end
46
+
47
+ it 'returns the number of remaining API calls in an XML string' do
48
+ result = as.train(:text => "I don't like coffee'",:mood => 'negative', :format => :xml)
49
+ result.should == xml_fixture('train_success.xml')
50
+ end
51
+
52
+
53
+ # Error handling
54
+ #----------------
55
+
56
+ example ".train(:format => :invalid-format raises a FormatError)" do
57
+ expect{
58
+ as.train(:text => "I don't like coffee'",:mood => 'negative', :format => :invalid_format)
59
+ }.to raise_error(SentimentAnalysis::FormatError)
60
+ end
61
+
62
+ example ".train without a :text parameter raises an ArgumentError" do
63
+ expect{
64
+ as.train(:mood => 'negative')
65
+ }.to raise_error(ArgumentError)
66
+ end
67
+
68
+ example ".train without a :text parameter raises an ArgumentError" do
69
+ expect{
70
+ as.train(:text => "I don't like coffee'")
71
+ }.to raise_error(ArgumentError)
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,30 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://viralheat.com:80/api/sentiment/quota.json?api_key=AN-invalid-API-key
6
+ body: !!null
7
+ headers: !!null
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ server:
14
+ - nginx/0.7.62
15
+ date:
16
+ - Tue, 13 Sep 2011 11:38:49 GMT
17
+ content-type:
18
+ - application/json; charset=utf-8
19
+ transfer-encoding:
20
+ - chunked
21
+ etag:
22
+ - ! '"043341334b56f8bf1f2cdd30a73843ea"'
23
+ x-ua-compatible:
24
+ - IE=Edge,chrome=1
25
+ cache-control:
26
+ - max-age=0, private, must-revalidate
27
+ status:
28
+ - '200'
29
+ body: ! '{"quota_remaining":0}'
30
+ http_version: '1.1'
@@ -0,0 +1,96 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://viralheat.com:80/api/sentiment/review.json?api_key=AN-invalid-API-key&text=I%20don't%20like%20coffee
6
+ body: !!null
7
+ headers: !!null
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 302
11
+ message: Found
12
+ headers:
13
+ server:
14
+ - nginx/0.7.62
15
+ date:
16
+ - Tue, 13 Sep 2011 11:38:50 GMT
17
+ content-type:
18
+ - text/html; charset=utf-8
19
+ transfer-encoding:
20
+ - chunked
21
+ x-ua-compatible:
22
+ - IE=Edge,chrome=1
23
+ cache-control:
24
+ - no-cache
25
+ location:
26
+ - http://viralheat.com/api/error/over_quota
27
+ status:
28
+ - '302'
29
+ vary:
30
+ - Accept-Encoding
31
+ body: <html><body>You are being <a href="http://viralheat.com/api/error/over_quota">redirected</a>.</body></html>
32
+ http_version: '1.1'
33
+ - !ruby/struct:VCR::HTTPInteraction
34
+ request: !ruby/struct:VCR::Request
35
+ method: :get
36
+ uri: http://viralheat.com:80/api/error/over_quota
37
+ body: !!null
38
+ headers: !!null
39
+ response: !ruby/struct:VCR::Response
40
+ status: !ruby/struct:VCR::ResponseStatus
41
+ code: 302
42
+ message: Found
43
+ headers:
44
+ server:
45
+ - nginx/0.7.62
46
+ date:
47
+ - Tue, 13 Sep 2011 11:38:51 GMT
48
+ content-type:
49
+ - text/html; charset=utf-8
50
+ transfer-encoding:
51
+ - chunked
52
+ x-ua-compatible:
53
+ - IE=Edge,chrome=1
54
+ cache-control:
55
+ - no-cache
56
+ location:
57
+ - http://viralheat.com/api/error/over_quota.xml
58
+ status:
59
+ - '302'
60
+ vary:
61
+ - Accept-Encoding
62
+ body: <html><body>You are being <a href="http://viralheat.com/api/error/over_quota.xml">redirected</a>.</body></html>
63
+ http_version: '1.1'
64
+ - !ruby/struct:VCR::HTTPInteraction
65
+ request: !ruby/struct:VCR::Request
66
+ method: :get
67
+ uri: http://viralheat.com:80/api/error/over_quota.xml
68
+ body: !!null
69
+ headers: !!null
70
+ response: !ruby/struct:VCR::Response
71
+ status: !ruby/struct:VCR::ResponseStatus
72
+ code: 200
73
+ message: OK
74
+ headers:
75
+ server:
76
+ - nginx/0.7.62
77
+ date:
78
+ - Tue, 13 Sep 2011 11:38:51 GMT
79
+ content-type:
80
+ - application/xml; charset=utf-8
81
+ transfer-encoding:
82
+ - chunked
83
+ etag:
84
+ - ! '"209b2aaad1c49df22c2ba0e9a9b5bbd9"'
85
+ x-ua-compatible:
86
+ - IE=Edge,chrome=1
87
+ cache-control:
88
+ - max-age=0, private, must-revalidate
89
+ status:
90
+ - '200'
91
+ body: ! '<?xml version="1.0" encoding="UTF-8"?>
92
+
93
+ <error>Error: Over quota limit. Please try again in 24 hours.</error>
94
+
95
+ '
96
+ http_version: '1.1'
@@ -0,0 +1,30 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://viralheat.com:80/api/sentiment/train.json?api_key=AN-invalid-API-key&text=I%20don't%20like%20coffee'&mood=negative
6
+ body: !!null
7
+ headers: !!null
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ server:
14
+ - nginx/0.7.62
15
+ date:
16
+ - Tue, 13 Sep 2011 11:38:49 GMT
17
+ content-type:
18
+ - application/json; charset=utf-8
19
+ transfer-encoding:
20
+ - chunked
21
+ etag:
22
+ - ! '"0f0479874bf6f4a7281099b15df27c27"'
23
+ x-ua-compatible:
24
+ - IE=Edge,chrome=1
25
+ cache-control:
26
+ - max-age=0, private, must-revalidate
27
+ status:
28
+ - '200'
29
+ body: ! '{"status":"ok"}'
30
+ http_version: '1.1'
@@ -0,0 +1,30 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://viralheat.com:80/api/sentiment/quota.json?api_key=aJMm2A4wTh1esjSkETGq
6
+ body: !!null
7
+ headers: !!null
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ server:
14
+ - nginx/0.7.62
15
+ date:
16
+ - Tue, 13 Sep 2011 11:47:42 GMT
17
+ content-type:
18
+ - application/json; charset=utf-8
19
+ transfer-encoding:
20
+ - chunked
21
+ etag:
22
+ - ! '"664eedcae409b4801d7907e7d81e3da1"'
23
+ x-ua-compatible:
24
+ - IE=Edge,chrome=1
25
+ cache-control:
26
+ - max-age=0, private, must-revalidate
27
+ status:
28
+ - '200'
29
+ body: ! '{"quota_remaining":4976}'
30
+ http_version: '1.1'
@@ -0,0 +1,30 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://viralheat.com:80/api/sentiment/quota.json?api_key=aJMm2A4wTh1esjSkETGq
6
+ body: !!null
7
+ headers: !!null
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ server:
14
+ - nginx/0.7.62
15
+ date:
16
+ - Tue, 13 Sep 2011 11:46:22 GMT
17
+ content-type:
18
+ - application/json; charset=utf-8
19
+ transfer-encoding:
20
+ - chunked
21
+ etag:
22
+ - ! '"664eedcae409b4801d7907e7d81e3da1"'
23
+ x-ua-compatible:
24
+ - IE=Edge,chrome=1
25
+ cache-control:
26
+ - max-age=0, private, must-revalidate
27
+ status:
28
+ - '200'
29
+ body: ! '{"quota_remaining":4976}'
30
+ http_version: '1.1'
@@ -0,0 +1,30 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://viralheat.com:80/api/sentiment/quota.xml?api_key=aJMm2A4wTh1esjSkETGq
6
+ body: !!null
7
+ headers: !!null
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ server:
14
+ - nginx/0.7.62
15
+ date:
16
+ - Tue, 13 Sep 2011 11:52:43 GMT
17
+ content-type:
18
+ - application/xml; charset=utf-8
19
+ transfer-encoding:
20
+ - chunked
21
+ etag:
22
+ - ! '"ac88f5e43483b580e736eb8aff92933a"'
23
+ x-ua-compatible:
24
+ - IE=Edge,chrome=1
25
+ cache-control:
26
+ - max-age=0, private, must-revalidate
27
+ status:
28
+ - '200'
29
+ body: ! "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<result>\n <quota_remaining>4976</quota_remaining>\n</result>\n"
30
+ http_version: '1.1'
@@ -0,0 +1,30 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://viralheat.com:80/api/sentiment/quota.json?api_key=aJMm2A4wTh1esjSkETGq
6
+ body: !!null
7
+ headers: !!null
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ server:
14
+ - nginx/0.7.62
15
+ date:
16
+ - Tue, 13 Sep 2011 09:25:13 GMT
17
+ content-type:
18
+ - application/json; charset=utf-8
19
+ transfer-encoding:
20
+ - chunked
21
+ etag:
22
+ - ! '"d1a69490951e0608a75c768cf7e5d5bc"'
23
+ x-ua-compatible:
24
+ - IE=Edge,chrome=1
25
+ cache-control:
26
+ - max-age=0, private, must-revalidate
27
+ status:
28
+ - '200'
29
+ body: ! '{"quota_remaining":1234}'
30
+ http_version: '1.1'
@@ -0,0 +1,30 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://viralheat.com:80/api/sentiment/review.json?api_key=aJMm2A4wTh1esjSkETGq&text=I%20don't%20like%20coffee
6
+ body: !!null
7
+ headers: !!null
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ server:
14
+ - nginx/0.7.62
15
+ date:
16
+ - Tue, 13 Sep 2011 09:56:15 GMT
17
+ content-type:
18
+ - application/json; charset=utf-8
19
+ transfer-encoding:
20
+ - chunked
21
+ etag:
22
+ - ! '"498f051bc0c72599a87e728b909e7bd7"'
23
+ x-ua-compatible:
24
+ - IE=Edge,chrome=1
25
+ cache-control:
26
+ - max-age=0, private, must-revalidate
27
+ status:
28
+ - '200'
29
+ body: ! '{"prob":0.55865964876338,"mood":"negative","text":"I don''t like coffee"}'
30
+ http_version: '1.1'
@@ -0,0 +1,30 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://viralheat.com:80/api/sentiment/review.json?api_key=aJMm2A4wTh1esjSkETGq&text=I%20don't%20like%20coffee
6
+ body: !!null
7
+ headers: !!null
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ server:
14
+ - nginx/0.7.62
15
+ date:
16
+ - Tue, 13 Sep 2011 12:20:34 GMT
17
+ content-type:
18
+ - application/json; charset=utf-8
19
+ transfer-encoding:
20
+ - chunked
21
+ etag:
22
+ - ! '"2e87cef6d63d1b03a760cfddc986e0e0"'
23
+ x-ua-compatible:
24
+ - IE=Edge,chrome=1
25
+ cache-control:
26
+ - max-age=0, private, must-revalidate
27
+ status:
28
+ - '200'
29
+ body: ! '{"mood":"negative","prob":0.55865964876338,"text":"I don''t like coffee"}'
30
+ http_version: '1.1'
@@ -0,0 +1,31 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://viralheat.com:80/api/sentiment/review.xml?api_key=aJMm2A4wTh1esjSkETGq&text=I%20don't%20like%20coffee
6
+ body: !!null
7
+ headers: !!null
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ server:
14
+ - nginx/0.7.62
15
+ date:
16
+ - Tue, 13 Sep 2011 12:20:35 GMT
17
+ content-type:
18
+ - application/xml; charset=utf-8
19
+ transfer-encoding:
20
+ - chunked
21
+ etag:
22
+ - ! '"18b284a27005fd36483abfbb8a0106ce"'
23
+ x-ua-compatible:
24
+ - IE=Edge,chrome=1
25
+ cache-control:
26
+ - max-age=0, private, must-revalidate
27
+ status:
28
+ - '200'
29
+ body: ! "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<result>\n <text>I don't
30
+ like coffee</text>\n <mood>negative</mood>\n <prob>0.55865964876338</prob>\n</result>\n"
31
+ http_version: '1.1'
@@ -0,0 +1,59 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://viralheat.com:80/api/sentiment/train.json?api_key=aJMm2A4wTh1esjSkETGq&text=I%20don't%20like%20coffee'&mood=negative
6
+ body: !!null
7
+ headers: !!null
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ server:
14
+ - nginx/0.7.62
15
+ date:
16
+ - Tue, 13 Sep 2011 09:25:14 GMT
17
+ content-type:
18
+ - application/json; charset=utf-8
19
+ transfer-encoding:
20
+ - chunked
21
+ etag:
22
+ - ! '"0f0479874bf6f4a7281099b15df27c27"'
23
+ x-ua-compatible:
24
+ - IE=Edge,chrome=1
25
+ cache-control:
26
+ - max-age=0, private, must-revalidate
27
+ status:
28
+ - '200'
29
+ body: ! '{"status":"ok"}'
30
+ http_version: '1.1'
31
+ - !ruby/struct:VCR::HTTPInteraction
32
+ request: !ruby/struct:VCR::Request
33
+ method: :get
34
+ uri: http://viralheat.com:80/api/sentiment/train.xml?api_key=aJMm2A4wTh1esjSkETGq&text=I%20don't%20like%20coffee'&mood=negative
35
+ body: !!null
36
+ headers: !!null
37
+ response: !ruby/struct:VCR::Response
38
+ status: !ruby/struct:VCR::ResponseStatus
39
+ code: 200
40
+ message: OK
41
+ headers:
42
+ server:
43
+ - nginx/0.7.62
44
+ date:
45
+ - Tue, 13 Sep 2011 12:14:07 GMT
46
+ content-type:
47
+ - application/xml; charset=utf-8
48
+ transfer-encoding:
49
+ - chunked
50
+ etag:
51
+ - ! '"38ab7795ed364c12f37d99bbf1861d6b"'
52
+ x-ua-compatible:
53
+ - IE=Edge,chrome=1
54
+ cache-control:
55
+ - max-age=0, private, must-revalidate
56
+ status:
57
+ - '200'
58
+ body: ! "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<result>\n <status>ok</status>\n</result>\n"
59
+ http_version: '1.1'
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sentiment_analysis
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Alain Ravet
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-09-13 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: httparty
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: rspec
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :development
43
+ version_requirements: *id002
44
+ - !ruby/object:Gem::Dependency
45
+ name: rdoc
46
+ prerelease: false
47
+ requirement: &id003 !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ type: :development
55
+ version_requirements: *id003
56
+ - !ruby/object:Gem::Dependency
57
+ name: vcr
58
+ prerelease: false
59
+ requirement: &id004 !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ type: :development
67
+ version_requirements: *id004
68
+ - !ruby/object:Gem::Dependency
69
+ name: fakeweb
70
+ prerelease: false
71
+ requirement: &id005 !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ type: :development
79
+ version_requirements: *id005
80
+ description: Client for the SentimentAnalysis API
81
+ email:
82
+ - alain.ravet@gmail.com
83
+ executables: []
84
+
85
+ extensions: []
86
+
87
+ extra_rdoc_files: []
88
+
89
+ files:
90
+ - .gitignore
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - Rakefile
94
+ - Readme.markdown
95
+ - doc/development.txt
96
+ - lib/sentiment_analysis.rb
97
+ - lib/sentiment_analysis/client.rb
98
+ - lib/sentiment_analysis/version.rb
99
+ - sentiment_analysis.gemspec
100
+ - spec/config.yml.example
101
+ - spec/error_invalid_api_key_spec.rb
102
+ - spec/fixtures/quota_success.xml
103
+ - spec/fixtures/review_success.xml
104
+ - spec/fixtures/train_success.xml
105
+ - spec/quota_spec.rb
106
+ - spec/review_spec.rb
107
+ - spec/spec.opts
108
+ - spec/spec_helper.rb
109
+ - spec/support/vcr.rb
110
+ - spec/support/xml.rb
111
+ - spec/train_spec.rb
112
+ - spec/vcr_cassette_library/errors/quota_with_an_invalid_api_key.yml
113
+ - spec/vcr_cassette_library/errors/review_with_an_invalid_api_key.yml
114
+ - spec/vcr_cassette_library/errors/train_with_an_invalid_api_key.yml
115
+ - spec/vcr_cassette_library/quota_with_json_format_parameter.yml
116
+ - spec/vcr_cassette_library/quota_with_parameter.yml
117
+ - spec/vcr_cassette_library/quota_with_xml_format_parameter.yml
118
+ - spec/vcr_cassette_library/quota_without_parameter.yml
119
+ - spec/vcr_cassette_library/review.yml
120
+ - spec/vcr_cassette_library/review_with_json_format_parameter.yml
121
+ - spec/vcr_cassette_library/review_with_xml_format_parameter.yml
122
+ - spec/vcr_cassette_library/train_with_a_negative_mood.yml
123
+ has_rdoc: true
124
+ homepage: ""
125
+ licenses: []
126
+
127
+ post_install_message:
128
+ rdoc_options: []
129
+
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ segments:
137
+ - 0
138
+ version: "0"
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ segments:
144
+ - 0
145
+ version: "0"
146
+ requirements: []
147
+
148
+ rubyforge_project: sentiment_analysis
149
+ rubygems_version: 1.3.6
150
+ signing_key:
151
+ specification_version: 3
152
+ summary: Client for the SentimentAnalysis API
153
+ test_files:
154
+ - spec/config.yml.example
155
+ - spec/error_invalid_api_key_spec.rb
156
+ - spec/fixtures/quota_success.xml
157
+ - spec/fixtures/review_success.xml
158
+ - spec/fixtures/train_success.xml
159
+ - spec/quota_spec.rb
160
+ - spec/review_spec.rb
161
+ - spec/spec.opts
162
+ - spec/spec_helper.rb
163
+ - spec/support/vcr.rb
164
+ - spec/support/xml.rb
165
+ - spec/train_spec.rb
166
+ - spec/vcr_cassette_library/errors/quota_with_an_invalid_api_key.yml
167
+ - spec/vcr_cassette_library/errors/review_with_an_invalid_api_key.yml
168
+ - spec/vcr_cassette_library/errors/train_with_an_invalid_api_key.yml
169
+ - spec/vcr_cassette_library/quota_with_json_format_parameter.yml
170
+ - spec/vcr_cassette_library/quota_with_parameter.yml
171
+ - spec/vcr_cassette_library/quota_with_xml_format_parameter.yml
172
+ - spec/vcr_cassette_library/quota_without_parameter.yml
173
+ - spec/vcr_cassette_library/review.yml
174
+ - spec/vcr_cassette_library/review_with_json_format_parameter.yml
175
+ - spec/vcr_cassette_library/review_with_xml_format_parameter.yml
176
+ - spec/vcr_cassette_library/train_with_a_negative_mood.yml