Permalink
Browse files

Re-generated convenience methods against newly built API

  • Loading branch information...
1 parent 8213464 commit 846a4cb8e835c089970ae95eb5a48740ef5ae630 @zeke zeke committed Jun 13, 2011
Showing with 68 additions and 12 deletions.
  1. +68 −12 lib/wordrabbit/resource_modules/content.rb
@@ -3,8 +3,35 @@
module ContentMethods
- # Adds a new document to the system
- # Tags are optional.
+ # Finds the documents similar to supplied document
+ # Document is not saved in this call, it just returns matched document with score. Higher the score the closer the match
+ #
+ def find_similar(body, *args)
+ http_method = :post
+ path = '/content/findSimilar'
+
+ # Ruby turns all key-value arguments at the end into a single hash
+ # e.g. Wordrabbit.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
+ last_arg = args.pop if args.last.is_a?(Hash)
+ last_arg = args.pop if args.last.is_a?(Array)
+ last_arg ||= {}
+
+ # Look for a kwarg called :request_only, whose presence indicates
+ # that we want the request itself back, not the response body
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
+ request_only = true
+ last_arg.delete(:request_only)
+ end
+
+ params = last_arg
+ body ||= {}
+ request = Wordrabbit::Request.new(http_method, path, :params => params, :body => body)
+ request_only ? request : request.response.body
+ end
+
+ # Adds or updates document to the system
+ # Tags are optional. Update overrides all values with newly supplied values. Use "update" query parameter to override this behavior
#
def upload_document(body, *args)
http_method = :post
@@ -84,6 +111,7 @@ def tag_document(body, *args)
end
# Returns a document by ID
+ # by default it doesn't return content of the document, use "content" query parameter to get the document with content.
#
def get_document_by_id(id, *args)
http_method = :get
@@ -110,12 +138,13 @@ def get_document_by_id(id, *args)
request_only ? request : request.response.body
end
- # Finds the documents similar to supplied document
- # Document is not saved in this call, it just returns matched document with score. Higher the score the closer the match
+ # Finds the documents similar to supplied document id
+ # Higher the score the closer the match
#
- def find_similar(body, *args)
- http_method = :post
- path = '/content/findSimilar'
+ def find_similar_by_id(clientDocumentGUID, *args)
+ http_method = :get
+ path = '/content/findSimilar/{clientDocumentGUID}'
+ path.sub!('{clientDocumentGUID}', clientDocumentGUID.to_s)
# Ruby turns all key-value arguments at the end into a single hash
# e.g. Wordrabbit.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
@@ -137,13 +166,40 @@ def find_similar(body, *args)
request_only ? request : request.response.body
end
- # Finds the documents similar to supplied document id
- # Higher the score the closer the match
+ # Finds documents for a given clientId
+ # By default, returns 10 documents
#
- def find_similar_by_id(clientDocumentGUID, *args)
+ def find_all(*args)
http_method = :get
- path = '/content/findSimilar/{clientDocumentGUID}'
- path.sub!('{clientDocumentGUID}', clientDocumentGUID.to_s)
+ path = '/content/findAll'
+
+ # Ruby turns all key-value arguments at the end into a single hash
+ # e.g. Wordrabbit.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
+ last_arg = args.pop if args.last.is_a?(Hash)
+ last_arg = args.pop if args.last.is_a?(Array)
+ last_arg ||= {}
+
+ # Look for a kwarg called :request_only, whose presence indicates
+ # that we want the request itself back, not the response body
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
+ request_only = true
+ last_arg.delete(:request_only)
+ end
+
+ params = last_arg
+ body ||= {}
+ request = Wordrabbit::Request.new(http_method, path, :params => params, :body => body)
+ request_only ? request : request.response.body
+ end
+
+ # Finds documents for a given tag
+ # By default, returns 10 documents
+ #
+ def find_by_tag(tagName, *args)
+ http_method = :get
+ path = '/content/findByTag/{tagName}'
+ path.sub!('{tagName}', tagName.to_s)
# Ruby turns all key-value arguments at the end into a single hash
# e.g. Wordrabbit.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')

0 comments on commit 846a4cb

Please sign in to comment.