applied 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 14b98e71134bfd46b00b8fc161382faa3e680708
4
+ data.tar.gz: 4e1f85664c0eeb6e68427c43a8457c170ccab40f
5
+ SHA512:
6
+ metadata.gz: d5262e492fd0e3837593aa979e0147fb5074c9535ad04413222cda826a9d9083a35d7a2083c806c935922d44de6458df9289944d668edf3ee62247d140cfc24f
7
+ data.tar.gz: 563b4113e79ed379682fd4101b928694a8c7e3c5a2b088025b834a694c6e7c0e8132584f10226a09026e1d010a72a95d6743ed8fd18981f275683406b41c110b
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+
24
+ .DS_Store
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ - 2.1.1
5
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in applied.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Andrea Mostosi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Applied
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'applied'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install applied
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/applied/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task default: :spec
data/applied.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'applied/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "applied"
8
+ spec.version = Applied::VERSION
9
+ spec.authors = ["Andrea Mostosi"]
10
+ spec.email = ["andrea.mostosi@zenkay.net"]
11
+ spec.summary = %q{Ruby Gem for AI Applied service}
12
+ spec.description = %q{Ruby Gem for AI Applied service (ai-applied.nl)}
13
+ spec.homepage = "https://github.com/zenkay/ai-applied-ruby"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = '~> 2.0'
22
+
23
+ spec.add_dependency "faraday", '~> 0.9', '>= 0.9.0'
24
+ spec.add_dependency "faraday_middleware", '~> 0.9', '>= 0.9.1'
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.3"
27
+ spec.add_development_dependency "rspec", "~> 2.12"
28
+ spec.add_development_dependency "rake", "~> 10.1"
29
+ spec.add_development_dependency "vcr", "~> 2.4"
30
+ spec.add_development_dependency "webmock", "~> 1.17"
31
+ spec.add_development_dependency "simplecov", "~> 0.8"
32
+ spec.add_development_dependency "coveralls", "~> 0.7"
33
+ end
data/lib/applied.rb ADDED
@@ -0,0 +1,20 @@
1
+ require "applied/version"
2
+ require "applied/sentiment"
3
+
4
+ module Applied
5
+
6
+ def self.configure(&block)
7
+ yield @config ||= Configuration.new
8
+ end
9
+
10
+ def self.config
11
+ @config
12
+ end
13
+
14
+ class Configuration
15
+ attr_accessor :api_key, :endpoint
16
+ end
17
+
18
+ class BadResponse < Exception; end
19
+
20
+ end
@@ -0,0 +1,46 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+ require "json"
4
+
5
+ module Applied
6
+
7
+ class Sentiment
8
+
9
+ ENDPOINT = "/api/sentiment_api/"
10
+
11
+ attr_accessor :return_original, :classifier
12
+
13
+ def analyze(data, options)
14
+ params = options
15
+ call(ENDPOINT, data, options)
16
+ end
17
+
18
+ protected
19
+
20
+ def call(endpoint, data, options)
21
+ begin
22
+ request = {
23
+ data: {
24
+ api_key: Applied.config.api_key,
25
+ call: {
26
+ return_original: options[:return_original],
27
+ classifier: options[:classifier],
28
+ data: data
29
+ }
30
+ }
31
+ }
32
+ conn = Faraday.new(url: Applied.config.endpoint) do |faraday|
33
+ faraday.request :url_encoded
34
+ faraday.adapter Faraday.default_adapter
35
+ end
36
+ response = conn.post endpoint, request: request.to_json
37
+ JSON.parse response.body
38
+ rescue Exception => e
39
+ raise Applied::BadResponse
40
+ end
41
+ end
42
+
43
+
44
+ end
45
+
46
+ end
@@ -0,0 +1,3 @@
1
+ module Applied
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,40 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://api.ai-applied.nl/api/sentiment_api/
6
+ body:
7
+ encoding: UTF-8
8
+ string: request=%7B%22data%22%3A%7B%22api_key%22%3A%22837b4a6bc73bce85abec5db64dfcde9cab92a1bf%22%2C%22call%22%3A%7B%22return_original%22%3Afalse%2C%22classifier%22%3A%22default%22%2C%22data%22%3A%5B%7B%22text%22%3A%22Sono+molto+contento+di+quello+che+%C3%A8+successo%22%2C%22language_iso%22%3A%22ita%22%2C%22id%22%3A42%7D%5D%7D%7D%7D
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.0
12
+ Content-Type:
13
+ - application/x-www-form-urlencoded
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - '*/*'
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Date:
24
+ - Sun, 26 Oct 2014 09:57:04 GMT
25
+ Server:
26
+ - Apache/2.2.17 (Ubuntu)
27
+ Vary:
28
+ - Accept-Encoding
29
+ Content-Length:
30
+ - '164'
31
+ Content-Type:
32
+ - application/x-javascript
33
+ body:
34
+ encoding: UTF-8
35
+ string: '{"status": 1, "id": null, "response": {"data": [{"confidence_sentiment":
36
+ 0.735094833636812, "sentiment_class": "positive", "id": 42}], "description":
37
+ "OK: Call processed.", "success": true}}'
38
+ http_version:
39
+ recorded_at: Sun, 26 Oct 2014 09:57:04 GMT
40
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ vcr_options = { :cassette_name => "applied_sentiment", :record => :new_episodes }
4
+
5
+ describe Applied::Sentiment, vcr: vcr_options do
6
+
7
+ before(:each) do
8
+ Applied.configure do |c|
9
+ # account: <applied@mailinator.com>
10
+ c.api_key = "837b4a6bc73bce85abec5db64dfcde9cab92a1bf"
11
+ c.endpoint = "http://api.ai-applied.nl/"
12
+ end
13
+ end
14
+
15
+ it "initialize a new sentiment request" do
16
+ request = Applied::Sentiment.new
17
+ expect(request).to be_an_instance_of(Applied::Sentiment)
18
+ end
19
+
20
+ it "make a request sentiment of an italian sentence" do
21
+ element = Applied::Sentiment.new
22
+ options = {return_original: false, classifier: "default"}
23
+ data = [{text: "Sono molto contento di quello che è successo", language_iso: "ita", id: 42}]
24
+ response = element.analyze(data, options)
25
+
26
+ expect(response).not_to be_empty
27
+ expect(response["status"]).to eq 1
28
+ expect(response["response"]).to be_a Hash
29
+ expect(response["response"]["data"]).to be_a Array
30
+ response["response"]["data"].each do |d|
31
+ expect(d["sentiment_class"]).to match /positive|negative|unknown/
32
+ expect(d["id"]).to be 42
33
+ expect(d["confidence_sentiment"]).to be_between(0.0, 1.0)
34
+ end
35
+ end
36
+
37
+ it "raise exception on wrong config parameters" do
38
+ Applied.configure do |c|
39
+ c.api_key = "bad-app-id"
40
+ c.endpoint = "not-an-url-endpoint"
41
+ end
42
+ element = Applied::Sentiment.new
43
+ expect { element.analyze({text: "test"}, []) }.to raise_error(Applied::BadResponse)
44
+ end
45
+
46
+ end
@@ -0,0 +1,22 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'coveralls'
5
+ Coveralls.wear!
6
+
7
+ require "applied"
8
+ require 'vcr'
9
+
10
+ VCR.configure do |c|
11
+ c.cassette_library_dir = 'spec/cassettes'
12
+ c.hook_into :webmock
13
+ c.configure_rspec_metadata!
14
+ end
15
+
16
+ RSpec.configure do |config|
17
+ config.treat_symbols_as_metadata_keys_with_true_values = true
18
+ config.run_all_when_everything_filtered = true
19
+ config.filter_run :focus
20
+ config.order = 'random'
21
+ # config.color_enabled = true
22
+ end
metadata ADDED
@@ -0,0 +1,198 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: applied
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Andrea Mostosi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ - - '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 0.9.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.9'
30
+ - - '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 0.9.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: faraday_middleware
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: '0.9'
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: 0.9.1
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ version: '0.9'
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: 0.9.1
53
+ - !ruby/object:Gem::Dependency
54
+ name: bundler
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ version: '1.3'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ version: '1.3'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rspec
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ version: '2.12'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ~>
79
+ - !ruby/object:Gem::Version
80
+ version: '2.12'
81
+ - !ruby/object:Gem::Dependency
82
+ name: rake
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: '10.1'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: '10.1'
95
+ - !ruby/object:Gem::Dependency
96
+ name: vcr
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '2.4'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ~>
107
+ - !ruby/object:Gem::Version
108
+ version: '2.4'
109
+ - !ruby/object:Gem::Dependency
110
+ name: webmock
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ~>
114
+ - !ruby/object:Gem::Version
115
+ version: '1.17'
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ~>
121
+ - !ruby/object:Gem::Version
122
+ version: '1.17'
123
+ - !ruby/object:Gem::Dependency
124
+ name: simplecov
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ~>
128
+ - !ruby/object:Gem::Version
129
+ version: '0.8'
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ~>
135
+ - !ruby/object:Gem::Version
136
+ version: '0.8'
137
+ - !ruby/object:Gem::Dependency
138
+ name: coveralls
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ~>
142
+ - !ruby/object:Gem::Version
143
+ version: '0.7'
144
+ type: :development
145
+ prerelease: false
146
+ version_requirements: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ~>
149
+ - !ruby/object:Gem::Version
150
+ version: '0.7'
151
+ description: Ruby Gem for AI Applied service (ai-applied.nl)
152
+ email:
153
+ - andrea.mostosi@zenkay.net
154
+ executables: []
155
+ extensions: []
156
+ extra_rdoc_files: []
157
+ files:
158
+ - .gitignore
159
+ - .travis.yml
160
+ - Gemfile
161
+ - LICENSE.txt
162
+ - README.md
163
+ - Rakefile
164
+ - applied.gemspec
165
+ - lib/applied.rb
166
+ - lib/applied/sentiment.rb
167
+ - lib/applied/version.rb
168
+ - spec/cassettes/applied_sentiment.yml
169
+ - spec/sentiment_spec.rb
170
+ - spec/spec_helper.rb
171
+ homepage: https://github.com/zenkay/ai-applied-ruby
172
+ licenses:
173
+ - MIT
174
+ metadata: {}
175
+ post_install_message:
176
+ rdoc_options: []
177
+ require_paths:
178
+ - lib
179
+ required_ruby_version: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - ~>
182
+ - !ruby/object:Gem::Version
183
+ version: '2.0'
184
+ required_rubygems_version: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - '>='
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ requirements: []
190
+ rubyforge_project:
191
+ rubygems_version: 2.2.2
192
+ signing_key:
193
+ specification_version: 4
194
+ summary: Ruby Gem for AI Applied service
195
+ test_files:
196
+ - spec/cassettes/applied_sentiment.yml
197
+ - spec/sentiment_spec.rb
198
+ - spec/spec_helper.rb