class Maxmind::Request
Constants
- DefaultTimeout
Attributes
Optional Fields
Optional Fields
Optional Fields
Optional Fields
Optional Fields
Required Fields
Required Fields
Required Fields
Optional Fields
Optional Fields
Optional Fields
Optional Fields
Optional Fields
Optional Fields
Optional Fields
Optional Fields
Required Fields
Required Fields
Optional Fields
Optional Fields
Optional Fields
Optional Fields
Optional Fields
Optional Fields
Optional Fields
Optional Fields
Optional Fields
Optional Fields
Optional Fields
Public Class Methods
# File lib/maxmind/request.rb, line 22 def initialize(attrs={}) self.attributes = attrs end
Public Instance Methods
# File lib/maxmind/request.rb, line 26 def attributes=(attrs={}) attrs.each do |k, v| self.send("#{k}=", v) end end
if a full card number is passed, grab just the first 6 digits (which is the bank id number)
# File lib/maxmind/request.rb, line 57 def bin=(bin) @bin = bin ? bin[0,6] : nil end
email domain … if a full email is provided, take just the domain portion
# File lib/maxmind/request.rb, line 33 def domain=(email) @domain = if email =~ /@(.+)/ $1 else email end end
customer email … sends just an MD5 hash of the email. also sets the email domain at the same time.
# File lib/maxmind/request.rb, line 43 def email=(email) @email = md5_digest(email) self.domain = email unless domain end
# File lib/maxmind/request.rb, line 52 def password=(password) @password = md5_digest(password) end
# File lib/maxmind/request.rb, line 67 def process process! rescue Exception => e false end
# File lib/maxmind/request.rb, line 61 def process! resp = post(query) resp.body.encode!("utf-8", "iso-8859-1") if resp.body.respond_to?(:encode!) Maxmind::Response.new(resp.body, resp.code) end
# File lib/maxmind/request.rb, line 73 def query validate required_fields = { :i => @client_ip, :city => @city, :region => @region, :postal => @postal, :country => @country, :license_key => Maxmind::license_key } optional_fields = { :domain => @domain, :bin => @bin, :binName => @bin_name, :binPhone => @bin_phone, :custPhone => @cust_phone, :requested_type => @request_type || self.class.default_request_type, :forwardedIP => @forwarded_ip, :emailMD5 => @email, :usernameMD5 => @username, :passwordMD5 => @password, :shipAddr => @shipping_address, :shipCity => @shipping_city, :shipRegion => @shipping_region, :shipPostal => @shipping_postal, :shipCountry => @shipping_country, :txnID => @transaction_id, :sessionID => @session_id, :user_agent => @user_agent, :accept_language => @accept_language, :avs_result => @avs_result, :cvv_result => @cvv_result, :txn_type => @txn_type, :order_amount => @order_amount, :order_currency => @order_currency } field_set = required_fields.merge(optional_fields) field_set.reject {|k, v| v.nil? } end
# File lib/maxmind/request.rb, line 48 def username=(username) @username = md5_digest(username) end
Protected Instance Methods
# File lib/maxmind/request.rb, line 153 def validate raise ArgumentError, 'License key is required' unless Maxmind::license_key raise ArgumentError, 'IP address is required' unless client_ip end
Private Instance Methods
# File lib/maxmind/request.rb, line 144 def md5_digest(value) if value =~ /^[0-9a-f]{32}$/i value else Digest::MD5.hexdigest(value.downcase) end end
Upon a failure at the first URL, will automatically retry with the second & third ones before finally raising an exception Returns an HTTPResponse object
# File lib/maxmind/request.rb, line 121 def post(query_params) servers ||= SERVERS.map{|hostname| "https://#{hostname}/app/ccv2r"} url = URI.parse(servers.shift) req = Net::HTTP::Post.new(url.path) req.set_form_data(query_params) h = Net::HTTP.new(url.host, url.port) h.use_ssl = true h.verify_mode = OpenSSL::SSL::VERIFY_NONE # set some timeouts h.open_timeout = 60 # this blocks forever by default, lets be a bit less crazy. h.read_timeout = self.class.timeout || DefaultTimeout h.ssl_timeout = self.class.timeout || DefaultTimeout h.start { |http| http.request(req) } rescue Exception => e retry if servers.size > 0 raise e end