lateral_recommender 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.
@@ -0,0 +1,149 @@
1
+ require 'spec_helper'
2
+
3
+ describe LateralRecommender do
4
+ describe 'API' do
5
+ let(:api) { LateralRecommender::API.new ENV['API_KEY'] }
6
+ let(:body) { File.read('spec/fixtures/article-body.txt') }
7
+
8
+ it 'errors with invalid API key' do
9
+ api = LateralRecommender::API.new 'no'
10
+ VCR.use_cassette('invalid_key') do
11
+ response = api.near_text text: 'test'
12
+ expect(response[:error][:status_code]).to eq(401)
13
+ expect(response[:error][:message]).to include('invalid subscription key')
14
+ end
15
+ end
16
+
17
+ it 'adds a document' do
18
+ VCR.use_cassette('add') do
19
+ response = api.add document_id: 'doc_id', text: body
20
+ expect(response['document_id']).to eq('doc_id')
21
+ expect(response['text']).to include('Space exploration')
22
+ end
23
+ end
24
+
25
+ it 'gets recommendations' do
26
+ VCR.use_cassette('near_text') do
27
+ response = api.near_text text: body
28
+ expect(response.length).to eq(20)
29
+ expect(response.first['document_id']).to eq('doc_id')
30
+ end
31
+ end
32
+
33
+ it 'gets recommendations from movies' do
34
+ api = LateralRecommender::API.new ENV['API_KEY'], 'movies'
35
+ VCR.use_cassette('near_text_movies') do
36
+ response = api.near_text text: body
37
+ expect(response.length).to eq(20)
38
+ expect(response.first['title']).to eq('First World')
39
+ end
40
+ end
41
+
42
+ it 'gets recommendations from news' do
43
+ api = LateralRecommender::API.new ENV['API_KEY'], 'news'
44
+ VCR.use_cassette('near_text_news') do
45
+ response = api.near_text text: body
46
+ expect(response.length).to be > 10 # This should be done better
47
+ expect(response.first['title']).to include('The Space Missions and Events')
48
+ end
49
+ end
50
+
51
+ it 'gets recommendations from wikipedia' do
52
+ api = LateralRecommender::API.new ENV['API_KEY'], 'wikipedia'
53
+ VCR.use_cassette('near_text_wikipedia') do
54
+ response = api.near_text text: body
55
+ expect(response.length).to eq(10)
56
+ expect(response.first['title']).to eq('Space exploration')
57
+ end
58
+ end
59
+
60
+ it 'gets recommendations from pubmed' do
61
+ api = LateralRecommender::API.new ENV['API_KEY'], 'pubmed'
62
+ VCR.use_cassette('near_text_pubmed') do
63
+ response = api.near_text text: body
64
+ expect(response.length).to eq(10)
65
+ expect(response.first['title']).to include('NASA and the search')
66
+ end
67
+ end
68
+
69
+ it 'gets recommendations from arxiv' do
70
+ api = LateralRecommender::API.new ENV['API_KEY'], 'arxiv'
71
+ VCR.use_cassette('near_text_arxiv') do
72
+ response = api.near_text text: body
73
+ expect(response.length).to eq(10)
74
+ expect(response.first['title']).to include('A Lunar L2-Farside')
75
+ end
76
+ end
77
+
78
+ it 'adds a user' do
79
+ VCR.use_cassette('add_user') do
80
+ response = api.add_user('user_id')
81
+ expect(response['id']).to eq('user_id')
82
+ end
83
+ end
84
+
85
+ it 'adds a user document' do
86
+ VCR.use_cassette('add_user_document') do
87
+ response = api.add_user_document('user_id', 'doc_id', body)
88
+ expect(response['id']).to eq('doc_id')
89
+ expect(response['user_id']).to eq('user_id')
90
+ expect(response['body']).to include('Space exploration')
91
+ end
92
+ end
93
+
94
+ # TODO: Change this so there is a document ID to validate
95
+ it 'gets recommendations for a user' do
96
+ VCR.use_cassette('near_user') do
97
+ response = api.near_user('user_id')
98
+ expect(response).to be_a(Array)
99
+ expect(response.length).to be > 10
100
+ end
101
+ end
102
+
103
+ it 'gets recommendations for a user from movies' do
104
+ api = LateralRecommender::API.new ENV['API_KEY'], 'movies'
105
+ VCR.use_cassette('near_user_movies') do
106
+ response = api.near_user('user_id')
107
+ expect(response.length).to eq(20)
108
+ expect(response.first['title']).to include('First World')
109
+ end
110
+ end
111
+
112
+ it 'gets recommendations for a user from news' do
113
+ api = LateralRecommender::API.new ENV['API_KEY'], 'news'
114
+ VCR.use_cassette('near_user_news') do
115
+ response = api.near_user('user_id')
116
+ expect(response.length).to be > 10 # This should be done better
117
+ expect(response.first['title']).to include('The Space Missions and')
118
+ end
119
+ end
120
+
121
+ it 'gets recommendations for a user from wikipedia' do
122
+ api = LateralRecommender::API.new ENV['API_KEY'], 'wikipedia'
123
+ VCR.use_cassette('near_user_wikipedia') do
124
+ response = api.near_user('user_id')
125
+ expect(response.length).to eq(9) # First one is cut because it is same page
126
+ expect(response.first['title']).to include('Unmanned NASA missions')
127
+ end
128
+ end
129
+
130
+ it 'gets recommendations for a user from pubmed' do
131
+ api = LateralRecommender::API.new ENV['API_KEY'], 'pubmed'
132
+ VCR.use_cassette('near_user_pubmed') do
133
+ response = api.near_user('user_id')
134
+ expect(response.length).to eq(10)
135
+ expect(response.first['title']).to include('NASA and the search for')
136
+ end
137
+ end
138
+
139
+ it 'gets recommendations for a user from arxiv' do
140
+ api = LateralRecommender::API.new ENV['API_KEY'], 'arxiv'
141
+ VCR.use_cassette('near_user_arxiv') do
142
+ response = api.near_user('user_id')
143
+ expect(response.length).to eq(10)
144
+ expect(response.first['title']).to include('A Lunar L2-Farside')
145
+ end
146
+ end
147
+
148
+ end
149
+ end
@@ -0,0 +1,11 @@
1
+ require 'env_vars'
2
+ require 'vcr'
3
+ require 'ap'
4
+ require 'lateral_recommender'
5
+ require 'webmock/rspec'
6
+
7
+ VCR.configure do |c|
8
+ c.cassette_library_dir = 'spec/fixtures/tapes'
9
+ c.hook_into :webmock
10
+ c.filter_sensitive_data('<API_KEY>') { ENV['API_KEY'] }
11
+ end
metadata ADDED
@@ -0,0 +1,217 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lateral_recommender
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Max Novakovic
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: awesome_print
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: yard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: httpclient
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: activesupport
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description:
140
+ email:
141
+ - max@lateral.io
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - .gitignore
147
+ - Gemfile
148
+ - LICENSE.txt
149
+ - README.md
150
+ - Rakefile
151
+ - lateral_recommender.gemspec
152
+ - lib/lateral_recommender.rb
153
+ - lib/lateral_recommender/version.rb
154
+ - spec/fixtures/article-body.txt
155
+ - spec/fixtures/tapes/add.yml
156
+ - spec/fixtures/tapes/add_user.yml
157
+ - spec/fixtures/tapes/add_user_document.yml
158
+ - spec/fixtures/tapes/invalid_key.yml
159
+ - spec/fixtures/tapes/near_text.yml
160
+ - spec/fixtures/tapes/near_text_arxiv.yml
161
+ - spec/fixtures/tapes/near_text_movies.yml
162
+ - spec/fixtures/tapes/near_text_news.yml
163
+ - spec/fixtures/tapes/near_text_pubmed.yml
164
+ - spec/fixtures/tapes/near_text_wikipedia.yml
165
+ - spec/fixtures/tapes/near_user.yml
166
+ - spec/fixtures/tapes/near_user_arxiv.yml
167
+ - spec/fixtures/tapes/near_user_movies.yml
168
+ - spec/fixtures/tapes/near_user_news.yml
169
+ - spec/fixtures/tapes/near_user_pubmed.yml
170
+ - spec/fixtures/tapes/near_user_wikipedia.yml
171
+ - spec/lateral_recommender_spec.rb
172
+ - spec/spec_helper.rb
173
+ homepage: https://github.com/lateral/recommender-gem
174
+ licenses:
175
+ - MIT
176
+ metadata: {}
177
+ post_install_message:
178
+ rdoc_options: []
179
+ require_paths:
180
+ - lib
181
+ required_ruby_version: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - '>='
184
+ - !ruby/object:Gem::Version
185
+ version: '0'
186
+ required_rubygems_version: !ruby/object:Gem::Requirement
187
+ requirements:
188
+ - - '>='
189
+ - !ruby/object:Gem::Version
190
+ version: '0'
191
+ requirements: []
192
+ rubyforge_project:
193
+ rubygems_version: 2.4.4
194
+ signing_key:
195
+ specification_version: 4
196
+ summary: Wrapper around the Lateral API.
197
+ test_files:
198
+ - spec/fixtures/article-body.txt
199
+ - spec/fixtures/tapes/add.yml
200
+ - spec/fixtures/tapes/add_user.yml
201
+ - spec/fixtures/tapes/add_user_document.yml
202
+ - spec/fixtures/tapes/invalid_key.yml
203
+ - spec/fixtures/tapes/near_text.yml
204
+ - spec/fixtures/tapes/near_text_arxiv.yml
205
+ - spec/fixtures/tapes/near_text_movies.yml
206
+ - spec/fixtures/tapes/near_text_news.yml
207
+ - spec/fixtures/tapes/near_text_pubmed.yml
208
+ - spec/fixtures/tapes/near_text_wikipedia.yml
209
+ - spec/fixtures/tapes/near_user.yml
210
+ - spec/fixtures/tapes/near_user_arxiv.yml
211
+ - spec/fixtures/tapes/near_user_movies.yml
212
+ - spec/fixtures/tapes/near_user_news.yml
213
+ - spec/fixtures/tapes/near_user_pubmed.yml
214
+ - spec/fixtures/tapes/near_user_wikipedia.yml
215
+ - spec/lateral_recommender_spec.rb
216
+ - spec/spec_helper.rb
217
+ has_rdoc: