Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Store expiration timestamp of access token.
2. Implement basic command line handling mechinism.
- Loading branch information
Showing
4 changed files
with
88 additions
and
14 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
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 |
---|---|---|
@@ -1,8 +1,55 @@ | ||
// Command format: | ||
// ./0xfb [Program option] <Command> [Command argument] | ||
|
||
|
||
var CONFIG = require('./config.js').app_config(); | ||
|
||
// prog_command: | ||
// Map command to module that run the command. | ||
// Each module must has run() function. And the first argument of this | ||
// function would be program option, while the second one would be | ||
// command argument. Move to ./config.js ? | ||
var progCommand = { | ||
// Update photo | ||
'uploadphoto' : './upload_photo.js' | ||
}; | ||
|
||
// It is a chance for program to make global setting before and command | ||
// is issued. Command will be executed right after this step. | ||
var handleSetting = function(progOpt, command, cmdArg) { | ||
// So far it's empty XD. | ||
} | ||
|
||
// Parse command line, collect program option, command, command argrment. | ||
var initRun = function() { | ||
|
||
var program_option = []; | ||
var command = ''; | ||
var command_argument = []; | ||
|
||
// [TODO Patrick] Here I assume there is no program options, so we just | ||
// use that first argument as command | ||
|
||
command = process.argv[2]; | ||
command_argument = process.argv.slice(3); | ||
|
||
if (!progCommand.hasOwnProperty(command)) { | ||
// Invalid command. | ||
process.exit(1); | ||
} | ||
|
||
handleSetting(program_option, command, command_argument); | ||
|
||
// Go | ||
require(progCommand[command]).run(program_option, command_argument); | ||
} | ||
|
||
// *** Start with fetching access token *** | ||
var fbOauthClient = require('./fb_oauth_client.js'); | ||
fbOauthClient.getAuthToken(function(access_token, expires) { | ||
// Debug !! | ||
console.log(" Access token: %s", access_token); | ||
console.log(" Expire Time: %d, now: %d", expires, parseInt(Date.now()/1000)); | ||
|
||
fbOauthClient.getAuthToken(function(access_token, expires_in) { | ||
console.log("We got token:"); | ||
console.log(" access_token: %s", access_token); | ||
console.log(" expires_in: %s", expires_in); | ||
process.exit(0); | ||
initRun(); | ||
}); |
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,5 @@ | ||
exports.run = function(progOpt, cmdArgs) { | ||
console.log(progOpt); | ||
console.log(cmdArgs); | ||
process.exit(0); | ||
} |