Module: Ingenia::Api
- Extended by:
- Api
- Defined in:
- lib/ingenia_api.rb,
lib/ingenia_api/remote.rb
Defined Under Namespace
Modules: Remote Classes: CallFailed
Constant Summary collapse
- API_KNOWN_PARAMS =
%w( limit text )
Instance Method Summary collapse
- #api_key ⇒ Object
- #api_key=(k) ⇒ Object
-
#classify(text) ⇒ Object
Classify some text.
- #debug=(dbg) ⇒ Object
- #endpoint=(ep) ⇒ Object
-
#similar_to(params = {}) ⇒ Object
Find similar items.
-
#status ⇒ Object
Status of your app.
-
#summarize(params = {}) ⇒ Object
Summarize some text.
-
#train(text, tags = {}) ⇒ Object
Deprecated train action, now creates an item.
- #trained_tags ⇒ Object
- #verify_response ⇒ Object
- #version=(v) ⇒ Object
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
Classify some text
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
Find similar items
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
Status of your app
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
Summarize some text
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, = {}) debug { "train" } if .is_a? Array Item.create(:json => { :text => text, :tags => }) elsif .is_a? Hash Item.create(:json => { :text => text, :tag_sets => }) else raise "Ingenia::Api.train(text, tags) must be called with tags argument as either an Array or a Hash" end end |
#trained_tags ⇒ Object
76 77 78 79 |
# File 'lib/ingenia_api.rb', line 76 def 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 |