konstati 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.markdown CHANGED
@@ -20,7 +20,8 @@ Use RubyGems to install this library:
20
20
 
21
21
  Konstati uses HTTP basic authentication, which can be setup using:
22
22
 
23
- Konstati::Base.authenticate(:username => "user", :password => "password")
23
+ Konstati.username = "user"
24
+ Konstati.apikey = "apikey"
24
25
 
25
26
  If authentication fails, Konstati will return 401 Unauhtorized.
26
27
 
@@ -30,56 +31,54 @@ If authentication fails, Konstati will return 401 Unauhtorized.
30
31
 
31
32
  This is a sample request:
32
33
 
33
- result = Konstati::Tests::Spamassassin.create(
34
+ result = Konstati::Tests.create(
34
35
  :bodyHtml => "<p>Hello World</p>", # required
35
36
  :bodyText => "Hello World", # optional
36
37
  :subject => "Free stuff!", # required
37
38
  :fromEmail => "email@example.com", # required
38
39
  :fromName => "John Doe", # required
39
- :lang => "pt_BR", # required
40
40
  :customer => "mycustomerlogin" # optional
41
41
  )
42
42
 
43
43
  The result will contain the following data:
44
44
 
45
- id # (String) unique test id, you can use this to query it
46
- isSpam # (Boolean) if the message is spam or not (thresold: 7.0 points)
47
- lang # (String) language used on the results
48
- score # (Float) total spam score for the message
49
- customer # (String) optional customer name/login
50
- message # (Message) contains all message-related parameters specified in the request
51
- status # (String) status of the spam test (done/processing/error/cancelled)
52
- testDuration # (Float) time it took for the test to be processed (in seconds)
53
- matchedRules # (Array) this Array contains all matched Spamassassin rules,
54
- # where each object contains "ruleName", "description",
55
- # "score" and "tips" (may be empty)
45
+ id # (String) unique test id, you can use this to query it later
46
+ emailMessage # (Hash) contains all message-related parameters specified in the request
47
+ customer # (String) optional customer name/login supplied in the request
48
+ lang # (String) language used on the results
49
+ type # (String) type of test (currently only spamassassin)
50
+ status # (String) status of the spam test (done/processing/error/cancelled)
51
+ startedAt # (Float) when the test was started (in seconds)
52
+ updatedAt # (Float) when the test was last updated (in seconds)
53
+ totalRuntime # (Float) time it took for the test to be processed (in seconds)
54
+ result # (Hash) contains all test result fields (score, isSpam, matchedRules)
56
55
 
57
56
  ### Get a Test Result
58
57
 
59
- result = Konstati::Tests::Spamassassin.find("4d54f05b898d2994e41dde8b")
58
+ result = Konstati::Tests.find("4d54f05b898d2994e41dde8b")
60
59
 
61
60
  If test does not exist, 404 Not Found will be raised.
62
61
 
63
62
  ### List Test Results
64
63
 
65
- results = Konstati::Tests::Spamassassin.find(:all, :params => {})
64
+ results = Konstati::Tests.find(:params => {})
66
65
 
67
66
  Optional parameters in :params may be used to filter results. Available parameters are **lang**,
68
- **status** and **customer**. Each parameter can be used alone or in a combination with other(s).
67
+ **status** and **customer**. Each parameter can be used alone or with other(s).
69
68
 
70
69
  Here are some examples:
71
70
 
72
71
  # all tests performed by "johndoe"
73
- results = Konstati::Tests::Spamassassin.find(:all, :params => {:customer => "johndoe"})
72
+ results = Konstati::Tests.find(:params => {:customer => "johndoe"})
74
73
 
75
- # all tests in pt_BR by "johndoe"
76
- results = Konstati::Tests::Spamassassin.find(:all, :params => {:customer => "johndoe", :lang => "pt_BR"})
74
+ # all tests in pt by "johndoe"
75
+ results = Konstati::Tests.find(:params => {:customer => "johndoe", :lang => "pt"})
77
76
 
78
- # all tests with "done" status in "en_EN"
79
- results = Konstati::Tests::Spamassassin.find(:all, :params => {:status => "done", :lang => "en_EN"})
77
+ # all tests with "done" status in "en"
78
+ results = Konstati::Tests .find(:params => {:status => "done", :lang => "en"})
80
79
 
81
80
  You can also perform pagination using **perPage** and **pageNumber** parameters. Default behavior is to
82
81
  return the first 20 results. These parameters can also be used together with filters:
83
82
 
84
- # give me 40 tests performed by "johndoe" in pt_BR
85
- results = Konstati::Tests::Spamassassin.find(:all, :params => {:lang => "en_EN", :perPage => 40, :customer => "johndoe"})
83
+ # give me 40 tests performed by "johndoe" in pt
84
+ results = Konstati::Tests.find(:params => {:lang => "en", :perPage => 40, :customer => "johndoe"})
@@ -0,0 +1,11 @@
1
+ require '../lib/konstati'
2
+ require '../lib/konstati/account'
3
+
4
+ Konstati.username = ''
5
+ Konstati.apikey = ''
6
+
7
+ info = Konstati::Account.info
8
+
9
+ credits = info['rateLimit']['max'] - info['rateLimit']['current']
10
+
11
+ puts "I still have #{credits} credits left."
@@ -0,0 +1,17 @@
1
+ require '../lib/konstati'
2
+
3
+ Konstati.username = ''
4
+ Konstati.apikey = ''
5
+
6
+ test = Konstati::Test.create(
7
+ :type => "spamassassin",
8
+ :bodyHtml => "<p>Hello World</p>",
9
+ :bodyText => "Hello World",
10
+ :subject => "CHEAP VIAGRA!!!!",
11
+ :fromEmail => "email@example.com",
12
+ :fromName => "John Doe",
13
+ :lang => "pt",
14
+ :customer => "mycustomerlogin"
15
+ )
16
+
17
+ puts "This email has scored #{test['result']['score']} points in SpamAssassin."
data/lib/konstati.rb CHANGED
@@ -1,39 +1,51 @@
1
- require "active_resource"
1
+ require 'restclient'
2
+ require 'json'
3
+
4
+ require File.dirname(__FILE__) + '/konstati/account'
5
+ require File.dirname(__FILE__) + '/konstati/tests'
2
6
 
3
7
  module Konstati
4
8
 
5
- VERSION = "0.1.0"
9
+ VERSION = '0.2.0'
6
10
 
7
- class Base < ActiveResource::Base
11
+ def self.endpoint
12
+ @endpoint ||= "https://api.konstati.co/v1"
13
+ end
8
14
 
9
- self.format = :json
10
- self.site = "http://api.konstati.co/"
11
- self.headers['User-Agent'] = "Konstati Ruby Client v0.1"
15
+ def self.endpoint=(val)
16
+ @endpoint = val
17
+ end
12
18
 
13
- def self.authenticate(options)
14
- self.user = options[:username]
15
- self.password = options[:password]
19
+ def self.username
20
+ @username
16
21
  end
17
22
 
18
- def self.element_path(id, prefix_options = {}, query_options = nil)
19
- prefix_options, query_options = split_options(prefix_options) if query_options.nil?
20
- "#{prefix(prefix_options)}#{collection_name}/#{id}#{query_string(query_options)}"
23
+ def self.username=(val)
24
+ @username = val
21
25
  end
22
26
 
23
- def self.collection_path(prefix_options = {}, query_options = nil)
24
- prefix_options, query_options = split_options(prefix_options) if query_options.nil?
25
- "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
27
+ def self.apikey=(val)
28
+ @apikey = val
26
29
  end
27
- end
28
30
 
29
- module Tests
31
+ def self.apikey
32
+ @apikey
33
+ end
30
34
 
31
- class Spamassassin < Base
32
- self.site = "http://api.konstati.co/"
33
- self.collection_name = "tests/spamassassin"
34
- self.element_name = "tests/spamassassin"
35
+ def self.resource(path)
36
+ RestClient::Resource.new(@endpoint + path, @username, @apikey)
35
37
  end
36
38
 
37
- end
39
+ def self.request(method, path, params = {})
40
+ JSON.parse(
41
+ RestClient::Request.execute(
42
+ :method => method,
43
+ :url => endpoint + path,
44
+ :payload => params,
45
+ :user => @username,
46
+ :password => @apikey
47
+ )
48
+ )
49
+ end
38
50
 
39
51
  end
@@ -0,0 +1,15 @@
1
+ require 'json'
2
+
3
+ module Konstati
4
+ class Account
5
+
6
+ def self.initialize
7
+ puts 'bola'
8
+ end
9
+
10
+ def self.info
11
+ Konstati.request("get", "/account")
12
+ # RestClient::Resource.new(Konstati::Config.endpoint + '/account', Konstati::Config.username, Konstati::Config.apikey).get
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ module Konstati
2
+
3
+ class Tests
4
+
5
+ def self.create(params)
6
+ Konstati.request(:post, '/tests', params)
7
+ end
8
+
9
+ def self.find(params = {})
10
+ Konstati.request(:get, '/tests', params)
11
+ end
12
+
13
+ def self.delete(id)
14
+ Konstati.request(:delete, '/tests/' + id)
15
+ end
16
+
17
+ def self.get(id)
18
+ Konstati.request(:get, '/tests/' + id)
19
+ end
20
+
21
+ end
22
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: konstati
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pedro Padron
@@ -15,11 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-11 00:00:00 -02:00
18
+ date: 2011-08-18 00:00:00 -03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: activeresource
22
+ name: json
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
@@ -32,6 +32,20 @@ dependencies:
32
32
  version: "0"
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: restclient
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
35
49
  description: Ruby client to the Konstati API
36
50
  email: ppadron@w3p.com.br
37
51
  executables: []
@@ -41,8 +55,14 @@ extensions: []
41
55
  extra_rdoc_files:
42
56
  - README.markdown
43
57
  - LICENSE
58
+ - examples/account_info.rb
59
+ - examples/create_spamassassin_test.rb
44
60
  files:
45
61
  - lib/konstati.rb
62
+ - lib/konstati/account.rb
63
+ - lib/konstati/tests.rb
64
+ - examples/account_info.rb
65
+ - examples/create_spamassassin_test.rb
46
66
  - README.markdown
47
67
  - LICENSE
48
68
  has_rdoc: true