Permalink
Browse files

Implementation of additional methods

- Create Billet
- Edit Billet
- Delete Billet
  • Loading branch information...
1 parent ae04764 commit 6903a5548245d354db6f7b44310f23b50821ea67 @ramorim committed Sep 27, 2012
Showing with 82 additions and 2 deletions.
  1. +49 −0 lib/cobregratis.js
  2. +33 −2 test.js
View
@@ -19,4 +19,53 @@ exports.get_billets = function( callback ) {
callback( JSON.parse(body) )
})
+}
+
+exports.create = function( options, callback ) {
+
+ request(
+ {method : 'POST',
+ json : {'bank_billet' : options},
+ uri : "https://" + token + ":X@app.cobregratis.com.br/bank_billets.json"
+ },
+
+ function(err, response, body) {
+ callback( body );
+ }
+ );
+
+}
+
+exports.edit = function( id, options, callback ) {
+
+ request(
+ {method : 'PUT',
+ json : {'bank_billet' : options},
+ uri : "https://" + token + ":X@app.cobregratis.com.br/bank_billets/"+ id + ".json"
+ },
+
+ function(err, response, body) {
+ callback( body );
+ }
+ );
+
+}
+
+exports.delete = function( id, callback ) {
+
+ request(
+ {method : 'DELETE',
+ uri : "https://" + token + ":X@app.cobregratis.com.br/bank_billets/"+ id + ".json"
+ },
+
+ function(err, response, body) {
+
+ if (response.statusCode === 200) {
+ callback( "Removido com sucesso." );
+ } else {
+ callback( "Erro ao remover." );
+ }
+ }
+ );
+
}
View
35 test.js
@@ -1,15 +1,46 @@
var cobregratis = require("./lib/cobregratis");
cobregratis.set_token("FlyKmxj1aIIlmcM9oCdcLA4DW5SxnqofLwn2NwAVsE1l8BYwOGiQn9HpxyEz");
+
+cobregratis.delete(68749, function(response) {
+
+ console.log(response);
+
+});
+
/*cobregratis.get_billet(68703, function(response) {
var bank_billet = response.bank_billet;
console.log(bank_billet.description)
-});*/
+});
cobregratis.get_billets(function(response) {
console.log(response);
-})
+})
+
+var options = {
+ bank_billet_account_id : 3096,
+ name: 'Rafael Amorim teste 3',
+ amount: 13.52,
+ expire_at: "2012-09-30",
+ };
+
+cobregratis.create(options, function(response) {
+
+ console.log(response);
+
+});
+
+var options = {
+ name: 'Rafael Amorim teste editado'
+ };
+
+cobregratis.edit(68746, options, function(response) {
+
+ console.log(response);
+
+});
+*/

0 comments on commit 6903a55

Please sign in to comment.