Permalink
Browse files

Whee here we go.

  • Loading branch information...
dariusk committed Feb 1, 2013
1 parent 6179b58 commit 8137f49ac682d8d2aa3f3b26a9d56341079f271e
Showing with 255 additions and 3 deletions.
  1. +2 −0 .gitignore
  2. +1 −0 .npmignore
  3. +22 −0 LICENSE-MIT
  4. +25 −3 README.md
  5. +40 −0 grunt.js
  6. +6 −0 index.js
  7. +81 −0 lib/wordnik-bb.js
  8. +41 −0 package.json
  9. +37 −0 test/wordnik-bb_test.js
View
@@ -1,3 +1,5 @@
+node_modules
+
lib-cov
*.seed
*.log
View
@@ -0,0 +1 @@
+/node_modules/
View
@@ -0,0 +1,22 @@
+Copyright (c) 2013 Darius Kazemi
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
View
@@ -1,5 +1,27 @@
-wordnik
-=======
+# wordnik-bb
-A node.js interface to the Wordnik API, which lets you get dictionary definitions, random words, pronunciation, and more!
+An interface to the Wordnik API, which lets you get dictionary definitions, random words, pronunciation, and more! Built with Backbone.js.
+## Getting Started
+Install the module with: `npm install wordnik-bb`
+
+```javascript
+var wordnik_bb = require('wordnik-bb');
+wordnik_bb.awesome(); // "awesome"
+```
+
+## Documentation
+_(Coming soon)_
+
+## Examples
+_(Coming soon)_
+
+## Contributing
+In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [grunt](https://github.com/gruntjs/grunt).
+
+## Release History
+_(Nothing yet)_
+
+## License
+Copyright (c) 2013 Darius Kazemi
+Licensed under the MIT license.
View
@@ -0,0 +1,40 @@
+module.exports = function(grunt) {
+
+ // Project configuration.
+ grunt.initConfig({
+ pkg: '<json:package.json>',
+ test: {
+ files: ['test/**/*.js']
+ },
+ lint: {
+ files: ['grunt.js', 'lib/**/*.js', 'test/**/*.js']
+ },
+ watch: {
+ files: '<config:lint.files>',
+ tasks: 'default'
+ },
+ jshint: {
+ options: {
+ curly: true,
+ eqeqeq: true,
+ immed: true,
+ latedef: true,
+ newcap: true,
+ noarg: true,
+ sub: true,
+ undef: true,
+ boss: true,
+ eqnull: true,
+ node: true,
+ strict: false
+ },
+ globals: {
+ exports: true
+ }
+ }
+ });
+
+ // Default task.
+ grunt.registerTask('default', 'lint test');
+
+};
View
@@ -0,0 +1,6 @@
+var APIKEY = 'd4711e36506fe047f12970c6fdc0b43f6e4fef2e855e03d5c';
+var Wordnik = require('./lib/wordnik-bb.js').init(APIKEY);
+
+var word = new Wordnik.Word({word: 'kings', includeSuggestions: true});
+
+word.getWord();
View
@@ -0,0 +1,81 @@
+/*
+ * wordnik-bb
+ * https://github.com/dariusk/wordnik-bb
+ *
+ * Copyright (c) 2013 Darius Kazemi
+ * Licensed under the MIT license.
+ */
+
+var _ = require('underscore');
+var Backbone = require('backbone');
+var request = require('request');
+var $ = require('jquery');
+Backbone.$ = $;
+
+exports.init = function(APIKEY) {
+ return {
+ Word: Backbone.Model.extend({
+ idAttribute: 'word',
+ defaults: {
+ params: {
+ useCanonical: false,
+ includeSuggestions: false
+ }
+ },
+ url: function() {
+ var params = this.get("params");
+ var queryString = "";
+ for (var i in params) {
+ if (params.hasOwnProperty(i)) {
+ queryString += "&"+i+"="+params[i];
+ }
+ }
+ queryString = queryString.substr(1,queryString.length);
+ var url = "http://api.wordnik.com//v4/word.json/"+this.get('word')+"?"+queryString;
+ console.log(url);
+ return url;
+ },
+ validate: function(attrs, options) {
+ },
+ parse: function(resp, options) {
+ return JSON.parse(resp);
+ },
+
+ sync: function(method, model, options) {
+ console.log(options.command);
+ var _sync = Backbone.sync;
+ var deferred = $.Deferred();
+ if (method === 'read') {
+ request({
+ url : _.result(model, 'url')+"&api_key="+APIKEY,
+ BBoptions : options
+ }, function(error, response, body) {
+ if (!error && response.statusCode === 200) {
+ console.log(_.result(model, 'url')+"&api_key="+APIKEY);
+ options.success(model, body, options.BBoptions);
+ deferred.resolve(model);
+ }
+ });
+
+ return deferred.promise();
+ }
+ else {
+ return _sync.apply(this, arguments);
+ }
+ },
+ getWord: function() {
+ this.fetch({
+ command: "",
+ success : function(model, response) {
+ console.log(model);
+ },
+ error : function(model, response) {
+ console.log(response.responseText);
+ }
+ });
+ },
+ getExamples: function() {
+ }
+ })
+ };
+};
View
@@ -0,0 +1,41 @@
+{
+ "name": "wordnik-bb",
+ "description": "An interface to the Wordnik API, which lets you get dictionary definitions, random words, pronunciation, and more! Built with Backbone.js.",
+ "version": "0.1.0",
+ "homepage": "https://github.com/dariusk/wordnik-bb",
+ "author": {
+ "name": "Darius Kazemi",
+ "email": "darius.kazemi@gmail.com",
+ "url": "http://tinysubversions.com"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/dariusk/wordnik-bb.git"
+ },
+ "bugs": {
+ "url": "https://github.com/dariusk/wordnik-bb/issues"
+ },
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "https://github.com/dariusk/wordnik-bb/blob/master/LICENSE-MIT"
+ }
+ ],
+ "main": "lib/wordnik-bb",
+ "dependencies": {
+ "underscore": ">=1.4.4",
+ "backbone": ">=0.9.10",
+ "request": "2.12.0",
+ "jquery": "1.8.3"
+ },
+ "engines": {
+ "node": ">=0.8.0"
+ },
+ "scripts": {
+ "test": "grunt test"
+ },
+ "devDependencies": {
+ "grunt": "~0.3.17"
+ },
+ "keywords": []
+}
View
@@ -0,0 +1,37 @@
+var _ = require('underscore');
+var Backbone = require('backbone');
+
+var wordnik_bb = require('../lib/wordnik-bb.js');
+console.log("!!!",wordnik_bb.init('').Word());
+/*
+ ======== A Handy Little Nodeunit Reference ========
+ https://github.com/caolan/nodeunit
+
+ Test methods:
+ test.expect(numAssertions)
+ test.done()
+ Test assertions:
+ test.ok(value, [message])
+ test.equal(actual, expected, [message])
+ test.notEqual(actual, expected, [message])
+ test.deepEqual(actual, expected, [message])
+ test.notDeepEqual(actual, expected, [message])
+ test.strictEqual(actual, expected, [message])
+ test.notStrictEqual(actual, expected, [message])
+ test.throws(block, [error], [message])
+ test.doesNotThrow(block, [error], [message])
+ test.ifError(value)
+*/
+
+exports['init'] = {
+ setUp: function(done) {
+ // setup here
+ done();
+ },
+ 'no args': function(test) {
+ test.expect(1);
+ // tests here
+ test.equal(wordnik_bb.init('').Word() instanceof Backbone.Model,true , 'should be awesome.');
+ test.done();
+ }
+};

0 comments on commit 8137f49

Please sign in to comment.