Skip to content

Commit

Permalink
separating modules from RudderClient
Browse files Browse the repository at this point in the history
  • Loading branch information
prabrisha-rudder authored and sayan-rudder committed Sep 30, 2019
1 parent 6a4eba5 commit 2fd5e00
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 204 deletions.
210 changes: 6 additions & 204 deletions rudder-client-javascript/RudderClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,210 +28,12 @@ var RudderPayload = require("./utils.RudderPayload.js");
var RudderElement = require("./utils.RudderElement.js");
var RudderElementBuilder = require("./utils.RudderElementBuilder.js");
var RudderMessage = require("./utils.RudderMessage.js");

//Context class
class RudderContext {
constructor() {
this.rl_app = new RudderApp();
this.rl_traits = null;
this.rl_library = new RudderLibraryInfo();
//this.rl_os = null;
var os = new RudderOSInfo();
os.rl_version = ""; //skipping version for simplicity now
var screen = new RudderScreenInfo();

//Depending on environment within which the code is executing, screen
//dimensions can be set
//User agent and locale can be retrieved only for browser
//For server-side integration, same needs to be set by calling program
if (typeof window === "undefined") {
//server-side integration
screen.rl_width = 0;
screen.rl_height = 0;
screen.rl_density = 0;
os.rl_version = "";
os.rl_name = "";
this.rl_user_agent = null;
this.rl_locale = null;
} else {
//running within browser
screen.rl_width = window.width;
screen.rl_height = window.height;
screen.rl_density = window.devicePixelRatio;
this.rl_user_agent = navigator.userAgent;
//property name differs based on browser version
this.rl_locale = navigator.language || navigator.browserLanguage;
}

this.screen = screen;
this.rl_device = null;
this.rl_network = null;
}
}

//Application class
class RudderApp {
constructor() {
this.rl_build = "1.0.0";
this.rl_name = "RudderLabs JavaScript SDK";
this.rl_namespace = "com.rudderlabs.javascript";
this.rl_version = "1.0.0";
}
}

//Traits class
class RudderTraits {
constructor() {
this.rl_address = null;
this.rl_age = null;
this.rl_birthday = null;
this.rl_company = null;
this.rl_createdat = null;
this.rl_description = null;
this.rl_email = null;
this.rl_firstname = null;
this.rl_gender = null;
this.rl_id = null;
this.rl_lastname = null;
this.rl_name = null;
this.rl_phone = null;
this.rl_title = null;
this.rl_username = null;
}

//Setter methods to aid Builder pattern
setAddress(address) {
this.rl_address = address;
return this;
}

setAge(age) {
this.rl_age = age;
return this;
}

setBirthday(birthday) {
this.rl_birthday = birthday;
return this;
}

setCompany(company) {
this.rl_company = company;
return this;
}

setCreatedAt(createAt) {
this.rl_createdat = createAt;
return this;
}

setDescription(description) {
this.rl_description = description;
return this;
}

setEmail(email) {
this.rl_email = email;
return this;
}

setFirstname(firstname) {
this.rl_firstname = firstname;
return this;
}

setId(id) {
this.rl_id = id;
return this;
}

setLastname(lastname) {
this.rl_lastname = lastname;
return this;
}

setName(name) {
this.rl_name = name;
return this;
}

setPhone(phone) {
this.rl_phone = phone;
return this;
}

setTitle(title) {
this.rl_title = title;
return this;
}

setUsername(username) {
this.rl_username = username;
return this;
}
}

//Class for Address to be embedded in Traits
class TraitsAddress {
constructor() {
this.rl_city = "";
this.rl_country = "";
this.rl_postalcode = "";
this.rl_state = "";
this.rl_street = "";
}
}

//Class for Company to be embedded in Traits
class TraitsCompany {
constructor() {
this.rl_name = "";
this.rl_id = "";
this.rl_industry = "";
}
}

//Library information class
class RudderLibraryInfo {
constructor() {
this.rl_name = "RudderLabs JavaScript SDK";
this.rl_version = "1.0.0";
}
}

//Operating System information class
class RudderOSInfo {
constructor() {
this.rl_name = "";
this.rl_version = "";
}
}

