Permalink
Browse files

dotcom upgrade

  • Loading branch information...
gtzilla committed Feb 17, 2011
1 parent 400e3ca commit 1afe164b675242061bed7eae7369eda17581a6c9
View
@@ -3,3 +3,7 @@ build
# key file
src.pem
+bitly_oauth_credentials.js
+src.zip
+bitly_ext*.zip
+src_alter
View
@@ -12,6 +12,21 @@ Development releases can be build by getting the source and loading as an unpack
Source Code: [github.com/bitly/bitly_chrome_extension](http://github.com/bitly/bitly_chrome_extension)
+Please see notes on setting up valid Oauth credentials
+
+Bit.ly OAuth Credentials
+-------
+You will need to create and add a file to the js directory, so that
+
+ js/bitly_oauth_credentials.js
+
+This file will contain valid credentials to use when contacting bit.ly. This is to facilitate easier re-purposing of code contained within the project. The file bitly_oauth_credentials.js.sample has been added as a reference guide
+
+ var bitly_oauth_credentials={
+ client_id : "____YOUR_BITLY_OAUTH_CLIENT_ID____",
+ client_signature : "____YOUR_BITLY_OAUTH_SIGNATURE___"
+ }
+
Features / Description
-----
@@ -24,6 +39,7 @@ Features / Description
- Works with both HTTPS and HTTP sites
- Quickly copy short links to your clipboard.
- Uses new [bit.ly](http://bit.ly/) SSL [oauth](http://oauth.net/) for authentication. You're credentials are never sent as clear text.
+- Right click "shorten and copy" your link with bit.ly
Note to users experiencing problems directly after install: Chrome doesn't allow execution of content scripts on already open pages. If you try this immediately after install on existing tabs, it won't work, so we recommend to restarting Chrome after installing the extension.
View
@@ -17,6 +17,13 @@ if [ ! -f "$CWD/src/manifest.json" ]; then
exit 1;
fi
+# support and check for separate oauth file
+if [ ! -f "$CWD/src/js/bitly_oauth_credentials.js" ]; then
+ echo "valid oauth file is needed to build the extension correctly"
+ echo "create: src/js/bitly_oauth_credentials.js with instructions from README.md"
+ exit 1;
+fi
+
## now increment the trailing version number
perl -pe 's/(\s+.version.: .\d+\.\d+\.\d+\.)(\d+)/$1.($2+1)/eg' -i "src/manifest.json"
View
@@ -0,0 +1,67 @@
+#!/bin/sh
+
+HOST_FILES="manifest.json"
+CWD=`pwd`
+#KEY="/PATH/to/chrome_extension.pem"
+# KEY=$1
+
+CHROME="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
+if [ ! -f "$CHROME" ]; then
+ echo error: ${CHROME} is not accessible
+ echo "hint: run this from your mac"
+ exit 1;
+fi
+
+if [ ! -f "$CWD/src/manifest.json" ]; then
+ echo "must be run from the chrome_extension directory"
+ exit 1;
+fi
+
+# support and check for separate oauth file
+if [ ! -f "$CWD/src/js/bitly_oauth_credentials.js" ]; then
+ echo "valid oauth file is needed to build the extension correctly"
+ echo "create: src/js/bitly_oauth_credentials.js with instructions from README.md"
+ exit 1;
+fi
+
+## now increment the trailing version number
+perl -pe 's/(\s+.version.: .\d+\.\d+\.\d+\.)(\d+)/$1.($2+1)/eg' -i "src/manifest.json"
+
+VERSION=`cat src/manifest.json | grep '"version"' | awk -F '"' '{print $4}'`
+echo "new extension version is $VERSION"
+
+## compress JS and use that for zip..
+## todo
+## cp -r src src_alter
+## for file in src/js/*.js; do echo $file; done;
+## for file in src/js/content_plugins/*.js; do echo $file; done;
+## for file in src/js/libs/*.js; do echo $file; done;
+## do
+COMPRESS_JAR="../projects/website/tools/closure_compiler.jar"
+# cp -r src src_alter
+# if [ ! -f "$COMPRESS_JAR" ]; then
+# echo "no closure compule, skipping"
+# else
+# echo "build compressed files"
+#
+# for file in src_alter/js/*.js;
+# do java -jar "$COMPRESS_JAR" --js=$file --js_output_file=$file
+# done;
+# for file in src_alter/js/content_plugins/*.js;
+# do java -jar "$COMPRESS_JAR" --js=$file --js_output_file=$file
+# done;
+# for file in src_alter/js/libs/*.js;
+# do java -jar "$COMPRESS_JAR" --js=$file --js_output_file=$file
+# done;
+#
+# fi
+## java -jar ../projects/website/tools/closure_compiler.jar --js=$file --js_output_file=$file
+## done;
+
+## remove the sample file and any Mac specific files
+zip -q -r "bitly_ext-$VERSION.zip" "$CWD/src" --exclude \*.DS_Store \*bitly_oauth_credentials.js.sample
+# rm -rf src_alter
+
+echo "upload: bitly_ext-$VERSION.zip"
+exit 0;
+
View
@@ -23,11 +23,14 @@
<!-- compress and build these?????? -->
<script type="text/javascript" src="js/bitlyapi-v3.0.js"></script>
+ <!-- //*this file does NOT appear in GIT, you will have to manually add the correct credentials* -->
+ <script type="text/javascript" src="js/bitly_oauth_credentials.js"></script>
<script type="text/javascript" src="js/sqldb-v1.0.js"></script>
<script type="text/javascript" src="js/libs/md5.js"></script>
<script type="text/javascript" src="js/libs/bg_common.js"></script>
<script type="text/javascript" src="js/libs/common.js"></script>
<script type="text/javascript" src="js/libs/bitNote.js"></script>
+ <script type="text/javascript" charset="utf-8" src="js/libs/expand_thirdparty.js"></script>
<script type="text/javascript" charset="utf-8">
@@ -163,7 +166,7 @@
}
var black_list=[], note_blacklist = localfetch("note_blacklist") || [];
- console.log("starts with", note_blacklist)
+ // console.log("starts with", note_blacklist)
var params = {
oauth_key : bitly.bit_request.access_token,
'black_list' : note_blacklist,
@@ -200,8 +203,8 @@
}
l_notes = l_notes.concat(notes_list);
- console.log("l_notes", l_notes)
- console.log("black list", black_list)
+ // console.log("l_notes", l_notes)
+ // console.log("black list", black_list)
set_notification_list( l_notes );
if(l_notes.length > 0 ) {
@@ -220,7 +223,7 @@
// I can trim out stuff from note_blacklist
- console.log("Updating the worker", black_list, params)
+ // console.log("Updating the worker", black_list, params)
trends_worker.postMessage( params );
}
@@ -475,9 +478,11 @@
function init_api() {
// get from local storage?
// pull this value from a settings file
- var client_id = "298b336871d6aa29e06b3033269f21ced9717625",
- client_signature = "319b6d82931c7b92bc05d83e005c3f415a66e31b",
- b = bitlyAPI( client_id, client_signature );
+ if(!bitly_oauth_credentials) {
+ console.log("a required file is missing! please add a valid js/bitly_oauth_credentials.js")
+ throw "MISSING_CREDENTIALS_FILE";
+ }
+ var b = bitlyAPI( bitly_oauth_credentials.client_id, bitly_oauth_credentials.client_signature );
return b;
}
function init_db( name ) {
@@ -512,6 +517,7 @@
function _util_expand_and_reshorten( long_url ) {
bitly.expand( long_url, function(jo) {
expand_meta_data = jo&&jo.expand&&jo.expand.pop();
+ if(!expand_meta_data) { return; } // todo, bubble error??
bitly.shorten( expand_meta_data.long_url, function(jo) {
if(jo && jo.url && jo.url !== "") {
copy_to_clip(jo.url);
@@ -547,7 +553,7 @@
function trends_worker_message_event( evt ) {
// console.log(evt, "the worker says?")
- console.log(evt.data, "trend data")
+ // console.log(evt.data, "trend data")
if(!evt.data.trending_links) {
@@ -571,6 +577,8 @@
}
+ /////////////////////////////////////////////////////////////
+ /// START UP the Chrome Extension Application..
logger("Initialize bit.ly extension");
// the bit.ly API connector, db interface and other global variables
var bitly=init_api(), bit_db=init_db(), trends_worker, click_by_min_worker,
@@ -586,7 +594,7 @@
trends_worker = new Worker("js/workers/realtime_data.js");
trends_worker.onmessage = trends_worker_message_event;
-
+ // derive items from cache
set_current_bitly_user_from_cache();
set_domain_list_from_cache();
set_auto_expand_from_cache();
@@ -595,19 +603,7 @@
set_auto_copy_from_cache();
set_notifications_from_cache();
set_enhance_twitter_com_from_cache();
-
-
-
-
-
-
- // click_by_min_worker = new Worker("js/workers/clicks_per_minute.js");
- // click_by_min_worker.postMessage({'shortUrl' : []});
- //
- // click_by_min_worker.onmessage = function(evt) {
- // console.log(evt, "that worker works")
- // }
-
+
/*
View
@@ -0,0 +1,7 @@
+/*
+ metrics.css
+ bitly_chrome_extension
+
+ Created by gregory tomlinson on 2011-02-12.
+ Copyright 2011 the public domain. All rights reserved.
+*/
@@ -0,0 +1,14 @@
+/*
+ This is a sample file for bit.ly oauth credentials,
+ obtain valid credentials from bit.ly, updating the below client_id and client_signature accordingly
+
+ copy the valid file from bitly_oauth_credentials.js.sample to bitly_oauth_credentials.js
+
+ support@bit.ly
+
+ Stay up-to-date with the latest api news
+*/
+var bitly_oauth_credentials={
+ client_id : "____YOUR_BITLY_OAUTH_CLIENT_ID____",
+ client_signature : "____YOUR_BITLY_OAUTH_SIGNATURE___"
+}
View
@@ -8,8 +8,8 @@
// TODO
// move this info to settings file
-var host = "http://api.bit.ly",
- ssl_host = "https://api-ssl.bit.ly",
+var host = "http://api.bitly.com",
+ ssl_host = "https://api-ssl.bitly.com",
urls = {
'shorten' : '/v3/shorten',
'expand' : '/v3/expand',
@@ -23,7 +23,8 @@ var host = "http://api.bit.ly",
'lookup' : '/v3/lookup',
'clicks_by_minute' : '/v3/clicks_by_minute',
'realtime' : '/v3/user/realtime_links',
- 'metrics_base' : '/v3/user/'
+ 'metrics_base' : '/v3/user/',
+ 'user_clicks' : '/v3/user/clicks'
}, errors = [];
///user/(clicks|country|referrers), /user/realtime_links
@@ -194,6 +195,10 @@ BitApi.prototype = {
SSL Hosts (HTTPS)
*/
+ user_clicks : function( days, callback) {
+ var params = { 'access_token' : this.bit_request.access_token, 'days' : days }
+ bitlyRequest( ssl_host + urls.user_clicks, params, callback );
+ },
realtime : function( callback ) {
var params = { 'access_token' : this.bit_request.access_token }
@@ -0,0 +1,75 @@
+//
+// expand_thirdparty.js
+// bitly_chrome_extension
+//
+// Created by gregory tomlinson on 2011-02-12.
+// Copyright 2011 the public domain. All rights reserved.
+//
+(function(){
+ window['expand_thirdparty']={
+ google : expand_google_shortlink,
+ isgd : expand_isgd_shortlink,
+ }
+
+ function startapp() {
+
+
+ }
+
+ function expand_google_shortlink( short_url ) {
+ // https://www.googleapis.com/urlshortener/v1/url?shortUrl=http://goo.gl/fbsS
+ var url="https://www.googleapis.com/urlshortener/v1/url?shortUrl="+short_url
+ open_remote(url,"GET",function(jo) {
+ console.log(jo);
+ });
+ }
+
+ function expand_isgd_shortlink(short_url) {
+ // http://is.gd/rV9Wer
+ var url = "http://is.gd/forward.php?format=json&shorturl="+short_url;
+ open_remote(url,"GET",function(jo) {
+ console.log(jo);
+ });
+ }
+
+ // function expand_tinyurl(short_url) {
+ // // http://tinyurl.com/6fmqp2o
+ // // http://preview.tinyurl.com/6fmqp2o
+ // open_remote(short_url.replace("http://", "http://preview."), "GET", function(jo) {
+ // // console.log("doc head", jo);
+ // console.log(typeof jo, jo.replace(/\n/gm, "").replace(/\r/gm, ""))
+ // var matches = jo.replace(/\n/gm, "").replace(/\r/gm, "").match(/(following)/gmi); // [^http]{1,}(http[^ ]{2,})
+ // console.log(matches);
+ // })
+ // }
+
+ function open_remote(url, type, callback) {
+ var xhr = new XMLHttpRequest(), message;
+
+ xhr.open(type, url);
+ // xhr.setRequestHeader
+
+ xhr.onreadystatechange=function() {
+ console.log("yup", xhr.getAllResponseHeaders())
+ if (xhr.readyState == 4) {
+ // do success
+ if(xhr.status === 200) {
+ try {
+ message = JSON.parse(xhr.responseText);
+ if(message && message.status_code === 200) {
+ message = message.data;
+ } else { /*throw error back?*/ }
+ } catch(e) {
+ // NOT JSON
+ message = xhr.responseXML || xhr.responseText
+ }
+ callback( message );
+ } else {
+ // non 200 status
+ callback( xhr.responseText || xhr.responseXML );
+ }
+ }
+ }
+ xhr.send();
+ }
+})();
Oops, something went wrong.

0 comments on commit 1afe164

Please sign in to comment.