Class: Icontact

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

Constant Summary collapse

@@settings =
{ :url => nil,
:listid => nil,
:clientid => nil,
:formid => nil,
:specialid => nil,
:reallistid => nil,
:doubleopt => nil}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#form_varsObject

Returns the value of attribute form_vars.



21
22
23
# File 'lib/icontact.rb', line 21

def form_vars
  @form_vars
end

Instance Method Details

#create_post_string(options = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/icontact.rb', line 44

def create_post_string(options = {})
  data = {}
  data.merge!(settings)
  data.merge!(options)
  data.stringify_keys!
  
  # modify the specialid value that icontact expects to receive, converts "specialid" => "specialid:XXXX" where XXXX is the list id
  specialid = settings[:specialid]
  data.delete("specialid")
  @form_vars = data.merge!({"specialid:#{settings[:listid]}" => specialid})

  param_array = []
  @form_vars.each { |k,v| param_array << "#{k}=#{v}"}
  param_array.sort! # alphabetize for easier testing
  pstring = "?" << param_array.join("&")
end

#settingsObject



23
24
25
# File 'lib/icontact.rb', line 23

def settings
  @settings || @@settings
end

#settings=(settings) ⇒ Object



27
28
29
# File 'lib/icontact.rb', line 27

def settings=(settings)
  @settings = settings
end

#submit(options) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/icontact.rb', line 35

def submit(options)
  create_post_string(options)
  uri = URI.parse(settings[:url])
  req = Net::HTTP::Post.new(url)
  req.set_form_data(@form_vars)
  response = Net::HTTP.new(uri.host, uri.port).start { |http| http.request(req) }
  determine_success(response)
end

#urlObject



31
32
33
# File 'lib/icontact.rb', line 31

def url
  settings[:url]
end