Class: Emailage::Client
- Inherits:
-
Object
- Object
- Emailage::Client
- Defined in:
- lib/emailage/client.rb
Instance Attribute Summary collapse
-
#hmac_key ⇒ Object
readonly
Returns the value of attribute hmac_key.
-
#raise_errors ⇒ Object
Returns the value of attribute raise_errors.
-
#sandbox ⇒ Object
readonly
Returns the value of attribute sandbox.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
-
#flag(flag, query, fraud_code = nil) ⇒ Object
Mark an email address as fraud, good, or neutral.
-
#flag_as_fraud(query, fraud_code) ⇒ Object
Mark an email address as fraud.
-
#flag_as_good(query) ⇒ Object
Mark an email address as good.
-
#initialize(secret, token, options = {}) ⇒ Client
constructor
A new instance of Client.
-
#query(query, params = {}) ⇒ Object
Query a risk score information for the provided email address, IP address, or a combination.
-
#query_email(email, params = {}) ⇒ Object
Query a risk score information for the provided email address.
-
#query_email_and_ip_address(email, ip, params = {}) ⇒ Object
Query a risk score information for the provided combination of an Email and IP address.
-
#query_ip_address(ip, params = {}) ⇒ Object
Query a risk score information for the provided IP address.
-
#remove_flag(query) ⇒ Object
Unflag an email address that was marked as good or fraud previously.
Constructor Details
#initialize(secret, token, options = {}) ⇒ Client
HMAC key is created according to Emailage docs.
Returns a new instance of Client.
17 18 19 20 21 22 23 24 |
# File 'lib/emailage/client.rb', line 17 def initialize(secret, token, ={}) @secret, @token = secret, token @sandbox = .fetch :sandbox, false @raise_errors = .fetch :raise_errors, false # @hmac_key = [@secret, @token].map {|e| CGI.escape(e)}.join '&' @hmac_key = @token + '&' end |
Instance Attribute Details
#hmac_key ⇒ Object (readonly)
Returns the value of attribute hmac_key.
7 8 9 |
# File 'lib/emailage/client.rb', line 7 def hmac_key @hmac_key end |
#raise_errors ⇒ Object
Returns the value of attribute raise_errors.
8 9 10 |
# File 'lib/emailage/client.rb', line 8 def raise_errors @raise_errors end |
#sandbox ⇒ Object (readonly)
Returns the value of attribute sandbox.
7 8 9 |
# File 'lib/emailage/client.rb', line 7 def sandbox @sandbox end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
7 8 9 |
# File 'lib/emailage/client.rb', line 7 def secret @secret end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
7 8 9 |
# File 'lib/emailage/client.rb', line 7 def token @token end |
Instance Method Details
#flag(flag, query, fraud_code = nil) ⇒ Object
Mark an email address as fraud, good, or neutral.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/emailage/client.rb', line 116 def flag(flag, query, fraud_code=nil) flags = %w[fraud neutral good] unless flags.include? flag.to_s raise ArgumentError, "flag must be one of #{flags * ', '}. #{flag} is given." end Validation.validate_email! query query *= '+' if query.is_a? Array params = {:flag => flag, :query => query} if flag == 'fraud' unless (1..9).to_a.include? fraud_code raise ArgumentError, "fraud_code must be an integer from 1 to 9 corresponding to #{FRAUD_CODES.values*', '}. #{fraud_code} is given." end params[:fraudcodeID] = fraud_code end request '/flag', params end |
#flag_as_fraud(query, fraud_code) ⇒ Object
Mark an email address as fraud.
144 145 146 |
# File 'lib/emailage/client.rb', line 144 def flag_as_fraud(query, fraud_code) flag 'fraud', query, fraud_code end |
#flag_as_good(query) ⇒ Object
Mark an email address as good.
152 153 154 |
# File 'lib/emailage/client.rb', line 152 def flag_as_good(query) flag 'good', query end |
#query(query, params = {}) ⇒ Object
Query a risk score information for the provided email address, IP address, or a combination.
63 64 65 66 |
# File 'lib/emailage/client.rb', line 63 def query(query, params={}) query *= '+' if query.is_a? Array request '', params.merge(:query => query) end |
#query_email(email, params = {}) ⇒ Object
Query a risk score information for the provided email address. This method differs from #query in that it ensures that the string supplied is in rfc2822 format.
75 76 77 78 |
# File 'lib/emailage/client.rb', line 75 def query_email(email, params={}) Validation.validate_email! email query email, params end |
#query_email_and_ip_address(email, ip, params = {}) ⇒ Object
Query a risk score information for the provided combination of an Email and IP address. This method differs from #query in that it ensures that the strings supplied are in rfc2822 and rfc791 formats.
100 101 102 103 104 |
# File 'lib/emailage/client.rb', line 100 def query_email_and_ip_address(email, ip, params={}) Validation.validate_email! email Validation.validate_ip! ip query [email, ip], params end |
#query_ip_address(ip, params = {}) ⇒ Object
Query a risk score information for the provided IP address. This method differs from #query in that it ensures that the string supplied is in rfc791 format.
87 88 89 90 |
# File 'lib/emailage/client.rb', line 87 def query_ip_address(ip, params={}) Validation.validate_ip! ip query ip, params end |
#remove_flag(query) ⇒ Object
Unflag an email address that was marked as good or fraud previously.
160 161 162 |
# File 'lib/emailage/client.rb', line 160 def remove_flag(query) flag 'neutral', query end |