Skip to content
This repository was archived by the owner on Feb 10, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
.settings/
target/
mockapi/node_modules
/.idea/
/sdk.iml
104 changes: 63 additions & 41 deletions mockapi/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,101 +3,123 @@ var fs = require('fs');

var app = express.createServer();

app.configure(function(){
app.configure(function () {
app.use(express.methodOverride());
app.use(express.bodyParser());
});

app.post('/oauth/token', function(req, res) {
if(req.query["grant_type"]=="authorization_code") {
if(req.query["code"]=="bad code") {
res.send({"message":"Error validando el parámetro code","error":"invalid_grant","status":400,"cause":[]}, 400);
} else if(req.query["code"]=="valid code without refresh token") {
app.post('/oauth/token', function (req, res) {
if (req.query["grant_type"] == "authorization_code") {
if (req.query["code"] == "bad code") {
res.send({
"access_token" : "valid token",
"token_type" : "bearer",
"expires_in" : 10800,
"scope" : "write read"
"message": "Error validando el parámetro code",
"error": "invalid_grant",
"status": 400,
"cause": []
}, 400);
} else if (req.query["code"] == "valid code without refresh token") {
res.send({
"access_token": "valid token",
"token_type": "bearer",
"expires_in": 10800,
"scope": "write read"
});
} else if(req.query["code"]=="valid code with refresh token") {
} else if (req.query["code"] == "valid code with refresh token") {
res.send({
"access_token" : "valid token",
"token_type" : "bearer",
"expires_in" : 10800,
"refresh_token" : "valid refresh token",
"scope" : "write read"
"access_token": "valid token",
"token_type": "bearer",
"expires_in": 10800,
"refresh_token": "valid refresh token",
"scope": "write read"
});
} else {
res.send(404);
}
} else if(req.query['grant_type']=='refresh_token') {
if(req.query['refresh_token']=='valid refresh token') {
} else if (req.query['grant_type'] == 'refresh_token') {
if (req.query['refresh_token'] == 'valid refresh token') {
res.send({
"access_token" : "valid token",
"token_type" : "bearer",
"expires_in" : 10800,
"scope" : "write read"
"access_token": "valid token",
"token_type": "bearer",
"expires_in": 10800,
"scope": "write read"
});
}
}
});

app.get('/sites', function(req, res) {
res.send([{"id":"MLA","name":"Argentina"},{"id":"MLB","name":"Brasil"},{"id":"MCO","name":"Colombia"},{"id":"MCR","name":"Costa Rica"},{"id":"MEC","name":"Ecuador"},{"id":"MLC","name":"Chile"},{"id":"MLM","name":"Mexico"},{"id":"MLU","name":"Uruguay"},{"id":"MLV","name":"Venezuela"},{"id":"MPA","name":"Panamá"},{"id":"MPE","name":"Perú"},{"id":"MPT","name":"Portugal"},{"id":"MRD","name":"Dominicana"}]);
app.get('/sites', function (req, res) {
res.send([{"id": "MLA", "name": "Argentina"}, {"id": "MLB", "name": "Brasil"}, {
"id": "MCO",
"name": "Colombia"
}, {"id": "MCR", "name": "Costa Rica"}, {"id": "MEC", "name": "Ecuador"}, {
"id": "MLC",
"name": "Chile"
}, {"id": "MLM", "name": "Mexico"}, {"id": "MLU", "name": "Uruguay"}, {
"id": "MLV",
"name": "Venezuela"
}, {"id": "MPA", "name": "Panamá"}, {"id": "MPE", "name": "Perú"}, {"id": "MPT", "name": "Portugal"}, {
"id": "MRD",
"name": "Dominicana"
}]);
});


app.get('/users/me', function(req, res) {
if(req.query['access_token']=='valid token') {
res.send({"id":123456,"nickname":"foobar"});
} else if(req.query['access_token']=='expired token') {
app.get('/users/me', function (req, res) {
if (req.query['access_token'] == 'valid token') {
res.send({"id": 123456, "nickname": "foobar"});
} else if (req.query['access_token'] == 'expired token') {
res.send(404);
} else {
res.send({"message":"The User ID must match the consultant's","error":"forbidden","status":403,"cause":[]}, 403);
res.send({
"message": "The User ID must match the consultant's",
"error": "forbidden",
"status": 403,
"cause": []
}, 403);
}
});


app.post('/items', function(req, res) {
if(req.query['access_token']=='valid token') {
if(req.body && req.body.foo == "bar") {
app.post('/items', function (req, res) {
if (req.query['access_token'] == 'valid token') {
if (req.body && req.body.foo == "bar") {
res.send(201);
} else {
res.send(400);
}
} else if(req.query['access_token']=='expired token') {
} else if (req.query['access_token'] == 'expired token') {
res.send(404);
} else {
res.send(403);
}
});


app.put('/items/123', function(req, res) {
if(req.query['access_token']=='valid token') {
if(req.body && req.body.foo == "bar") {
app.put('/items/123', function (req, res) {
if (req.query['access_token'] == 'valid token') {
if (req.body && req.body.foo == "bar") {
res.send(200);
} else {
res.send(400);
}
} else if(req.query['access_token']=='expired token') {
} else if (req.query['access_token'] == 'expired token') {
res.send(404);
} else {
res.send(403);
}
});

app.delete('/items/123', function(req, res) {
if(req.query['access_token']=='valid token') {
app.delete('/items/123', function (req, res) {
if (req.query['access_token'] == 'valid token') {
res.send(200);
} else if(req.query['access_token']=='expired token') {
} else if (req.query['access_token'] == 'expired token') {
res.send(404);
} else {
res.send(403);
}
});

app.get('/echo/user_agent',function(req,res) {
app.get('/echo/user_agent', function (req, res) {
if (req.headers['user-agent'].match(/MELI-JAVA-SDK-.*/))
res.send(200);
else
Expand Down
12 changes: 6 additions & 6 deletions mockapi/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "mockapi",
"version": "1.0.0",
"dependencies": {
"express" : "2.5.x"
},
"engine": "node ~> 0.8.x"
"name": "mockapi",
"version": "1.0.0",
"dependencies": {
"express": "2.5.x"
},
"engine": "node ~> 0.8.x"
}
153 changes: 101 additions & 52 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,58 +1,107 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mercadolibre</groupId>
<artifactId>sdk</artifactId>
<version>0.0.3-SNAPSHOT</version>
<distributionManagement>
<repository>
<id>repo</id>
<url>https://github.com/mercadolibre/java-sdk-repo/raw/master/releases</url>
</repository>
<snapshotRepository>
<id>snapshot-repo</id>
<url>https://github.com/mercadolibre/java-sdk-repo/raw/master/snapshots</url>
</snapshotRepository>
</distributionManagement>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<groupId>com.mercadolibre</groupId>
<artifactId>sdk</artifactId>
<version>0.0.4-SNAPSHOT</version>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<dependencies>
<dependency>
<groupId>com.ning</groupId>
<artifactId>async-http-client</artifactId>
<version>1.7.4</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
<scope>test</scope>
</dependency>
</dependencies>

</plugins>
</build>
<distributionManagement>
<repository>
<id>repo</id>
<url>https://github.com/mercadolibre/java-sdk-repo/raw/master/releases</url>
</repository>
<snapshotRepository>
<id>snapshot-repo</id>
<url>https://github.com/mercadolibre/java-sdk-repo/raw/master/snapshots</url>
</snapshotRepository>
</distributionManagement>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.6</version>
</plugin>
</plugins>
</build>

<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.9</version>
<configuration>
<dependencyLocationsEnabled>false</dependencyLocationsEnabled>
</configuration>
<reportSets>
<reportSet>
<reports>
<report>index</report>
<report>summary</report>
</reports>
</reportSet>
</reportSets>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<formats>
<format>html</format>
<format>xml</format>
</formats>
</configuration>
</plugin>
</plugins>
</reporting>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
<dependency>
<groupId>com.ning</groupId>
<artifactId>async-http-client</artifactId>
<version>1.7.4</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.2</version>
</dependency>
</dependencies>
</project>
Loading