Skip to content

Commit

Permalink
Merge pull request #1 from johndavi/master
Browse files Browse the repository at this point in the history
update library for V3 compatibility and additional enumerated APIs
  • Loading branch information
johndavi committed Dec 9, 2015
2 parents abd4d25 + 45767b5 commit 37a1016
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 439 deletions.
76 changes: 41 additions & 35 deletions README.md
Expand Up @@ -17,9 +17,9 @@ Include the following JavaScript file just before the closing </head> tag of you
To access the API, you first need to create an instance of the Diffbot class.

```JavaScript
var client = new DiffBot("your token");
var client = new Diffbot("DIFFBOT TOKEN");
```
Replacing your token with your developer token.
Replacing "DIFFBOT TOKEN" with your developer token, obtainable at http://www.diffbot.com/pricing.

The library takes care of passing your API token with all API calls for the lifetime of the object.

Expand All @@ -31,31 +31,34 @@ Assume that we have our `client` configured. Now we can call the get function on
The url parameter must be an absolute url of the page you are retreiving data for.

```JavaScript
client.article.get({
client.article.get({
url: "http://www.xconomy.com/san-francisco/2012/07/25/diffbot-is-using-computer-vision-to-reinvent-the-semantic-web/"
}, function onSuccess(response) {
// output the summary
document.getElementById("content").write(response.summary);
// output the title
var element = document.getElementById("content");
element.innerHTML = response["objects"][0]["title"];
}, function onError(response) {
switch(response.errorCode) {
case "401":
break;
case "404":
break;
case "500":
break;
}
});
});
switch(response.errorCode) {
case 401:
alert(response.error)
break;
case 404:
alert(response.error)
break;
case 500:
alert(response.error)
break;
}
});
```

The first parameter accepts an object with properties as specified in the DiffBot API documentation which can be found here:
http://diffbot.com/products/automatic/article/

The second parameter is a callback function which is called if your lookup to the API is successful. The callback function is passed a single parameter containing a JSON object with all of the information returned from the DiffBot API.

The third parameter is a callback function which is called should an error occur during your lookup.
For example if the page you have request cannot be found, the example above demonstrates how you can differentiate between the error types using the errorCode property returned from
The third parameter is a callback function which is called should an error occur during your lookup.
For example if the page you have request cannot be found, the example above demonstrates how you can differentiate between the error types using the errorCode property returned from
the API

For detailed documentation of the arguments for the request, and the JSON data returned as part of the response see the DiffBot article documentation.
Expand All @@ -67,35 +70,38 @@ http://diffbot.com/products/automatic/article/
Calling the Analyze API is the same as calling the article API, just calling a different function within the client.

```JavaScript
client.analyze.get({
client.analyze.get({
url: "http://www.xconomy.com/san-francisco/2012/07/25/diffbot-is-using-computer-vision-to-reinvent-the-semantic-web/"
}, function onSuccess(response) {
// output the summary
document.getElementById("content").write(response.summary);
// output the type
var element = document.getElementById("content");
element.innerHTML = response["type"];
}, function onError(response) {
switch(response.errorCode) {
case "401":
break;
case "404":
break;
case "500":
break;
}
});
});
switch(response.errorCode) {
case 401:
alert(response.error)
break;
case 404:
alert(response.error)
break;
case 500:
alert(response.error)
break;
}
});
```

The first parameter accepts an object with properties as specified in the DiffBot API documentation which can be found here:
http://diffbot.com/products/automatic/classifier/
http://diffbot.com/products/automatic/analyze/

The second parameter is a callback function which is called if your lookup to the API is successful. The callback function is passed a single parameter containing a JSON object with all of the information returned from the DiffBot API.

The third parameter is a callback function which is called should an error occur during your lookup.
For example if the page you have request cannot be found, the example above demonstrates how you can differentiate between the error types using the errorCode property returned from
The third parameter is a callback function which is called should an error occur during your lookup.
For example if the page you have request cannot be found, the example above demonstrates how you can differentiate between the error types using the errorCode property returned from
the API

For detailed documentation of the arguments for the request, and the JSON data returned as part of the response see the DiffBot article documentation.
http://diffbot.com/products/automatic/classifier/
http://diffbot.com/products/automatic/analyze/


### Error handling
Expand All @@ -110,4 +116,4 @@ Here's an example of an error object returned to the callback function :
{ error: "Not authorized API token.", errorCode: 401 }
```

-Initial commit by Craig Cooke-
-Initial commit by Craig Cooke-

0 comments on commit 37a1016

Please sign in to comment.