@@ -13,25 +13,25 @@ See the Apache License Version 2.0 for the specific language governing permissio
1313
1414#include " emitter.hpp"
1515
16- const int post_wrapper_bytes = 88 ; // "schema":"iglu:com.snowplowanalytics.snowplow/payload_data/jsonschema/1-0-3 ","data":[]
16+ const int post_wrapper_bytes = 88 ; // "schema":"iglu:com.snowplowanalytics.snowplow/payload_data/jsonschema/1-0-4 ","data":[]
1717const int post_stm_bytes = 22 ; // "stm":"1443452851000"
1818
19- Emitter::Emitter (const string & uri, Strategy strategy, Method method, Protocol protocol, int send_limit, const string & db_name) : m_db(db_name) {
19+ Emitter::Emitter (const string & uri, Strategy strategy, Method method, Protocol protocol, int send_limit,
20+ int byte_limit_post, int byte_limit_get, const string & db_name) : m_db(db_name), m_url(this ->get_collector_url (uri, protocol, method)) {
2021
2122 if (uri == " " ) {
2223 throw invalid_argument (" FATAL: Emitter URI cannot be empty." );
2324 }
2425
25- this ->m_uri = uri;
26+ if (!url.get_is_valid ()) {
27+ throw invalid_argument (" FATAL: Emitter URL is not valid - " + url.to_string ());
28+ }
29+
2630 this ->m_strategy = strategy;
2731 this ->m_method = method;
28- this ->m_protocol = protocol;
2932 this ->m_send_limit = send_limit;
30-
31- this ->m_byte_limit_post = 52000 ;
32- this ->m_byte_limit_get = 52000 ;
33-
34- this ->m_url = this ->get_collector_url ();
33+ this ->m_byte_limit_post = byte_limit_post;
34+ this ->m_byte_limit_get = byte_limit_get;
3535}
3636
3737Emitter::~Emitter () {
@@ -129,11 +129,11 @@ void Emitter::do_send(list<Storage::EventRow>* event_rows, list<HttpRequestResul
129129 if (this ->m_method == GET ) {
130130 for (list<Storage::EventRow>::iterator it = event_rows->begin (); it != event_rows->end (); ++it) {
131131 Payload event_payload = it->event ;
132- event_payload.add (" stm " , std::to_string (Utils::get_unix_epoch_ms ()));
133- string final_url = this -> m_url + " ? " + Utils::map_to_query_string (event_payload.get ());
132+ event_payload.add (SENT_TIMESTAMP , std::to_string (Utils::get_unix_epoch_ms ()));
133+ string query_string = Utils::map_to_query_string (event_payload.get ());
134134 list<int > row_id = {it->id };
135135
136- request_futures.push_back (std::async (HttpClient::http_get, final_url, row_id, (final_url .size () > this ->m_byte_limit_get )));
136+ request_futures.push_back (std::async (HttpClient::http_get, this -> m_url , query_string, row_id, (query_string .size () > this ->m_byte_limit_get )));
137137 }
138138 } else {
139139 list<int > row_ids;
@@ -188,19 +188,19 @@ string Emitter::build_post_data_json(list<Payload> payload_list) {
188188 // Add 'stm' to each payload
189189 string stm = std::to_string (Utils::get_unix_epoch_ms ());
190190 for (list<Payload>::iterator it = payload_list.begin (); it != payload_list.end (); ++it) {
191- it->add (" stm " , stm);
191+ it->add (SENT_TIMESTAMP , stm);
192192 data_array.push_back (it->get ());
193193 }
194194
195195 // Build Post event
196- SelfDescribingJson post_envelope (" iglu:com.snowplowanalytics.snowplow/payload_data/jsonschema/1-0-4 " , data_array);
196+ SelfDescribingJson post_envelope (SCHEMA_PAYLOAD_DATA , data_array);
197197 return post_envelope.to_string ();
198198}
199199
200- string Emitter::get_collector_url () {
200+ string Emitter::get_collector_url (const string & uri, Protocol protocol, Method method ) {
201201 stringstream url;
202- url << (this -> m_protocol == HTTP ? " http" : " https" ) << " ://" << this -> m_uri ;
203- url << ( this -> m_method == GET ? " /i " : " /com.snowplowanalytics.snowplow/tp2 " );
202+ url << (protocol == HTTP ? " http" : " https" ) << " ://" << uri ;
203+ url << " / " << (method == GET ? GET_PROTOCOL_PATH : POST_PROTOCOL_VENDOR + " / " + POST_PROTOCOL_VERSION );
204204 return url.str ();
205205}
206206
0 commit comments