Module: Kontagent

Defined in:
lib/kontagent.rb

Constant Summary collapse

PARAMS_MAP =
{
  :uid                => :s,
  :birth_year         => :b,
  :sex                => [:g, :escape],
  :city               => [:ly, :escape],
  :country            => [:lc, :escape],
  :zip                => [:lp, :escape],
  :state              => [:ls, :escape],
  :friend_count       => :f,
  :short_tag          => :su,
  :tag                => :u,
  :channel            => :tu,
  :link_type          => :tu,
  :st1                => [:st1, :escape],
  :st2                => [:st2, :escape],
  :st3                => [:st3, :escape],
  :responder_uid      => :r,
  :recipient_uids     => [:r, :escape],
  :existing_install?  => :i,
  :timestamp          => :ts,
}

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_keyObject

Returns the value of attribute api_key.



30
31
32
# File 'lib/kontagent.rb', line 30

def api_key
  @api_key
end

.api_urlObject

Returns the value of attribute api_url.



30
31
32
# File 'lib/kontagent.rb', line 30

def api_url
  @api_url
end

Class Method Details

.application_added(options = {}) ⇒ Object



60
61
62
63
# File 'lib/kontagent.rb', line 60

def self.application_added(options = {})
  assert_options(options, :uid)
  call_method("apa", options)
end

.application_removed(options = {}) ⇒ Object



65
66
67
68
# File 'lib/kontagent.rb', line 65

def self.application_removed(options = {})
  assert_options(options, :uid)
  call_method("apr", options)
end

.base_urlObject



46
47
48
# File 'lib/kontagent.rb', line 46

def self.base_url
  File.join(api_url, api_key)
end

.build_url(method, options = {}) ⇒ Object



107
108
109
# File 'lib/kontagent.rb', line 107

def self.build_url(method, options = {})
  File.join(self.base_url, method, "?#{kontagent_params(options)}")
end

.configuration=(options) ⇒ Object



41
42
43
44
# File 'lib/kontagent.rb', line 41

def self.configuration=(options)
  self.api_url = options[:api_url]
  self.api_key = options[:api_key]
end

.create_short_tagObject



56
57
58
# File 'lib/kontagent.rb', line 56

def self.create_short_tag
  create_tracking_tag
end

.create_tracking_tag {|tag| ... } ⇒ Object

Yields:

  • (tag)


50
51
52
53
54
# File 'lib/kontagent.rb', line 50

def self.create_tracking_tag
  tag = UUIDTools::UUID.random_create.to_s.gsub("-", "")
  yield tag if block_given?
  tag
end

.get_page_request_url(options = {}) ⇒ Object



70
71
72
73
74
# File 'lib/kontagent.rb', line 70

def self.get_page_request_url(options = {})
  assert_options(options, :uid)
  options[:timestamp] ||= Time.now.strftime("%Y-%m-%dT%H:%M:%S")
  build_url("pgr", options)
end

.track_invite(options = {}) ⇒ Object



95
96
97
98
99
# File 'lib/kontagent.rb', line 95

def self.track_invite(options = {})
  assert_options(options, :uid, :tag, :recipient_uids)
  options[:recipient_uids] = options[:recipient_uids].join(",")
  call_method("ins", options)
end

.track_invite_response(options = {}) ⇒ Object



101
102
103
104
105
# File 'lib/kontagent.rb', line 101

def self.track_invite_response(options = {})
  assert_options(options, :responder_uid, :tag, :existing_install?)
  options[:existing_install?] = options[:existing_install?] && 1 || 0  
  call_method("inr", options)
end


111
112
113
114
115
# File 'lib/kontagent.rb', line 111

def self.track_link(options)
  assert_options(options, :link_type, :existing_install?, :short_tag)
  options[:existing_install?] = options[:existing_install?] ? 1 : 0
  call_method("ucc", options)
end

.track_post(options = {}) ⇒ Object



82
83
84
85
86
# File 'lib/kontagent.rb', line 82

def self.track_post(options = {})
  assert_options(options, :uid, :tag, :channel)
  assert_channel(options[:channel])
  call_method("pst", options)
end

.track_post_response(options = {}) ⇒ Object



88
89
90
91
92
93
# File 'lib/kontagent.rb', line 88

def self.track_post_response(options = {})
  assert_options(options, :responder_uid, :tag, :channel, :existing_install?)
  assert_channel(options[:channel])
  options[:existing_install?] = options[:existing_install?] && 1 || 0  
  call_method("psr", options)
end

.track_user(options = {}) ⇒ Object



76
77
78
79
80
# File 'lib/kontagent.rb', line 76

def self.track_user(options = {})
  assert_options(options, :uid)
  options[:sex] = options[:sex].to_s[0,1]
  call_method("cpu", options)
end