Class: Defensio
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.1"
- 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
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#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
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
32 33 34 |
# File 'lib/defensio.rb', line 32 def api_key @api_key end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
32 33 34 |
# File 'lib/defensio.rb', line 32 def client @client end |
Class Method Details
Instance Method Details
#get_basic_stats ⇒ Array
Get basic statistics for the current user
69 70 71 |
# File 'lib/defensio.rb', line 69 def get_basic_stats respond self.class.get(api_path("basic-stats")) end |
#get_document(signature) ⇒ Array
Get the status of an existing document
55 56 57 |
# File 'lib/defensio.rb', line 55 def get_document(signature) respond self.class.get(api_path("documents", signature)) end |
#get_extended_stats(data) ⇒ Array
Get more exhaustive statistics for the current user
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/defensio.rb', line 76 def get_extended_stats(data) result = self.class.get(api_path("extended-stats"), :query => data) code = result.code result = result[ROOT_NODE] 0.upto(result["data"].size - 1) do |i| result["data"][i]["date"] = Date.parse(result["data"][i]["date"]) end [code, result] end |
#get_user ⇒ Object
Get information about the api key
40 41 42 |
# File 'lib/defensio.rb', line 40 def get_user respond self.class.get(api_path) 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.
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/defensio.rb', line 97 def handle_post_document_async_callback(request) if request.is_a?(String) data = request elsif request.respond_to?(:body) && request.body.respond_to?(:read) 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
47 48 49 50 |
# File 'lib/defensio.rb', line 47 def post_document(data) data = { :client => @client }.merge(data) respond self.class.post(api_path("documents"), :body => data) end |
#post_profanity_filter(data) ⇒ Object
Filter a set of values based on a pre-defined dictionary
89 90 91 |
# File 'lib/defensio.rb', line 89 def post_profanity_filter(data) respond self.class.post(api_path("profanity-filter"), :body => data) end |
#put_document(signature, data) ⇒ Array
Modify the properties of an existing document
63 64 65 |
# File 'lib/defensio.rb', line 63 def put_document(signature, data) respond self.class.put(api_path("documents", signature), :body => data) end |