Module: Ingenia::Api
Defined Under Namespace
Modules: Remote
Classes: CallFailed
Constant Summary
collapse
- API_KNOWN_PARAMS =
%w( limit text )
Instance Method Summary
collapse
Instance Method Details
#api_key ⇒ Object
96
97
98
99
|
# File 'lib/ingenia_api.rb', line 96
def api_key
raise 'Ingenia::Api.api_key not set' if @api_key.nil?
@api_key
end
|
#api_key=(k) ⇒ Object
91
92
93
94
|
# File 'lib/ingenia_api.rb', line 91
def api_key=(k)
debug { "api_key=#{k}" }
@api_key = k
end
|
#classify(text) ⇒ Object
36
37
38
39
|
# File 'lib/ingenia_api.rb', line 36
def classify(text)
debug { "classify" }
verify_response { Remote.post('/classify', :api_key => api_key, :text => text) }
end
|
#debug=(dbg) ⇒ Object
101
102
103
104
|
# File 'lib/ingenia_api.rb', line 101
def debug=(dbg)
@debug = dbg
debug { "debug is on" }
end
|
#endpoint=(ep) ⇒ Object
81
82
83
84
|
# File 'lib/ingenia_api.rb', line 81
def endpoint=(ep)
debug { "endpoint=#{Remote.endpoint}" }
Remote.endpoint = ep
end
|
#similar_to(params = {}) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/ingenia_api.rb', line 56
def similar_to( params = {} )
debug { "similar_to" }
initialize_params params
if params.has_key? :text
verify_response { Remote.post("/similar_to_text", @params ) }
elsif params.has_key? :tag_ids
verify_response { Remote.get("/similar_to_tags", @params ) }
end
end
|
#status ⇒ Object
30
31
32
33
|
# File 'lib/ingenia_api.rb', line 30
def status
debug { "status" }
verify_response { Remote.get('/status', :api_key => api_key ) }
end
|
#summarize(params = {}) ⇒ Object
69
70
71
72
73
74
|
# File 'lib/ingenia_api.rb', line 69
def summarize(params = {})
debug { "summarize" }
initialize_params params
verify_response { Remote.post("/summarise", @params ) }
end
|
#train(text, tags = {}) ⇒ Object
Deprecated train action, now creates an item
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/ingenia_api.rb', line 42
def train(text, tags = {})
debug { "train" }
if tags.is_a? Array
Item.create(:json => { :text => text, :tags => tags })
elsif tags.is_a? Hash
Item.create(:json => { :text => text, :tag_sets => tags })
else
raise "Ingenia::Api.train(text, tags) must be called with tags argument as either an Array or a Hash"
end
end
|
76
77
78
79
|
# File 'lib/ingenia_api.rb', line 76
def trained_tags
debug { "trained_tags" }
verify_response { Remote.get('/learnt_tags', :api_key => api_key) }
end
|
#verify_response ⇒ Object
106
107
108
109
110
111
112
|
# File 'lib/ingenia_api.rb', line 106
def verify_response
output = yield
return output['data'] unless output['data'].nil?
raise CallFailed.new( output )
end
|
#version=(v) ⇒ Object
86
87
88
89
|
# File 'lib/ingenia_api.rb', line 86
def version=(v)
debug { "version=#{Remote.version}" }
Remote.version = v
end
|