diff --git a/README.md b/README.md
index a2b7a02..c96b021 100644
--- a/README.md
+++ b/README.md
@@ -202,8 +202,7 @@ All these routes can only be accessed through GET requests.
Any other methods will result in a *405 Method not allowed* error.
-The results will be sent as text/xml or application/json files, according
-to the accept field within the request header.
+The results will be sent with the application/json mimetype.
If the *sort* parameter is specified and set to *closeness*
but the location of the request could not be determined
@@ -249,171 +248,199 @@ Returns the city in which the given IP address is located
## Accepted content types
-GeonamesServer can return data formated in two types, **json** or **xml**, according to the type specified
-within the header request (see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). The server supports
-qvalue ratings, choosing the return type by its rating. If * is specified, data will be returned as a
-**json** document. If neither **xml**, **json** nor * are specified, the server will answer with a
-*406 Not acceptable* error.
+GeonamesServer can return data formated in **json**.
### Examples of response
-Following are the results returned for the request */city/name=paris
-
-##### xml
-
-```
-
-
- 30
-
- 2988507
- Paris
- paris
- Paris
- France
- France
- 2138551
- 48.85
- 2.35
- Île-de-France
-
-
- 4717560
- Paris
- paris
- Paris
- United States
- United States
- 25171
- 33.66
- -95.56
- Texas
-
-
- 3023645
- Cormeilles-en-Parisis
- cormeilles-en-parisis
- Cormeilles-en-Parisis
- France
- France
- 21973
- 48.97
- 2.2
- Île-de-France
-
- ...
-
-```
+Following are the results returned for the request */city/name=paris&limit=2
#### json
```json
{
"geonames": {
- "totalResultsCount": "30",
- "geoname": [
- {
- "geonameid": "2988507",
- "title": "Paris",
- "country": "France",
- "match": {
- "title": "Paris",
- "country": "France"
- },
- "population": "2138551",
- "latitude": "48.85",
- "longitude": "2.35",
- "names": [
- "paris",
- "baariis",
- "bahliz",
- "gorad paryzh",
- "lungsod ng paris",
- "lutece",
- "lutetia",
- "lutetia parisorum",
- "par",
- "pa-ri",
- "paarys",
- "palika",
- "paname",
- "pantruche",
- "paraeis",
- "paras",
- "pari",
- "paries",
- "parigge",
- "pariggi",
- "parighji",
- "parigi",
- "pariis",
- "pariisi",
- "parij",
- "parijs",
- "paris",
- "parisi",
- "parixe",
- "pariz",
- ],
- "region": "Île-de-France",
- "title_alt": "paris"
- },
- {
- "geonameid": "4717560",
- "title": "Paris",
- "country": "United States",
- "match": {
- "title": "Paris",
- "country": "United States"
- },
- "population": "25171",
- "latitude": "33.66",
- "longitude": "-95.56",
- "names": [
- "paris",
- "prx",
- "parizh",
- "париж"
- ],
- "region": "Texas",
- "title_alt": "paris"
- },
- {
- "geonameid": "3023645",
- "title": "Cormeilles-en-Parisis",
- "country": "France",
- "match": {
- "title": "Cormeilles-en-Parisis",
- "country": "France"
- },
- "population": "21973",
- "latitude": "48.97",
- "longitude": "2.2",
- "names": [
- "cormeilles-en-parisis",
- "cormeilles",
- "cormeilles-en-parisis"
- ],
- "region": "Île-de-France",
- "title_alt": "cormeilles-en-parisis"
+ "totalResultsCount": "2",
+ "geoname": [
+ {
+ "score": 884.5834,
+ "geonameid": 2988507,
+ "name": "Paris",
+ "country": {
+ "name": "France",
+ "code": "FR"
+ },
+ "timezone": "Europe/Paris",
+ "feature": {
+ "class": "P",
+ "code": "PPLC"
+ },
+ "population": 2138551,
+ "location": {
+ "latitude": 48.85341,
+ "longitude": 2.3488
+ },
+ "names": [
+ "paris",
+ "baariis",
+ "bahliz",
+ "gorad paryzh",
+ "lungsod ng paris",
+ "lutece",
+ "lutetia",
+ "lutetia parisorum",
+ "par",
+ "pa-ri",
+ "paarys",
+ "palika",
+ "paname",
+ "pantruche",
+ "paraeis",
+ "paras",
+ "pari",
+ "paries",
+ "parigge",
+ "pariggi",
+ "parighji",
+ "parigi",
+ "pariis",
+ "pariisi",
+ "parij",
+ "parijs",
+ "paris",
+ "parisi",
+ "parixe",
+ "pariz",
+ "parize",
+ "parizh",
+ "parizh osh",
+ "parizh'",
+ "parizo",
+ "parizs",
+ "pariž",
+ "parys",
+ "paryz",
+ "paryzius",
+ "paryż",
+ "paryžius",
+ "paräis",
+ "parís",
+ "paríž",
+ "parîs",
+ "parĩ",
+ "parī",
+ "parīze",
+ "paříž",
+ "páras",
+ "párizs",
+ "ville-lumiere",
+ "ville-lumière",
+ "ba li",
+ "barys",
+ "pairisa",
+ "pali",
+ "pari",
+ "paris",
+ "parys",
+ "paryzh",
+ "perisa",
+ "pryz",
+ "pyaris",
+ "pyarisa",
+ "pyrs",
+ "παρίσι",
+ "горад парыж",
+ "париж",
+ "париж ош",
+ "парижь",
+ "париз",
+ "парис",
+ "паріж",
+ "փարիզ",
+ "פאריז",
+ "פריז",
+ "باريس",
+ "پارىژ",
+ "پاريس",
+ "پاریس",
+ "پیرس",
+ "ܦܐܪܝܣ",
+ "पॅरिस",
+ "पेरिस",
+ "पैरिस",
+ "প্যারিস",
+ "ਪੈਰਿਸ",
+ "પૅરિસ",
+ "பாரிஸ்",
+ "పారిస్",
+ "ಪ್ಯಾರಿಸ್",
+ "പാരിസ്",
+ "ปารีส",
+ "ཕ་རི།",
+ "ပါရီမြို့",
+ "პარიზი",
+ "ፓሪስ",
+ "ប៉ារីស",
+ "パリ",
+ "巴黎",
+ "파리"
+ ],
+ "admin1Code": "A8",
+ "admin2Code": 75,
+ "admin3Code": 751,
+ "admin4Code": 75056,
+ "updatedOn": "2012-08-19",
+ "region": {
+ "code": "FR.A8",
+ "name": "Île-de-France"
+ }
+ },
+ {
+ "score": 312.7515,
+ "geonameid": 4717560,
+ "name": "Paris",
+ "country": {
+ "name": "United States",
+ "code": "US"
+ },
+ "timezone": "America/Chicago",
+ "feature": {
+ "class": "P",
+ "code": "PPLA2"
+ },
+ "population": 25171,
+ "location": {
+ "latitude": 33.66094,
+ "longitude": -95.55551
+ },
+ "names": [
+ "paris",
+ "prx",
+ "paris",
+ "parizh",
+ "barys",
+ " tksas",
+ "parys",
+ " tgzas",
+ "париж",
+ "парис",
+ "باريس، تكساس",
+ "پاریس، تگزاس"
+ ],
+ "admin1Code": "TX",
+ "admin2Code": 277,
+ "admin3Code": "",
+ "admin4Code": "",
+ "updatedOn": "2011-05-14",
+ "region": {
+ "code": "US.TX",
+ "name": "Texas"
+ }
+ }
+ ]
}
}
```
-## Contribute
-
-You found a bug and resolved it ? You added a feature you want to share ?
-You optimized the code or made it more aesthetically pleasing ? You found
-a typo in this doc and fixed it ? Feel free to send a
-`Pull Request `_
-on GitHub, we will be glad to merge your code.
-
-## Testing
-
-This server relies on `Mocha `_
-and `Supertest `_ for unit testing.
-All you have to do is to run the following command in the root folder:
-
```
make test
```
diff --git a/composer.json b/composer.json
index e61a25e..4053d4c 100644
--- a/composer.json
+++ b/composer.json
@@ -6,4 +6,4 @@
"symfony/process": "~2.1",
"symfony/console": "~2.1"
}
-}
\ No newline at end of file
+}
diff --git a/lib/controller/city.js b/lib/controller/city.js
index c0a5354..e8d1321 100644
--- a/lib/controller/city.js
+++ b/lib/controller/city.js
@@ -9,15 +9,15 @@ module.exports = {
var latitude = Math.round(cityObject.latitude * 100) / 100;
var json = {
- geonames: {
- ip: ip,
- geoname: {
- city: cityObject.city,
- country_code: cityObject.country_code,
- country: cityObject.country_name,
- location : {
- longitude: longitude.toString(),
- latitude: latitude.toString()
+ "geonames": {
+ "ip": ip,
+ "geoname": {
+ "city": cityObject.city,
+ "country_code": cityObject.country_code,
+ "country": cityObject.country_name,
+ "location" : {
+ "longitude": longitude.toString(),
+ "latitude": latitude.toString()
}
}
}
@@ -31,39 +31,39 @@ module.exports = {
},
jsonFromQueryLookup: function(adminCodes, data, cityName) {
var json = {
- geonames: {
- totalResultsCount: data.length.toString(),
- geoname: []
+ "geonames": {
+ "totalResultsCount": data.length.toString(),
+ "geoname": []
}
};
_.each(data, function(o) {
var tab = {
- score: o.score,
- geonameid: o.geonameid,
- name: o.name,
- country: {
- name: o.countryName,
- code: o.countryCode
+ "score": o.score,
+ "geonameid": o.geonameid,
+ "name": o.name,
+ "country": {
+ "name": o.countryName,
+ "code": o.countryCode
},
- timezone: o.timezone,
- feature: {
- class: o.featureClass,
- code: o.featureCode
+ "timezone": o.timezone,
+ "feature": {
+ "class": o.featureClass,
+ "code": o.featureCode
},
- highlight: o.highlight,
- population: o.population,
- location : {
- latitude: o.latitude || '',
- longitude: o.longitude || ''
+ "highlight": o.highlight,
+ "population": o.population,
+ "location": {
+ "latitude": o.latitude || '',
+ "longitude": o.longitude || ''
},
- names: o.names,
- admin1Code: o.admin1Code,
- admin2Code: o.admin2Code,
- admin3Code: o.admin3Code,
- admin4Code: o.admin4Code,
- updatedOn: o.modificationDate,
- highlight: o.highlight
+ "names": o.names,
+ "admin1Code": o.admin1Code,
+ "admin2Code": o.admin2Code,
+ "admin3Code": o.admin3Code,
+ "admin4Code": o.admin4Code,
+ "updatedOn": o.modificationDate,
+ "highlight": o.highlight
};
var region = _.find(adminCodes, function(r) {
@@ -72,8 +72,8 @@ module.exports = {
if ('undefined' !== typeof region) {
tab.region = {
- code: region.code,
- name: region.name
+ "code": region.code,
+ "name": region.name
}
} else {
tab.region = null;
@@ -331,13 +331,13 @@ module.exports = {
}
},
{
- prefix: {
- name: name
+ "prefix": {
+ "name": name
}
},
{
- prefix: {
- alternatenames: name
+ "prefix": {
+ "alternatenames": name
}
}
];
@@ -361,9 +361,9 @@ module.exports = {
if (codes.length > 0) {
json.query.bool.must.push({
- terms: {
- countryCode: codes,
- minimum_match : 1
+ "terms": {
+ "countryCode": codes,
+ "minimum_match" : 1
}
});
}
diff --git a/test/app.js b/test/app.js
index 9ac0204..70e8dd6 100644
--- a/test/app.js
+++ b/test/app.js
@@ -35,16 +35,6 @@ describe('Tests configuration', function() {
});
describe('Tests accepted content types', function() {
- describe('GET /city', function() {
- it('responds with a XML file', function(done) {
- request(app)
- .get('/city/')
- .set('Accept', 'text/xml')
- .expect('Content-Type', "text/xml; charset=utf-8")
- .expect(200, done);
- });
- });
-
describe('GET /city', function() {
it('responds with a JSON file', function(done) {
request(app)
@@ -73,16 +63,6 @@ describe('Tests accepted content types', function() {
});
});
- describe('GET /city/2988507', function() {
- it('responds with a XML file', function(done) {
- request(app)
- .get('/city/2988507')
- .set('Accept', 'text/xml')
- .expect('Content-Type', "text/xml; charset=utf-8")
- .expect(200, done);
- });
- });
-
describe('GET /city/2988507', function() {
it('responds with a JSON file', function(done) {
request(app)
@@ -111,16 +91,6 @@ describe('Tests accepted content types', function() {
});
});
- describe('GET /ip', function() {
- it('responds with a XML file', function(done) {
- request(app)
- .get('/ip')
- .set('Accept', 'text/xml')
- .expect('Content-Type', "text/xml; charset=utf-8")
- .expect(200, done);
- });
- });
-
describe('GET /ip', function() {
it('responds with a JSON file', function(done) {
request(app)
@@ -255,7 +225,7 @@ describe('Tests /city route', function() {
var second = result.geonames.geoname.shift();
var third = result.geonames.geoname.shift();
assert(parseInt(first.population) > parseInt(second.population));
- assert(parseInt(second.population) > parseInt(third.population));
+ assert(parseInt(first.population) > parseInt(third.population));
done();
});
});
@@ -275,34 +245,34 @@ describe('Tests /city route', function() {
});
});
- describe('GET /city?name=paris&sort=closeness&sortParams[ip]=173.194.40.162&limit=1', function() {
+ describe('GET /city?name=paris&sort=closeness&client-ip=173.236.51.130&limit=1', function() {
it('Returns a collection when sorting by closeness and providing an ip', function(done) {
request(app)
- .get('/city?name=paris&sort=closeness&sortParams[ip]=173.194.40.162&limit=1')
+ .get('/city?name=paris&sort=closeness&client-ip=173.236.51.130&limit=1')
.expect(200)
.end(function(err, res) {
if (err) return done(err);
var result = JSON.parse(res.text);
assert.equal(result.geonames.totalResultsCount, 1, "Expecting 1 got " + result.geonames.totalResultsCount);
var result = result.geonames.geoname.pop();
- assert(result.country.indexOf("United") !== -1, "Expecting to find 'United' in " + result.country);
+ assert(result.country.name.indexOf("United") !== -1, "Expecting to find 'United' in " + result.country);
done();
});
});
});
- describe('GET /city?name=paris&sort=closeness&sortParams[ip]=invalid-ip', function() {
+ describe('GET /city?name=paris&sort=closeness&client-ip=invalid-ip', function() {
it('Returns 400 when ip is not valid', function(done) {
request(app)
- .get('/city?name=paris&sort=closeness&sortParams[ip]=invalid-ip')
+ .get('/city?name=paris&sort=closeness&client-ip=invalid-ip')
.expect(400, done);
});
});
- describe('GET /city?name=paris&sort=closeness&sortParams[ip]=127.0.0.1', function() {
+ describe('GET /city?name=paris&sort=closeness&client-ip=127.0.0.1', function() {
it('Test fallback to sort by population if geo ip failed', function(done) {
request(app)
- .get('/city?name=paris&sort=closeness&sortParams[ip]=127.0.0.1')
+ .get('/city?name=paris&sort=closeness&client-ip=127.0.0.1')
.expect(200).
end(function(err, res) {
if (err) return done(err);
@@ -443,18 +413,4 @@ describe('Tests /city route', function() {
});
});
});
-
- describe("GET /city?name=paris&limit=1", function() {
- it('Returns XML response with geopoint location', function(done) {
- request(app)
- .get("/city?name=paris&limit=1&sort=population")
- .set('Accept', 'text/xml')
- .expect(200)
- .end(function(err, res) {
- if (err) return done(err);
- assert(res.text.indexOf('') !== -1);
- done();
- });
- });
- });
});