Browse files

remove serverparameters class

  • Loading branch information...
1 parent dd49674 commit 39a0f4158cf83be60c6e416996dddd175c7fd8da Aaron Peckham committed Apr 13, 2012
Showing with 0 additions and 61 deletions.
  1. +0 −27 spec/TicketSpec.js
  2. +0 −34 widgets.js
View
27 spec/TicketSpec.js
@@ -18,31 +18,4 @@ describe("Ticket", function() {
var ticket = new Urban.Ticket({description: "The word is http://www.urbandictionary.com/author.php?author=Nerd%20bird+jetblue+plane)"});
expect(ticket.getMatches()).toEqual([{string: 'Nerd bird jetblue plane', type: 'author'}]);
});
-
- it("should extract server parameters", function() {
- var ticket = new Urban.Ticket({"description":"Hello,Thanks,\nN\n\n------------------\n Submitted from: {\"HTTP_USER_AGENT\":\"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.126 Safari/533.4\",\"REMOTE_ADDR\":\"208.122.31.10\",\"HTTP_REFERER\":null,\"HTTP_COOKIE\":\"__qca=P0-447681624-1282156495013; __gads=ID=cef860e362d010e2:T=1282156496:S=ALNI_MZnlOLsEPsLIMpNPUFSyXIqYN0WTg; __utmz=246446400.1282156669.1.1.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=emil%20mesaros; __utma=246446400.35929657.1282156669.1282156669.1282156669.1; __utmc=246446400; __utmb=246446400.1.10.1282156669; _urban_session=BAh7BzoPc2Vzc2lvbl9pZCIlZDAwMGI0OGQ4NDUxMzc2NGQ5OTk4YjYxZDc0MjYyYzY6EXZpZXdlZF9kZWZpZCIMMzE1MDg1Ng%3D%3D--e36a5b9417acd5ab9fef2a7cf434acdc3200e422\",\"HTTP_X_FORWARDED_FOR\":\"86.34.204.8, 208.122.31.29\"}"});
- expect(ticket.getServerParameters().get('HTTP_USER_AGENT')).toEqual("Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.126 Safari/533.4");
- });
-
- it("should extract server parameters when missing", function() {
- var ticket = new Urban.Ticket({"description":"Hello,Thanks,"});
- expect(ticket.getServerParameters()).toBeNull();
- });
-
- it("should handle invalid JSON", function() {
- var ticket = new Urban.Ticket({"description":"Hello,Thanks,\nN\n\n------------------\n Submitted from: {\"HTTP_USER_AGENT}"});
- expect(ticket.getServerParameters()).toBeNull();
- });
-
- describe("Server parameters", function() {
- it("should return the IP", function() {
- var serverParameters = new Urban.Ticket.ServerParameters({"REMOTE_ADDR": "208.122.31.10", "HTTP_X_FORWARDED_FOR": "86.34.204.8, 208.122.31.29"});
- expect(serverParameters.getIp()).toEqual("86.34.204.8");
- });
-
- it("should return null if there is no IP", function() {
- var serverParameters = new Urban.Ticket.ServerParameters({});
- expect(serverParameters.getIp()).toBeNull();
- });
- });
});
View
34 widgets.js
@@ -71,40 +71,6 @@ Urban.Ticket = Class.create({
addMatches(/author=([\w%\+]+)/g, "author", clean);
return matches;
- },
-
- getServerParameters: function() {
- var matches = this.json.description.match(/------------------\s+Submitted from: (\{.+\})/);
- if (!matches) {
- return null;
- }
-
- var parsed;
- try {
- parsed = JSON.parse(matches[1]);
- } catch (e) {
- return null;
- }
-
- return new Urban.Ticket.ServerParameters(parsed);
- }
-});
-
-Urban.Ticket.ServerParameters = Class.create({
- initialize: function(json) {
- this.json = json;
- },
-
- get: function(key) {
- return this.json[key];
- },
-
- getIp: function() {
- field = this.json["HTTP_X_FORWARDED_FOR"];
- if (!field) {
- return null;
- }
- return field.split(", ")[0];
}
});

0 comments on commit 39a0f41

Please sign in to comment.