Permalink
Browse files

completing oauth update, testing, new basic tests, new maxSockets, an…

…d version bump
  • Loading branch information...
1 parent bf00d7d commit 041087c2327c9f2b64e5047514c23166d98718a4 @mckelvey committed Jun 23, 2011
View
@@ -1,4 +1,12 @@
+0.0.7 / 2011-06-23
+==================
+
+ * Added more control for server responses in oauth.ask_for_access_token
+ * Added Instagram.oauth tests
+ * Added Instagram.set tests
+ * Added test server option (mostly for oauth testing)
+
0.0.6 / 2011-06-09
==================
View
@@ -42,6 +42,10 @@ If you intend to use user-specific methods (e.g. relationships), then you must a
Instagram.set('redirect_uri', 'YOUR-REDIRECT-URI');
+Lastly, if you find that the default max sockets of 5 is too few for the http(s) client, you can increase it as needed with the set method. The new max sockets value must be a positive integer greater than zero.
+
+ Instagram.set('maxSockets', 10);
+
## Available Methods
All of the methods below follow a similar pattern. Each accepts a single javascript object with the needed parameters to complete the API call. Required parameters are shown below; refer to [the API docs](http://instagram.com/developer/endpoints/) for the optional parameters. All parameters are passed through to the request, so use the exact terms that the API docs provide.
@@ -450,23 +454,32 @@ To obtain a user url for the link to Instagram, use the authorization_url method
#### Ask for an Access Token
-The example below uses Express to specify a route to respond to the user's return from Instagram. It will pass the access_token and user object returned to a provided complete function. Your complete function should handle the server response (passed as a parameter) *or* include a redirect parameter for simple redirects. Be advised however, due to the event model of node.js, your users may reach the redirect address before the complete method is executed.
+The example below uses Express to specify a route to respond to the user's return from Instagram. It will pass the access_token and user object returned to a provided complete function. Your complete and error functions should handle your app server response (passed as a parameter for oauth only) *or* include a redirect parameter for simple redirects.
+
+If you choose to use the simple redirect, be advised that due to the event model of node.js, your users may reach the redirect address before the complete method is executed.
app.get('/oauth', function(request, response){
Instagram.oauth.ask_for_access_token({
request: request,
response: response,
redirect: 'http://your.redirect/url', // optional
- respond: function(response){
- response.redirect('http://your.redirect/url');
- // or some other response ended with
- response.end();
- },
complete: function(params, response){
// params['access_token']
// params['user']
+ response.writeHead(200, {'Content-Type': 'text/plain'});
+ // or some other response ended with
+ response.end();
+ },
+ error: function(errorMessage, errorObject, caller, response){
+ // errorMessage is the raised error message
+ // errorObject is either the object that caused the issue, or the nearest neighbor
+ // caller is the method in which the error occurred
+ response.writeHead(406, {'Content-Type': 'text/plain'});
+ // or some other response ended with
+ response.end();
}
});
+ return null;
});
## Developers
View
@@ -4,20 +4,22 @@ querystring = require 'querystring'
class InstagramAPI
constructor: ->
@_api_version = 'v1'
- @_client = require 'https'
+ @_http_client = require 'http'
+ @_https_client = require 'https'
@_config =
client_id: if process.env['CLIENT_ID']? then process.env['CLIENT_ID'] else 'CLIENT-ID'
client_secret: if process.env['CLIENT_SECRET']? then process.env['CLIENT_SECRET'] else 'CLIENT-SECRET'
callback_url: if process.env['CALLBACK_URL']? then process.env['CALLBACK_URL'] else 'CALLBACK-URL'
redirect_uri: if process.env['REDIRECT_URI']? then process.env['REDIRECT_URI'] else 'REDIRECT_URI'
access_token: if process.env['ACCESS_TOKEN']? then process.env['ACCESS_TOKEN'] else null
+ maxSockets: 5
@_options =
- host: 'api.instagram.com'
- port: null
+ host: if process.env['TEST_HOST']? then process.env['TEST_HOST'] else 'api.instagram.com'
+ port: if process.env['TEST_PORT']? then process.env['TEST_PORT'] else null
method: "GET"
path: ''
headers: {
- 'User-Agent': 'Instagram Node Lib 0.0.6'
+ 'User-Agent': 'Instagram Node Lib 0.0.7'
'Accept': 'application/json'
'Content-Length': 0
}
@@ -73,12 +75,18 @@ class InstagramAPI
to_object
###
- Generic Methods
+ Set Methods
###
+ _set_maxSockets: (value) ->
+ if parseInt(value) is value and value > 0
+ @_http_client.Agent.defaultMaxSockets = value
+ @_https_client.Agent.defaultMaxSockets = value
+
set: (property, value) ->
@_config[property] = value if @_config[property] isnt undefined
@_options[property] = value if @_options[property] isnt undefined
+ @["_set_#{property}"](value) if typeof @["_set_#{property}"] is 'function'
###
Shared Request Methods
@@ -97,10 +105,9 @@ class InstagramAPI
_request: (params) ->
options = @_clone(@_options)
- options['host'] = params['host'] if params['host']?
- options['port'] = params['port'] if params['port']?
options['method'] = params['method'] if params['method']?
options['path'] = params['path'] if params['path']?
+ options['path'] = if process.env['TEST_PATH_PREFIX']? then "#{process.env['TEST_PATH_PREFIX']}#{options['path']}" else options['path']
complete = params['complete'] ?= @_complete
appResponse = params['response']
error = params['error'] ?= @_error
@@ -109,7 +116,11 @@ class InstagramAPI
else
post_data = ''
options['headers']['Content-Length'] = post_data.length
- request = @_client.request options, (response) ->
+ if process.env['TEST_PROTOCOL'] is 'http'
+ http_client = @_http_client
+ else
+ http_client = @_https_client
+ request = http_client.request options, (response) ->
data = ''
response.setEncoding 'utf8'
response.on 'data', (chunk) ->
@@ -125,7 +136,10 @@ class InstagramAPI
pagination = if typeof parsedResponse['pagination'] is 'undefined' then {} else parsedResponse['pagination']
complete parsedResponse['data'], pagination
catch e
- error e, data, '_request'
+ if appResponse?
+ error e, data, '_request', appResponse
+ else
+ error e, data, '_request'
if post_data?
request.write post_data
request.addListener 'error', (connectionException) ->
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -1,6 +1,4 @@
-url = require 'url'
-
class InstagramOAuth
constructor: (parent) ->
@parent = parent
@@ -12,18 +10,16 @@ class InstagramOAuth
return "https://#{@parent._options['host']}/oauth/authorize/?#{@parent._to_querystring(params)}"
ask_for_access_token: (params) ->
+ url = require 'url'
parsed_query = url.parse(params['request'].url, true).query
if parsed_query.error?
@parent._error "#{parsed_query.error}: #{parsed_query.error_reason}: #{parsed_query.error_description}", parsed_query, 'handshake'
else if parsed_query.code?
- console.log "SURPRISE"
token_params =
complete: params['complete']
response: params['response']
- host: if process.env['TEST_HOST']? then process.env['TEST_HOST'] else @parent._options['host']
- port: if process.env['TEST_PORT']? then process.env['TEST_PORT'] else @parent._options['port']
method: "POST"
- path: if process.env['TEST_HOST']? then "/fake/oauth/access_token" else "/oauth/access_token"
+ path: "/oauth/access_token"
post_data:
client_id: @parent._config.client_id
client_secret: @parent._config.client_secret
@@ -1,6 +1,5 @@
(function() {
- var InstagramOAuth, url;
- url = require('url');
+ var InstagramOAuth;
InstagramOAuth = (function() {
function InstagramOAuth(parent) {
this.parent = parent;
@@ -12,19 +11,17 @@
return "https://" + this.parent._options['host'] + "/oauth/authorize/?" + (this.parent._to_querystring(params));
};
InstagramOAuth.prototype.ask_for_access_token = function(params) {
- var parsed_query, token_params;
+ var parsed_query, token_params, url;
+ url = require('url');
parsed_query = url.parse(params['request'].url, true).query;
if (parsed_query.error != null) {
return this.parent._error("" + parsed_query.error + ": " + parsed_query.error_reason + ": " + parsed_query.error_description, parsed_query, 'handshake');
} else if (parsed_query.code != null) {
- console.log("SURPRISE");
token_params = {
complete: params['complete'],
response: params['response'],
- host: process.env['TEST_HOST'] != null ? process.env['TEST_HOST'] : this.parent._options['host'],
- port: process.env['TEST_PORT'] != null ? process.env['TEST_PORT'] : this.parent._options['port'],
method: "POST",
- path: process.env['TEST_HOST'] != null ? "/fake/oauth/access_token" : "/oauth/access_token",
+ path: "/oauth/access_token",
post_data: {
client_id: this.parent._config.client_id,
client_secret: this.parent._config.client_secret,
View
@@ -1,7 +1,7 @@
{
"name": "instagram-node-lib",
"description": "This package is a wrapper for the Instagram API.",
- "version": "0.0.6",
+ "version": "0.0.7",
"author": "David W. McKelvey <david@mckelveycreative.com> (http://david.mckelveycreative.com/)",
"contributors": [],
"keywords": [
@@ -25,6 +25,7 @@
"url": "git://github.com/mckelvey/instagram-node-lib.git"
},
"scripts": {
+ "test set": "expresso ./test/instagram.js"
"test geographies": "expresso ./test/instagram.geographies.js",
"test locations": "expresso ./test/instagram.locations.js",
"test media": "expresso ./test/instagram.media.js",
Oops, something went wrong.

0 comments on commit 041087c

Please sign in to comment.