Class: Defensio
- Inherits:
-
Object
- Object
- Defensio
- Defined in:
- lib/defensio.rb
Constant Summary collapse
- API_VERSION =
You shouldn’t modify these values unless you really know what you are doing. And then again…
2.0
- API_HOST =
"http://api.defensio.com"
- LIB_VERSION =
You should’t modify anything below this line.
"0.9"
- ROOT_NODE =
"defensio-result"
- FORMAT =
:yaml
- USER_AGENT =
"Defensio-Ruby #{LIB_VERSION}"
- CLIENT =
"Defensio-Ruby | #{LIB_VERSION} | Carl Mercier | [email protected]"
- KEEP_ALIVE =
false
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Class Method Summary collapse
-
.handle_post_document_async_callback(request) ⇒ Object
See handle_post_document_async_callback.
Instance Method Summary collapse
-
#get_basic_stats ⇒ Array
Get basic statistics for the current user.
-
#get_document(signature) ⇒ Array
Get the status of an existing document.
-
#get_extended_stats(data) ⇒ Array
Get more exhaustive statistics for the current user.
-
#get_user ⇒ Object
Get information about the api key.
-
#handle_post_document_async_callback(request) ⇒ Hash
Takes the request object (Rails, Sinatra, Merb) of an async request callback and returns a hash containing the status of the document being analyzed.
-
#initialize(api_key, client = CLIENT) ⇒ Defensio
constructor
A new instance of Defensio.
-
#post_document(data) ⇒ Array
Create and analyze a new document.
-
#post_profanity_filter(data) ⇒ Object
Filter a set of values based on a pre-defined dictionary.
-
#put_document(signature, data) ⇒ Array
Modify the properties of an existing document.
Constructor Details
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
28 29 30 |
# File 'lib/defensio.rb', line 28 def client @client end |
Class Method Details
Instance Method Details
#get_basic_stats ⇒ Array
Get basic statistics for the current user
65 66 67 |
# File 'lib/defensio.rb', line 65 def get_basic_stats call :get, api_url("basic-stats") end |
#get_document(signature) ⇒ Array
Get the status of an existing document
51 52 53 |
# File 'lib/defensio.rb', line 51 def get_document(signature) call :get, api_url("documents", signature) end |
#get_extended_stats(data) ⇒ Array
Get more exhaustive statistics for the current user
72 73 74 75 76 77 78 79 |
# File 'lib/defensio.rb', line 72 def get_extended_stats(data) result = call(:get, api_url("extended-stats"), data) 0.upto(result[1]["data"].size - 1) do |i| result[1]["data"][i]["date"] = Date.parse(result[1]["data"][i]["date"]) end result end |
#get_user ⇒ Object
Get information about the api key
36 37 38 |
# File 'lib/defensio.rb', line 36 def get_user call :get, api_url end |
#handle_post_document_async_callback(request) ⇒ Hash
Takes the request object (Rails, Sinatra, Merb) of an async request callback and returns a hash containing the status of the document being analyzed.
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/defensio.rb', line 90 def handle_post_document_async_callback(request) if request.is_a?(String) data = request elsif request.respond_to?(:body) && request.body.is_a?(StringIO) data = request.body.read else raise ArgumentError, "Unknown request type: #{request.class}" end parse_body(data) end |
#post_document(data) ⇒ Array
Create and analyze a new document
43 44 45 46 |
# File 'lib/defensio.rb', line 43 def post_document(data) data = { :client => @client }.merge(data) call :post, api_url("documents"), data end |
#post_profanity_filter(data) ⇒ Object
Filter a set of values based on a pre-defined dictionary
82 83 84 |
# File 'lib/defensio.rb', line 82 def post_profanity_filter(data) call :post, api_url("profanity-filter"), data end |
#put_document(signature, data) ⇒ Array
Modify the properties of an existing document
59 60 61 |
# File 'lib/defensio.rb', line 59 def put_document(signature, data) call :put, api_url("documents", signature), data end |