Class: Rack::Deduce::Ingest
- Inherits:
-
Object
- Object
- Rack::Deduce::Ingest
- Defined in:
- lib/rack/deduce/ingest.rb,
lib/rack/deduce/ingest/helpers.rb,
lib/rack/deduce/ingest/version.rb
Defined Under Namespace
Modules: Helpers Classes: Railtie
Constant Summary collapse
- URL =
"//lore.deduce.com/p/collect"
- EVENT_URL =
only https
"https://event.deduce.com/p/event"
- TIMEOUT =
1.1
- VERHASH =
Digest::SHA1.hexdigest("ruby/#{VERSION}")[0..16]
- VERSION =
"0.0.1"
Class Attribute Summary collapse
-
.apikey ⇒ Object
Returns the value of attribute apikey.
-
.site_id ⇒ Object
Returns the value of attribute site_id.
-
.ssl ⇒ Object
Returns the value of attribute ssl.
-
.testmode ⇒ Object
Returns the value of attribute testmode.
Class Method Summary collapse
-
.event(email, ip, event, additional = {}, options = {}) ⇒ String
On error, returns an error message; or nothing on success.
-
.events(evts, options = {}) ⇒ String
On error, returns an error message; or nothing on success.
- .html(email, options = {}) ⇒ Object
- .init(app, site_id, apikey, options = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(app, site_id, apikey, options = {}) ⇒ Ingest
constructor
A new instance of Ingest.
Constructor Details
#initialize(app, site_id, apikey, options = {}) ⇒ Ingest
Returns a new instance of Ingest.
206 207 208 209 |
# File 'lib/rack/deduce/ingest.rb', line 206 def initialize(app, site_id, apikey, = {}) self.class.init(app, site_id, apikey, ) self.class end |
Class Attribute Details
.apikey ⇒ Object
Returns the value of attribute apikey.
25 26 27 |
# File 'lib/rack/deduce/ingest.rb', line 25 def apikey @apikey end |
.site_id ⇒ Object
Returns the value of attribute site_id.
25 26 27 |
# File 'lib/rack/deduce/ingest.rb', line 25 def site_id @site_id end |
.ssl ⇒ Object
Returns the value of attribute ssl.
25 26 27 |
# File 'lib/rack/deduce/ingest.rb', line 25 def ssl @ssl end |
.testmode ⇒ Object
Returns the value of attribute testmode.
25 26 27 |
# File 'lib/rack/deduce/ingest.rb', line 25 def testmode @testmode end |
Class Method Details
.event(email, ip, event, additional = {}, options = {}) ⇒ String
Returns on error, returns an error message; or nothing on success.
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/rack/deduce/ingest.rb', line 132 def event(email, ip, event, additional = {}, = {}) return if limited? return "invalid email" unless email_valid? email event_data = additional.dup event_data[:email] = email # fixup will hash the email event_data[:ip] = ip event_data[:event] = event events [event_data], end |
.events(evts, options = {}) ⇒ String
Returns on error, returns an error message; or nothing on success.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/rack/deduce/ingest.rb', line 87 def events(evts, = {}) return if limited? site_id = @site_id apikey = @apikey timeout = [:timeout] || (TIMEOUT + evts.length / 10) post_data = { site: site_id, apikey: apikey, vers: VERHASH } post_data[:backfill] = true if [:backfill] post_data[:testmode] = true if [:testmode] || @testmode post_data[:events] = evts.map{ |e| fixup_event( e.dup ) } uri = URI([:url] || EVENT_URL) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = (uri.scheme == 'https') http.open_timeout = timeout http.read_timeout = timeout http.ssl_timeout = timeout hreq = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json') hreq.body = post_data.to_json p post_data.to_json begin res = http.request(hreq) if res.code != '200' raise "#{res.code} - #{res.body}" end rescue => e adjust_fail return e end adjust_ok # return nil on success, else return the error return nil end |
.html(email, options = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/rack/deduce/ingest.rb', line 41 def html(email, = {}) site_id = [:site_id] || @site_id use_ssl = @ssl use_ssl = [:ssl] if .include? :ssl user_data = {site: site_id, vers: VERHASH} user_data[:testmode] = true if [:testmode] || @testmode if email_valid?(email) email = email.strip email_lc = email.downcase email_uc = email.upcase user_data[:ehls1] = Digest::SHA1.hexdigest(email_lc) user_data[:ehus1] = Digest::SHA1.hexdigest(email_uc) user_data[:ehlm5] = Digest::MD5.hexdigest(email_lc) user_data[:ehum5] = Digest::MD5.hexdigest(email_uc) user_data[:ehls2] = Digest::SHA256.hexdigest(email_lc) user_data[:ehus2] = Digest::SHA256.hexdigest(email_uc) end url = [:url] if !url if use_ssl.nil? url = URL elsif use_ssl url = 'https:' + URL else url = 'http:' + URL end end html = <<EOS <script type="text/javascript"> var dd_info = #{JSON.pretty_generate(user_data)}; </script> <script type="text/javascript" src="#{url}" async></script> EOS return html end |
.init(app, site_id, apikey, options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/rack/deduce/ingest.rb', line 31 def init(app, site_id, apikey, = {}) @app = app self.site_id = site_id self.apikey = apikey self.ssl = [:ssl] self.testmode = [:testmode] self.ssl = ssl end |