ingenia_api 1.0.6

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 @@
1
+ {"status":"okay","api_version":"1.0","start":0,"total":0,"limit":25,"knowledge_items":[]}
@@ -0,0 +1 @@
1
+ {}
@@ -0,0 +1 @@
1
+ {"status":"okay","api_version":"1.0","start":0,"total":5,"limit":25,"knowledge_items":[{"id":859,"":[]},{"id":858,"":[]},{"id":857,"":[]},{"id":856,"":[]},{"id":855,"":[]}]}
@@ -0,0 +1,2 @@
1
+ { "status": "okay", "api_version": "1.0", "knowledge_item" :
2
+ { "title": "A Knowledge Item", "id": 123, "tags": "some tags about this item", "status": "okay", "words": "words in this knowledge item they are unique", "source": "upload", "created": 1336468441 } }
@@ -0,0 +1 @@
1
+ {"status":"okay","api_version":"1.0","start":0,"total":1,"limit":25,"knowledge_items": [{"id":859,"":[]},{"id":858,"":[]},{"id":857,"":[]},{"id":856,"":[]},{"id":855,"":[]}]}
@@ -0,0 +1 @@
1
+ {"report":{"generated":"2012-05-03T12:48:47+01:00"},"server":{"uptime":"12:48:47 up 10 days, 5:20, 1 user, load average: 0.08, 0.24, 0.30"},"nowa":{"released":"2012-04-24T17:54:44+01:00"},"resque":{"info":{"pending":965,"processed":5846,"queues":5,"workers":0,"working":0,"failed":720,"servers":["redis://localhost:6379/0"],"environment":"development"},"queues":["google_doc_downloader_queue","learner_queue","word_counter_queue","url_fetch_queue","classifier_queue"]},"word_service":{"url":"http://localhost:9000/status","status":{"exception":"Connection refused - connect(2)"}},"weight_service":{"url":"http://localhost:9030/status","status":{"exception":"Connection refused - connect(2)"}},"word_count_service":{"url":"http://localhost:9040/status","status":{"exception":"Connection refused - connect(2)"}},"knowledge_item_service":{"url":"http://localhost:9050/status","status":{"exception":"Connection refused - connect(2)"}}}
@@ -0,0 +1 @@
1
+ { "status" : "okay" }
@@ -0,0 +1 @@
1
+ { "tags" : "a string of tags" }
@@ -0,0 +1,126 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ingenia::Api do
4
+
5
+ let( :empty_api_response ) { { 'status' => 'okay', 'data' => {} } }
6
+
7
+ before :each do
8
+ Ingenia::Api.api_key = '1234'
9
+ Ingenia::Api.version = nil
10
+ end
11
+
12
+ describe 'versioning' do
13
+ describe '::version' do
14
+
15
+ it 'is default' do
16
+ expect(Ingenia::Api::Remote.version).to eq 2.0
17
+ end
18
+
19
+ it 'can be set' do
20
+ Ingenia::Api::version = 1.0
21
+ expect(Ingenia::Api::Remote.version).to eq 1.0
22
+ end
23
+ end
24
+
25
+ describe 'path' do
26
+ it 'calls v2 by default' do
27
+ stub_request(:post, "api.ingeniapi.com/v2/classify")
28
+ .to_return( :body => '{"status":"okay","api_version":"1.0","data":{}}', :status => 200 )
29
+
30
+ Ingenia::Api.classify 'some text'
31
+ end
32
+
33
+ it 'calls without v2 if set to older version' do
34
+ stub_request(:post, "api.ingeniapi.com/classify")
35
+ .to_return( :body => '{"status":"okay","api_version":"1.0","data":{}}', :status => 200 )
36
+
37
+ Ingenia::Api.version = 1.0
38
+ Ingenia::Api.classify 'some text'
39
+ end
40
+
41
+ it 'calls correctly if set to 2.0' do
42
+ stub_request(:post, "api.ingeniapi.com/v2/classify")
43
+ .to_return( :body => '{"status":"okay","api_version":"1.0","data":{}}', :status => 200 )
44
+
45
+ Ingenia::Api.version = 2.0
46
+ Ingenia::Api.classify 'some text'
47
+ end
48
+
49
+ end
50
+ end
51
+
52
+ describe '::classify' do
53
+ it 'calls remote url properly' do
54
+
55
+ expect(Ingenia::Api::Remote).to receive( :post ).
56
+ with( '/classify', :text => 'some text', :api_key => '1234' ).
57
+ and_return( empty_api_response )
58
+
59
+ Ingenia::Api.classify 'some text'
60
+ end
61
+ end
62
+
63
+ describe '::train' do
64
+ it 'calls remote url properly with array tags' do
65
+
66
+ expect(Ingenia::Api::Remote).to receive( :post ).
67
+ with( '/items', :json => { :text => 'some text', :tags => %w{ some tags } }.to_json, :api_key => '1234' ).
68
+ and_return( empty_api_response )
69
+
70
+ Ingenia::Api.train 'some text', %w{ some tags }
71
+ end
72
+
73
+ it 'calls remote url properly with nested tags' do
74
+
75
+ tags = {
76
+ :tag_set_1 => %w{ tag1 tag2 tag3 },
77
+ :tag_set_2 => %w{ tag4 tag5 tag6 }
78
+ }
79
+
80
+ test_payload = {
81
+ :json => { :text => 'some text', :tag_sets => tags }.to_json,
82
+ :api_key => '1234'
83
+ }
84
+
85
+ expect(Ingenia::Api::Remote).to receive( :post ).
86
+ with( '/items', test_payload ).
87
+ and_return( empty_api_response )
88
+
89
+ Ingenia::Api.train 'some text', tags
90
+ end
91
+ end
92
+
93
+ describe '::summarize' do
94
+ it 'calls remote url properly' do
95
+
96
+ expect(Ingenia::Api::Remote).to receive( :post ).
97
+ with( "/summarise", :api_key => '1234', :text => "this is some long-winded text" ).
98
+ and_return( empty_api_response )
99
+
100
+ Ingenia::Api.summarize :text => "this is some long-winded text"
101
+ end
102
+ end
103
+
104
+
105
+ describe '::endpoint' do
106
+
107
+ it 'is default' do
108
+ expect(Ingenia::Api::Remote.endpoint).to eq 'api.ingeniapi.com'
109
+ end
110
+
111
+ it 'can be set' do
112
+ Ingenia::Api::endpoint = 'hoopla.com'
113
+ expect(Ingenia::Api::Remote.endpoint).to eq 'hoopla.com'
114
+ end
115
+
116
+ it 'can take port numbers' do
117
+ Ingenia::Api::endpoint = 'hoopla.com:8080'
118
+ expect(Ingenia::Api::Remote.endpoint).to eq 'hoopla.com'
119
+ expect(Ingenia::Api::Remote.port).to eq 8080
120
+ end
121
+ end
122
+
123
+
124
+ end
125
+
126
+
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ingenia::Bundle do
4
+ let( :empty_api_response ) { { 'status' => 'okay', 'data' => {} } }
5
+
6
+
7
+ describe '#create' do
8
+ it 'calls post' do
9
+ name = "this is a test bundle"
10
+
11
+ expected_path = '/bundles'
12
+ expected_request = {:api_key=>"1234", :json=>"{\"name\":\"this is a test bundle\"}"}
13
+
14
+ expect(Ingenia::Api::Remote).to receive( :post ).
15
+ with( expected_path, expected_request).
16
+ and_return( empty_api_response )
17
+
18
+ Ingenia::Bundle.create( :name => name )
19
+ end
20
+ end
21
+
22
+
23
+ describe '#update' do
24
+ it 'calls put' do
25
+ name = "this is an updated test bundle"
26
+
27
+ expected_path = '/bundles/1'
28
+ expected_request = { :json=>"{\"name\":\"#{name}\"}", :api_key=>"1234" }
29
+
30
+ expect(Ingenia::Api::Remote).to receive( :put ).
31
+ with( expected_path, expected_request).
32
+ and_return( empty_api_response )
33
+
34
+ Ingenia::Bundle.update( 1, :name => name )
35
+ end
36
+ end
37
+
38
+ describe '#get' do
39
+ it 'calls get' do
40
+ expected_path = '/bundles/1'
41
+ expected_request = { :api_key=>"1234" }
42
+
43
+ expect(Ingenia::Api::Remote).to receive( :get ).
44
+ with( expected_path, expected_request).
45
+ and_return( empty_api_response )
46
+
47
+ Ingenia::Bundle.get(1)
48
+ end
49
+ end
50
+
51
+ describe '#all' do
52
+ it 'calls get' do
53
+ expected_path = '/bundles'
54
+ expected_request = { :offset => 0, :limit => 50, :api_key=>"1234" }
55
+
56
+ expect(Ingenia::Api::Remote).to receive( :get ).
57
+ with( expected_path, expected_request).
58
+ and_return( empty_api_response )
59
+
60
+ Ingenia::Bundle.all :offset => 0, :limit => 50
61
+ end
62
+ end
63
+
64
+ describe '#delete' do
65
+ it 'calls delete' do
66
+ expected_path = '/bundles/1'
67
+ expected_request = {:params=>{:api_key=>"1234"}}
68
+
69
+ expect(Ingenia::Api::Remote).to receive( :delete ).
70
+ with( expected_path, expected_request).
71
+ and_return( empty_api_response )
72
+
73
+ Ingenia::Bundle.destroy(1)
74
+ end
75
+ end
76
+ end
77
+
78
+
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ingenia::HtmlExtractor do
4
+ let( :empty_api_response ) { { 'status' => 'okay', 'data' => {} } }
5
+
6
+
7
+ describe '#fetch' do
8
+ it 'calls fetch' do
9
+ expected_path = '/html_extractor/fetch'
10
+ expected_request = { :api_key=>"1234", :url=>'http://test.com/url' }
11
+
12
+ expect(Ingenia::Api::Remote).to receive( :get ).
13
+ with( expected_path, expected_request).
14
+ and_return( empty_api_response )
15
+
16
+ described_class.fetch(url: 'http://test.com/url')
17
+ end
18
+
19
+ describe 'url validation' do
20
+ it 'raise an error when not url param passed' do
21
+ expect {
22
+ described_class.fetch({})
23
+ }.to raise_error(described_class::MissingUrl)
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+
@@ -0,0 +1,115 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ingenia::Item do
4
+ let( :empty_api_response ) { { 'status' => 'okay', 'data' => {} } }
5
+
6
+
7
+ describe '#create' do
8
+ it 'calls post' do
9
+ text = "this is a test"
10
+
11
+ expected_path = '/items'
12
+ expected_request = {:json=>"{\"text\":\"this is a test\"}", :api_key=>"1234"}
13
+
14
+ expect(Ingenia::Api::Remote).to receive( :post ).
15
+ with( expected_path, expected_request).
16
+ and_return( empty_api_response )
17
+
18
+ Ingenia::Item.create(:json => { :text => text })
19
+ end
20
+ end
21
+
22
+
23
+ describe '#update' do
24
+ it 'calls put' do
25
+ text = "this is some updated text"
26
+
27
+ expected_path = '/items/1'
28
+ expected_request = {:json=>"{\"text\":\"this is some updated text\"}", :api_key=>"1234"}
29
+
30
+ expect(Ingenia::Api::Remote).to receive( :put ).
31
+ with( expected_path, expected_request).
32
+ and_return( empty_api_response )
33
+
34
+ Ingenia::Item.update(1, :json => { :text => text })
35
+ end
36
+ end
37
+
38
+ describe '#get' do
39
+ it 'calls get' do
40
+ expected_path = '/items/1'
41
+ expected_request = { :api_key=>"1234" }
42
+
43
+ expect(Ingenia::Api::Remote).to receive( :get ).
44
+ with( expected_path, expected_request).
45
+ and_return( empty_api_response )
46
+
47
+ Ingenia::Item.get(1)
48
+ end
49
+
50
+ it 'calls get for a specific bundle' do
51
+ expected_path = '/items/1'
52
+ expected_request = { :api_key=>"1234", :bundle_id=>257 }
53
+
54
+ expect(Ingenia::Api::Remote).to receive( :get ).
55
+ with( expected_path, expected_request).
56
+ and_return( empty_api_response )
57
+
58
+ Ingenia::Item.get(1, :bundle_id => 257)
59
+ end
60
+ end
61
+
62
+ describe '#all' do
63
+ it 'calls get for non full text' do
64
+ expected_path = '/items'
65
+ expected_request = { :offset => 0, :limit => 10, :api_key=>"1234" }
66
+
67
+ expect(Ingenia::Api::Remote).to receive( :get ).
68
+ with( expected_path, expected_request).
69
+ and_return( empty_api_response )
70
+
71
+ Ingenia::Item.all(:offset => 0, :limit => 10)
72
+ end
73
+
74
+ it 'calls get for full text' do
75
+ expected_path = '/items'
76
+ expected_request = { :offset => 0, :limit => 10, :api_key=>"1234", :full_text=>true }
77
+
78
+ expect(Ingenia::Api::Remote).to receive( :get ).
79
+ with( expected_path, expected_request).
80
+ and_return( empty_api_response )
81
+
82
+ Ingenia::Item.all(:offset => 0, :limit => 10, :full_text => true)
83
+ end
84
+ end
85
+
86
+ describe '#destroy' do
87
+ it 'calls delete' do
88
+ expected_path = '/items/1'
89
+ expected_request = {:params=>{:api_key=>"1234"}}
90
+
91
+ expect(Ingenia::Api::Remote).to receive( :delete ).
92
+ with( expected_path, expected_request).
93
+ and_return( empty_api_response )
94
+
95
+ Ingenia::Item.destroy(1)
96
+ end
97
+ end
98
+
99
+ describe '#similar_to' do
100
+ it 'calls similar_to' do
101
+
102
+ expected_path = '/items/1/similar_to'
103
+ expected_request = { :api_key => "1234", mode: 'word' }
104
+
105
+ expect(Ingenia::Api::Remote).to receive( :get ).
106
+ with( expected_path, expected_request).
107
+ and_return( empty_api_response )
108
+
109
+ Ingenia::Item.similar_to(1, :word)
110
+ end
111
+ end
112
+
113
+ end
114
+
115
+
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ingenia::TagSet do
4
+ let( :empty_api_response ) { { 'status' => 'okay', 'data' => {} } }
5
+
6
+
7
+ describe '#create' do
8
+ it 'calls post' do
9
+ name = "this is a test tagset"
10
+
11
+ expected_path = '/tag_sets'
12
+ expected_request = {:json=>"{\"name\":\"#{name}\"}", :api_key=>"1234"}
13
+
14
+ expect(Ingenia::Api::Remote).to receive( :post ).
15
+ with( expected_path, expected_request).
16
+ and_return( empty_api_response )
17
+
18
+ Ingenia::TagSet.create(:name => name)
19
+ end
20
+ end
21
+
22
+
23
+ describe '#update' do
24
+ it 'calls put' do
25
+ name = "this is an updated test tagset"
26
+
27
+ expected_path = '/tag_sets/1'
28
+ expected_request = {:json=>"{\"name\":\"#{name}\"}", :api_key=>"1234"}
29
+
30
+ expect(Ingenia::Api::Remote).to receive( :put ).
31
+ with( expected_path, expected_request).
32
+ and_return( empty_api_response )
33
+
34
+ Ingenia::TagSet.update(1, :name => name)
35
+ end
36
+ end
37
+
38
+ describe '#get' do
39
+ it 'calls get' do
40
+ expected_path = '/tag_sets/1'
41
+ expected_request = { :api_key=>"1234" }
42
+
43
+ expect(Ingenia::Api::Remote).to receive( :get ).
44
+ with( expected_path, expected_request).
45
+ and_return( empty_api_response )
46
+
47
+ Ingenia::TagSet.get(1)
48
+ end
49
+ end
50
+
51
+ describe '#all' do
52
+ it 'calls get' do
53
+ expected_path = '/tag_sets'
54
+ expected_request = { :offset => 0, :limit => 50, :api_key=>"1234" }
55
+
56
+ expect(Ingenia::Api::Remote).to receive( :get ).
57
+ with( expected_path, expected_request).
58
+ and_return( empty_api_response )
59
+
60
+ Ingenia::TagSet.all :offset => 0, :limit => 50
61
+ end
62
+ end
63
+
64
+ describe '#delete' do
65
+ it 'calls delete' do
66
+ expected_path = '/tag_sets/1'
67
+ expected_request = {:params=>{:api_key=>"1234"}}
68
+
69
+ expect(Ingenia::Api::Remote).to receive( :delete ).
70
+ with( expected_path, expected_request).
71
+ and_return( empty_api_response )
72
+
73
+ Ingenia::TagSet.destroy(1)
74
+ end
75
+ end
76
+ end
77
+
78
+