Class: Maxmind::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/maxmind/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(license_key, options = {}) ⇒ Request

Returns a new instance of Request.



12
13
14
15
16
17
18
# File 'lib/maxmind/request.rb', line 12

def initialize(license_key, options = {}) 
  @license_key = license_key
  
  options.each do |k, v|
    self.instance_variable_set("@#{k}", v)
  end
end

Instance Attribute Details

#accept_languageObject

Optional Fields



7
8
9
# File 'lib/maxmind/request.rb', line 7

def accept_language
  @accept_language
end

#binObject

Optional Fields



7
8
9
# File 'lib/maxmind/request.rb', line 7

def bin
  @bin
end

#bin_nameObject

Optional Fields



7
8
9
# File 'lib/maxmind/request.rb', line 7

def bin_name
  @bin_name
end

#bin_phoneObject

Optional Fields



7
8
9
# File 'lib/maxmind/request.rb', line 7

def bin_phone
  @bin_phone
end

#cityObject

Required Fields



4
5
6
# File 'lib/maxmind/request.rb', line 4

def city
  @city
end

#client_ipObject

Required Fields



4
5
6
# File 'lib/maxmind/request.rb', line 4

def client_ip
  @client_ip
end

#countryObject

Required Fields



4
5
6
# File 'lib/maxmind/request.rb', line 4

def country
  @country
end

#cust_phoneObject

Optional Fields



7
8
9
# File 'lib/maxmind/request.rb', line 7

def cust_phone
  @cust_phone
end

#domainObject

Optional Fields



7
8
9
# File 'lib/maxmind/request.rb', line 7

def domain
  @domain
end

#emailObject

Optional Fields



7
8
9
# File 'lib/maxmind/request.rb', line 7

def email
  @email
end

#forwarded_ipObject

Optional Fields



7
8
9
# File 'lib/maxmind/request.rb', line 7

def forwarded_ip
  @forwarded_ip
end

#license_keyObject

Required Fields



4
5
6
# File 'lib/maxmind/request.rb', line 4

def license_key
  @license_key
end

#passwordObject

Optional Fields



7
8
9
# File 'lib/maxmind/request.rb', line 7

def password
  @password
end

#postalObject

Required Fields



4
5
6
# File 'lib/maxmind/request.rb', line 4

def postal
  @postal
end

#regionObject

Required Fields



4
5
6
# File 'lib/maxmind/request.rb', line 4

def region
  @region
end

#requested_typeObject

Optional Fields



7
8
9
# File 'lib/maxmind/request.rb', line 7

def requested_type
  @requested_type
end

#session_idObject

Optional Fields



7
8
9
# File 'lib/maxmind/request.rb', line 7

def session_id
  @session_id
end

#shipping_addressObject

Optional Fields



7
8
9
# File 'lib/maxmind/request.rb', line 7

def shipping_address
  @shipping_address
end

#shipping_cityObject

Optional Fields



7
8
9
# File 'lib/maxmind/request.rb', line 7

def shipping_city
  @shipping_city
end

#shipping_countryObject

Optional Fields



7
8
9
# File 'lib/maxmind/request.rb', line 7

def shipping_country
  @shipping_country
end

#shipping_postalObject

Optional Fields



7
8
9
# File 'lib/maxmind/request.rb', line 7

def shipping_postal
  @shipping_postal
end

#shipping_regionObject

Optional Fields



7
8
9
# File 'lib/maxmind/request.rb', line 7

def shipping_region
  @shipping_region
end

#transaction_idObject

Optional Fields



7
8
9
# File 'lib/maxmind/request.rb', line 7

def transaction_id
  @transaction_id
end

#user_agentObject

Optional Fields



7
8
9
# File 'lib/maxmind/request.rb', line 7

def user_agent
  @user_agent
end

#usernameObject

Optional Fields



7
8
9
# File 'lib/maxmind/request.rb', line 7

def username
  @username
end

Instance Method Details

#get(query) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/maxmind/request.rb', line 62

def get(query)
  url = URI.parse("https://minfraud1.maxmind.com/app/ccv2r")
  req = Net::HTTP::Get.new("#{url.path}?#{query}")
  h = Net::HTTP.new(url.host, url.port)
  h.use_ssl = true
  response = h.start { |http| http.request(req) }
  return response.body
end

#query(string = false) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/maxmind/request.rb', line 20

def query(string = false)
  validate
  
  required_fields = {
    :i                => @client_ip,
    :city             => @city,
    :region           => @region,
    :postal           => @postal,
    :country          => @country,
    :license_key      => @license_key
  }
  
  optional_fields = {
    :domain           => @domain,
    :bin              => @bin,
    :binName          => @bin_name,
    :binPhone         => @bin_phone,
    :custPhone        => @cust_phone,
    :requested_type   => @requested_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_langage
  }
  
  query = required_fields.merge(optional_fields)
  if string == false
    return get(query.reject {|k, v| v.nil? }.to_query)    
  else
    return query.reject {|k, v| v.nil? }.to_query
  end
end