Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added delete, update, and get credit methods, created tests.
- Loading branch information
Showing
6 changed files
with
259 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
module.exports = function (grunt) { | ||
'use strict'; | ||
// Project configuration | ||
grunt.initConfig({ | ||
// Metadata | ||
pkg: grunt.file.readJSON('package.json'), | ||
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' + | ||
'<%= grunt.template.today("yyyy-mm-dd") %>\n' + | ||
'<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' + | ||
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' + | ||
' Licensed <%= pkg.licenses[0].type %> */\n', | ||
// Task configuration | ||
concat: { | ||
options: { | ||
banner: '<%= banner %>', | ||
stripBanners: true | ||
}, | ||
dist: { | ||
src: ['lib/**/*.js'], | ||
dest: 'dist/imgur.js' | ||
} | ||
}, | ||
uglify: { | ||
options: { | ||
banner: '<%= banner %>' | ||
}, | ||
dist: { | ||
src: '<%= concat.dist.dest %>', | ||
dest: 'dist/imgur.min.js' | ||
} | ||
}, | ||
jshint: { | ||
options: { | ||
node: true, | ||
curly: true, | ||
eqeqeq: true, | ||
immed: true, | ||
latedef: true, | ||
newcap: true, | ||
noarg: true, | ||
sub: true, | ||
undef: true, | ||
unused: true, | ||
eqnull: true, | ||
boss: true | ||
}, | ||
gruntfile: { | ||
src: 'gruntfile.js' | ||
}, | ||
lib_test: { | ||
src: ['lib/**/*.js', 'test/**/*.js'] | ||
} | ||
}, | ||
nodeunit: { | ||
files: ['test/**/*.spec.js'] | ||
}, | ||
watch: { | ||
gruntfile: { | ||
files: '<%= jshint.gruntfile.src %>', | ||
tasks: ['jshint:gruntfile'] | ||
}, | ||
lib_test: { | ||
files: '<%= jshint.lib_test.src %>', | ||
tasks: ['jshint:lib_test', 'nodeunit'] | ||
} | ||
} | ||
}); | ||
|
||
// These plugins provide necessary tasks | ||
grunt.loadNpmTasks('grunt-contrib-concat'); | ||
grunt.loadNpmTasks('grunt-contrib-uglify'); | ||
grunt.loadNpmTasks('grunt-contrib-nodeunit'); | ||
grunt.loadNpmTasks('grunt-contrib-jshint'); | ||
grunt.loadNpmTasks('grunt-contrib-watch'); | ||
|
||
// Default task | ||
grunt.registerTask('default', ['jshint', 'nodeunit', 'concat', 'uglify']); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
'use strict'; | ||
|
||
var nock = require('nock'); | ||
var path = require('path'); | ||
var imgur = require('../lib/imgur'); | ||
var clientId = 'myTestId'; | ||
var imageId = 'W0JfyHW'; | ||
|
||
exports.setUp = function(callback) { | ||
imgur.setClientID(clientId); | ||
nock('https://api.imgur.com').post('/3/upload').reply(200, { | ||
success: true, | ||
status: 200, | ||
data: { | ||
link: 'http://i.imgur.com/'+imageId+'.gif' | ||
} | ||
}); | ||
nock('https://api.imgur.com').get('/3/credits').reply(200, { | ||
data: { | ||
UserLimit: 500, | ||
UserRemaining: 500, | ||
UserReset: 1417550317, | ||
ClientLimit: 12500, | ||
ClientRemaining: 12268 | ||
}, | ||
success: true, | ||
status: 200 | ||
}); | ||
nock('https://api.imgur.com').post('/3/image/' + imageId, { | ||
title: 'MyTitle', | ||
description: 'MyDescription' | ||
}).reply(200, { | ||
success: true, | ||
status: 200 | ||
}); | ||
nock('https://api.imgur.com').delete('/3/image/' + imageId).reply(200, { | ||
success: true, | ||
status: 200 | ||
}); | ||
callback(); | ||
}; | ||
|
||
exports.testUrlUpload = function(test) { | ||
imgur.upload('http://i.imgur.com/'+imageId+'.gif', function (error, res) { | ||
test.equal(error, null); | ||
test.ok(res.success, 'Should be a successful upload.'); | ||
test.equal(res.status, 200); | ||
test.done(); | ||
}); | ||
}; | ||
|
||
exports.testFileUpload = function(test) { | ||
imgur.upload(path.join(__dirname, (imageId + '.gif')), function (error, res) { | ||
test.equal(error, null); | ||
test.ok(res.success, 'Should be a successful upload.'); | ||
test.equal(res.status, 200); | ||
test.done(); | ||
}); | ||
}; | ||
|
||
exports.delete = function(test) { | ||
imgur.delete(imageId, function (error, res) { | ||
test.equal(error, null); | ||
test.ok(res.success, 'Should successfully delete the image.'); | ||
test.equal(res.status, 200); | ||
test.done(); | ||
}); | ||
}; | ||
|
||
exports.update = function(test) { | ||
imgur.update({ | ||
id: imageId, | ||
title: 'MyTitle', | ||
description: 'MyDescription', | ||
}, function (error, res) { | ||
test.equal(error, null); | ||
test.ok(res.success, 'Should successfully update the image.'); | ||
test.equal(res.status, 200); | ||
test.done(); | ||
}); | ||
}; | ||
|
||
exports.getCredits = function(test) { | ||
imgur.getCredits(function (error, res) { | ||
test.equal(error, null); | ||
test.ok(res.success, 'Should successfully return the credits left.'); | ||
test.equal(res.status, 200); | ||
test.done(); | ||
}); | ||
}; |