//Screen information class
class RudderScreenInfo {
constructor() {
this.rl_density = 0;
this.rl_width = 0;
this.rl_height = 0;
}
}

//Device information class
class RudderDeviceInfo {
constructor() {
this.rl_id = "";
this.rl_manufacturer = "";
this.rl_model = "";
this.rl_name = "";
}
}

//Carrier information
class RudderNetwork {
constructor() {
this.rl_carrier = "";
}
}
var RudderContext = require("./utils.RudderContext.js");
var RudderApp = require("./utils.RudderApp.js");
var RudderTraits = require("./utils.RudderTraits.js").RudderTraits;
var TraitsAddress = require("./utils.RudderTraits.js").TraitsAddress;
var TraitsCompany = require("./utils.RudderTraits.js").TraitsCompany;
var RudderLibraryInfo = require("./utils.RudderInfo.js").RudderLibraryInfo;

//Singleton implementation of the core SDK client class
var RudderClient = (function() {
Expand Down
12 changes: 12 additions & 0 deletions rudder-client-javascript/utils/RudderApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//Application class
class RudderApp {
constructor() {
this.rl_build = "1.0.0";
this.rl_name = "RudderLabs JavaScript SDK";
this.rl_namespace = "com.rudderlabs.javascript";
this.rl_version = "1.0.0";
}
}
module.exports = {
RudderApp: RudderApp
};
46 changes: 46 additions & 0 deletions rudder-client-javascript/utils/RudderContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//Context class
var RudderApp = require("./utils.RudderApp.js");
var RudderLibraryInfo = require("./utils.RudderInfo.js").RudderLibraryInfo;
var RudderOSInfo = require("./utils.RudderInfo.js").RudderOSInfo;
var RudderScreenInfo = require("./utils.RudderInfo.js").RudderScreenInfo;
class RudderContext {
constructor() {
this.rl_app = new RudderApp();
this.rl_traits = null;
this.rl_library = new RudderLibraryInfo();
//this.rl_os = null;
var os = new RudderOSInfo();
os.rl_version = ""; //skipping version for simplicity now
var screen = new RudderScreenInfo();

//Depending on environment within which the code is executing, screen
//dimensions can be set
//User agent and locale can be retrieved only for browser
//For server-side integration, same needs to be set by calling program
if (typeof window === "undefined") {
//server-side integration
screen.rl_width = 0;
screen.rl_height = 0;
screen.rl_density = 0;
os.rl_version = "";
os.rl_name = "";
this.rl_user_agent = null;
this.rl_locale = null;
} else {
//running within browser
screen.rl_width = window.width;
screen.rl_height = window.height;
screen.rl_density = window.devicePixelRatio;
this.rl_user_agent = navigator.userAgent;
//property name differs based on browser version
this.rl_locale = navigator.language || navigator.browserLanguage;
}

this.screen = screen;
this.rl_device = null;
this.rl_network = null;
}
}
module.exports = {
RudderContext: RudderContext
};
44 changes: 44 additions & 0 deletions rudder-client-javascript/utils/RudderInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//Library information class
class RudderLibraryInfo {
constructor() {
this.rl_name = "RudderLabs JavaScript SDK";
this.rl_version = "1.0.0";
}
}
//Operating System information class
class RudderOSInfo {
constructor() {
this.rl_name = "";
this.rl_version = "";
}
}
//Screen information class
class RudderScreenInfo {
constructor() {
this.rl_density = 0;
this.rl_width = 0;
this.rl_height = 0;
}
}
//Device information class
class RudderDeviceInfo {
constructor() {
this.rl_id = "";
this.rl_manufacturer = "";
this.rl_model = "";
this.rl_name = "";
}
}
//Carrier information
class RudderNetwork {
constructor() {
this.rl_carrier = "";
}
}
module.exports = {
RudderLibraryInfo: RudderLibraryInfo,
RudderOSInfo: RudderOSInfo,
RudderScreenInfo: RudderScreenInfo,
RudderDeviceInfo: RudderDeviceInfo,
RudderNetwork: RudderNetwork
};

0 comments on commit 2fd5e00

Please sign in to comment.