]> ToastFreeware Gitweb - gregoa/bti.git/commitdiff
Merge branch 'oauth-readme' of https://github.com/agimenez/bti into agimenez-oauth...
authorGreg Kroah-Hartman <gregkh@suse.de>
Wed, 12 Jan 2011 19:06:33 +0000 (11:06 -0800)
committerGreg Kroah-Hartman <gregkh@suse.de>
Wed, 12 Jan 2011 19:06:33 +0000 (11:06 -0800)
* 'oauth-readme' of https://github.com/agimenez/bti:
  Document how to configure OAuth.

bti-bashcompletion
bti-shrink-urls.1
bti-shrink-urls.xml
bti.1
bti.c
bti.example
bti.xml

index 3dfdff050986f4beb22b918c8f9833f1a48d3dec..e627ae21c19195aa04b563a196b797d0476a74e8 100644 (file)
@@ -8,7 +8,7 @@ _bti()
                COMPREPLY=( $(compgen -W "-a -A -p -P -H -b -d -v -s -n -g -h -r
                        --account --action --password --proxy --host --bash \
                        --user --debug --dry-run --shrink-urls --page --version --verbose \
-                       --help --replyto" -- ${cur}) )
+                       --help --replyto --retweet" -- ${cur}) )
        fi
 
        if [[ "${prev}" == "--host" ]] ; then
index 288c3ec48cabfbb929484adb2f3b967e62288418..0c5ca7ff72a73ca194e0ac9f18a16a53dfb1b85e 100644 (file)
@@ -1,6 +1,7 @@
+'\" t
 .\"     Title: bti-shrink-urls
 .\"    Author: [see the "AUTHOR" section]
-.\" Generator: DocBook XSL Stylesheets v1.74.0 <http://docbook.sf.net/>
+.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
 .\"      Date: March 2009
 .\"    Manual: bti-shrink-urls
 .\"    Source: bti-shrink-urls
@@ -8,155 +9,6 @@
 .\"
 .TH "BTI\-SHRINK\-URLS" "1" "March 2009" "bti-shrink-urls" "bti-shrink-urls"
 .\" -----------------------------------------------------------------
-.\" * (re)Define some macros
-.\" -----------------------------------------------------------------
-.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-.\" toupper - uppercase a string (locale-aware)
-.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-.de toupper
-.tr aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ
-\\$*
-.tr aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz
-..
-.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-.\" SH-xref - format a cross-reference to an SH section
-.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-.de SH-xref
-.ie n \{\
-.\}
-.toupper \\$*
-.el \{\
-\\$*
-.\}
-..
-.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-.\" SH - level-one heading that works better for non-TTY output
-.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-.de1 SH
-.\" put an extra blank line of space above the head in non-TTY output
-.if t \{\
-.sp 1
-.\}
-.sp \\n[PD]u
-.nr an-level 1
-.set-an-margin
-.nr an-prevailing-indent \\n[IN]
-.fi
-.in \\n[an-margin]u
-.ti 0
-.HTML-TAG ".NH \\n[an-level]"
-.it 1 an-trap
-.nr an-no-space-flag 1
-.nr an-break-flag 1
-\." make the size of the head bigger
-.ps +3
-.ft B
-.ne (2v + 1u)
-.ie n \{\
-.\" if n (TTY output), use uppercase
-.toupper \\$*
-.\}
-.el \{\
-.nr an-break-flag 0
-.\" if not n (not TTY), use normal case (not uppercase)
-\\$1
-.in \\n[an-margin]u
-.ti 0
-.\" if not n (not TTY), put a border/line under subheading
-.sp -.6
-\l'\n(.lu'
-.\}
-..
-.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-.\" SS - level-two heading that works better for non-TTY output
-.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-.de1 SS
-.sp \\n[PD]u
-.nr an-level 1
-.set-an-margin
-.nr an-prevailing-indent \\n[IN]
-.fi
-.in \\n[IN]u
-.ti \\n[SN]u
-.it 1 an-trap
-.nr an-no-space-flag 1
-.nr an-break-flag 1
-.ps \\n[PS-SS]u
-\." make the size of the head bigger
-.ps +2
-.ft B
-.ne (2v + 1u)
-.if \\n[.$] \&\\$*
-..
-.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-.\" BB/BE - put background/screen (filled box) around block of text
-.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-.de BB
-.if t \{\
-.sp -.5
-.br
-.in +2n
-.ll -2n
-.gcolor red
-.di BX
-.\}
-..
-.de EB
-.if t \{\
-.if "\\$2"adjust-for-leading-newline" \{\
-.sp -1
-.\}
-.br
-.di
-.in
-.ll
-.gcolor
-.nr BW \\n(.lu-\\n(.i
-.nr BH \\n(dn+.5v
-.ne \\n(BHu+.5v
-.ie "\\$2"adjust-for-leading-newline" \{\
-\M[\\$1]\h'1n'\v'+.5v'\D'P \\n(BWu 0 0 \\n(BHu -\\n(BWu 0 0 -\\n(BHu'\M[]
-.\}
-.el \{\
-\M[\\$1]\h'1n'\v'-.5v'\D'P \\n(BWu 0 0 \\n(BHu -\\n(BWu 0 0 -\\n(BHu'\M[]
-.\}
-.in 0
-.sp -.5v
-.nf
-.BX
-.in
-.sp .5v
-.fi
-.\}
-..
-.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-.\" BM/EM - put colored marker in margin next to block of text
-.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-.de BM
-.if t \{\
-.br
-.ll -2n
-.gcolor red
-.di BX
-.\}
-..
-.de EM
-.if t \{\
-.br
-.di
-.ll
-.gcolor
-.nr BH \\n(dn
-.ne \\n(BHu
-\M[\\$1]\D'P -.75n 0 0 \\n(BHu -(\\n[.i]u - \\n(INu - .75n) 0 0 -\\n(BHu'\M[]
-.in 0
-.nf
-.BX
-.in
-.fi
-.\}
-..
-.\" -----------------------------------------------------------------
 .\" * set default formatting
 .\" -----------------------------------------------------------------
 .\" disable hyphenation
 .\" -----------------------------------------------------------------
 .\" * MAIN CONTENT STARTS HERE *
 .\" -----------------------------------------------------------------
-.SH "Name"
+.SH "NAME"
 bti-shrink-urls \- convert URLs to a shorter form using a web service
-.SH "Synopsis"
-.fam C
+.SH "SYNOPSIS"
 .HP \w'\fBbti\fR\ 'u
 \fBbti\fR [\fB\-\-escaped\fR] [\fB\-\-help\fR] [\fBURL\fR]
-.fam
 .SH "DESCRIPTION"
 .PP
 bti\-shrink\-urls converts URLs to a shorter form using a web service\&.
 .PP
-Currently only http://2tu\&.us/ is supported\&.
+Currently http://2tu\&.us/ (default) and http://bit\&.ly / http://j\&.mp are supported\&.
 .SH "OPTIONS"
 .PP
 \fB\-\-escaped\fR
@@ -194,13 +44,31 @@ Print help text\&.
 .RS 4
 Specify the URL to be converted\&. If no URL is given bti\-shrink\-urls waits for input on stdin\&.
 .RE
+.SH "CONFIGURATION"
+.PP
+bti\-shrink\-urls is configured by setting some values in ~/\&.bti:
+.PP
+\fBshrink_host\fR
+.RS 4
+Possible values: 2tu\&.us (default), bit\&.ly, j\&.mp
+.RE
+.PP
+\fBshrink_bitly_login\fR
+.RS 4
+API login for bit\&.ly, j\&.mp, required if shrink_host is set to bit\&.ly or j\&.mp\&. See https://code\&.google\&.com/p/bitly\-api/wiki/ApiDocumentation
+.RE
+.PP
+\fBshrink_bitly_key\fR
+.RS 4
+API key for bit\&.ly, j\&.mp, required if shrink_host is set to bit\&.ly or j\&.mp\&. See https://code\&.google\&.com/p/bitly\-api/wiki/ApiDocumentation
+.RE
 .SH "AUTHOR"
 .PP
 Written by Bart Trojanowski
-\FCbart@jukie\&.net\F[]\&.
+bart@jukie\&.net\&.
 .SH "COPYRIGHT AND LICENSE"
 .PP
 Copyright (C) 2009 Bart Trojanowski
-\FCbart@jukie\&.net\F[]\&.
+bart@jukie\&.net\&.
 .PP
 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation version 2 of the License\&.
index 491743bec4f1831c09aceafa0b2e81c0b363aae3..9a7c77042483478a270db1473d8627c32a92a4e3 100644 (file)
@@ -37,7 +37,7 @@
          bti-shrink-urls converts URLs to a shorter form using a web service.
         </para>
         <para>
-          Currently only http://2tu.us/ is supported.
+          Currently http://2tu.us/ (default) and http://bit.ly / http://j.mp are supported.
         </para>
       </refsect1>
 
         </variablelist>
       </refsect1>
 
+      <refsect1><title>CONFIGURATION</title>
+        <para>
+         bti-shrink-urls is configured by setting some values in ~/.bti:
+        </para>
+        <variablelist>
+          <varlistentry>
+            <term><option>shrink_host</option></term>
+            <listitem>
+              <para>
+               Possible values: 2tu.us (default), bit.ly, j.mp
+             </para>
+            </listitem>
+          </varlistentry>
+          <varlistentry>
+            <term><option>shrink_bitly_login</option></term>
+            <listitem>
+              <para>
+               API login for bit.ly, j.mp, required if shrink_host is set to  bit.ly or j.mp.
+               See https://code.google.com/p/bitly-api/wiki/ApiDocumentation
+              </para>
+            </listitem>
+          </varlistentry>
+          <varlistentry>
+            <term><option>shrink_bitly_key</option></term>
+            <listitem>
+              <para>
+               API key for bit.ly, j.mp, required if shrink_host is set to  bit.ly or j.mp.
+               See https://code.google.com/p/bitly-api/wiki/ApiDocumentation
+              </para>
+            </listitem>
+          </varlistentry>
+        </variablelist>
+      </refsect1>
+
        <refsect1><title>AUTHOR</title>
          <para>Written by Bart Trojanowski <email>bart@jukie.net</email>.</para>
        </refsect1>
diff --git a/bti.1 b/bti.1
index 778d58de851cba2082f527a159d15864015b9ec1..228cdf840ebc5e4b6156c09d84e1de94a1c8d302 100644 (file)
--- a/bti.1
+++ b/bti.1
@@ -22,7 +22,7 @@
 bti \- send a tweet to twitter\&.com or identi\&.ca from the command line
 .SH "SYNOPSIS"
 .HP \w'\fBbti\fR\ 'u
-\fBbti\fR [\fB\-\-account\ account\fR] [\fB\-\-password\ password\fR] [\fB\-\-action\ action\fR] [\fB\-\-user\ screenname\fR] [\fB\-\-host\ HOST_NAME\fR] [\fB\-\-proxy\ PROXY:PORT\fR] [\fB\-\-logfile\ LOGFILE\fR] [\fB\-\-config\ CONFIGFILE\fR] [\fB\-\-replyto\ ID\fR] [\fB\-\-page\ PAGENUMBER\fR] [\fB\-\-bash\fR] [\fB\-\-shrink\-urls\fR] [\fB\-\-debug\fR] [\fB\-\-dry\-run\fR] [\fB\-\-verbose\fR] [\fB\-\-version\fR] [\fB\-\-help\fR]
+\fBbti\fR [\fB\-\-account\ account\fR] [\fB\-\-password\ password\fR] [\fB\-\-action\ action\fR] [\fB\-\-user\ screenname\fR] [\fB\-\-host\ HOST_NAME\fR] [\fB\-\-proxy\ PROXY:PORT\fR] [\fB\-\-logfile\ LOGFILE\fR] [\fB\-\-config\ CONFIGFILE\fR] [\fB\-\-replyto\ ID\fR] [\fB\-\-retweet\ ID\fR] [\fB\-\-page\ PAGENUMBER\fR] [\fB\-\-bash\fR] [\fB\-\-shrink\-urls\fR] [\fB\-\-debug\fR] [\fB\-\-dry\-run\fR] [\fB\-\-verbose\fR] [\fB\-\-version\fR] [\fB\-\-help\fR]
 .SH "DESCRIPTION"
 .PP
 bti sends a tweet message to twitter\&.com or identi\&.ca\&.
@@ -81,11 +81,18 @@ For twitter, this is ignored unless the message starts with the @name of the own
 For status\&.net, this can link any two messages into context with each other\&. Status\&.net will also link a message that contains an @name without this without regard to context\&.
 .RE
 .PP
+\fB\-\-retweet ID\fR
+.RS 4
+Status ID of a single post which you want to retweet\&.
+.RE
+.PP
 \fB\-\-shrink\-urls\fR
 .RS 4
 Scans the tweet text for valid URL patterns and passes each through the supplied bti\-shrink\-urls script\&. The script will pass the URL to a web service that shrinks the URLs, making it more suitable for micro\-blogging\&.
 .sp
-Currently, only http://2tu\&.us/ is used as a URL shrinking service\&.
+The following URL shrinking services are available: http://2tu\&.us/ (default) and http://bit\&.ly / http://j\&.mp
+.sp
+See the documentation for bti\-shrink\-urls for the configuration options\&.
 .RE
 .PP
 \fB\-\-debug\fR
diff --git a/bti.c b/bti.c
index 0229a9a75fdf7a09fa0bc86a5fb177aa72909ae2..4ad5b541052a2ce7115a1255fca341e98404e194 100644 (file)
--- a/bti.c
+++ b/bti.c
@@ -98,6 +98,7 @@ struct session {
        int dry_run;
        int page;
        int no_oauth;
+       int guest;
        enum host host;
        enum action action;
        void *readline_handle;
@@ -592,7 +593,7 @@ static int send_request(struct session *session)
        if (!session->hosturl)
                session->hosturl = strdup(twitter_host);
 
-       if (session->no_oauth) {
+       if (session->no_oauth || session->guest) {
                curl_buf = bti_curl_buffer_alloc(session->action);
                if (!curl_buf)
                        return -ENOMEM;
@@ -749,26 +750,29 @@ static int send_request(struct session *session)
                        break;
                }
 
-               if (is_post) {
-                       req_url = oauth_sign_url2(endpoint, &postarg, OA_HMAC,
-                                                 NULL, session->consumer_key,
-                                                 session->consumer_secret,
-                                                 session->access_token_key,
-                                                 session->access_token_secret);
-                       reply = oauth_http_post(req_url, postarg);
-               } else {
-                       req_url = oauth_sign_url2(endpoint, NULL, OA_HMAC, NULL,
-                                                 session->consumer_key,
-                                                 session->consumer_secret,
-                                                 session->access_token_key,
-                                                 session->access_token_secret);
-                       reply = oauth_http_get(req_url, postarg);
-               }
+               dbg("%s\n", endpoint);
+               if (!session->dry_run) {
+                       if (is_post) {
+                               req_url = oauth_sign_url2(endpoint, &postarg, OA_HMAC,
+                                                         NULL, session->consumer_key,
+                                                         session->consumer_secret,
+                                                         session->access_token_key,
+                                                         session->access_token_secret);
+                               reply = oauth_http_post(req_url, postarg);
+                       } else {
+                               req_url = oauth_sign_url2(endpoint, NULL, OA_HMAC, NULL,
+                                                         session->consumer_key,
+                                                         session->consumer_secret,
+                                                         session->access_token_key,
+                                                         session->access_token_secret);
+                               reply = oauth_http_get(req_url, postarg);
+                       }
 
-               dbg("%s\n", req_url);
-               dbg("%s\n", reply);
-               if (req_url)
-                       free(req_url);
+                       dbg("%s\n", req_url);
+                       dbg("%s\n", reply);
+                       if (req_url)
+                               free(req_url);
+               }
 
                if ((session->action != ACTION_UPDATE) &&
                                (session->action != ACTION_RETWEET))
@@ -1544,11 +1548,17 @@ int main(int argc, char *argv[], char *envp[])
 
        if (session->host == HOST_TWITTER) {
                if (!session->consumer_key || !session->consumer_secret) {
-                       fprintf(stderr,
-                               "Twitter no longer supports HTTP basic authentication.\n"
-                               "Both consumer key, and consumer secret are required"
-                               " for bti in order to behave as an OAuth consumer.\n");
-                       goto exit;
+                       if (session->action == ACTION_USER ||
+                                       session->action == ACTION_PUBLIC) {
+                               /* Some actions may still work without authentication */
+                               session->guest = 1;
+                       } else {
+                               fprintf(stderr,
+                                               "Twitter no longer supports HTTP basic authentication.\n"
+                                               "Both consumer key, and consumer secret are required"
+                                               " for bti in order to behave as an OAuth consumer.\n");
+                               goto exit;
+                       }
                }
                if (session->action == ACTION_GROUP) {
                        fprintf(stderr, "Groups only work in Identi.ca.\n");
@@ -1570,7 +1580,7 @@ int main(int argc, char *argv[], char *envp[])
                                      session->hostname);
                        session->password = strdup(password);
                }
-       } else {
+       } else if (!session->guest) {
                if (!session->access_token_key ||
                    !session->access_token_secret) {
                        request_access_token(session);
index e6ad4899d8d81924e9702ce33bba262f6eb4aecc..615cc1081027981790ad3e5882e842cc1c0f4924 100644 (file)
@@ -13,3 +13,7 @@ logfile=.bti.log
 #user=gregkh
 #proxy=http://localhost:8080
 #shrink-urls=yes
+# Example of using bit.ly in bti-shrink-urls
+#shrink_host=bit.ly
+#shrink_bitly_login=bitlyuser
+#shrink_bitly_key=R_deadbeef
diff --git a/bti.xml b/bti.xml
index 0fba17ff5b48d9036bfe6e28987f61ecf4ab9162..ae08e4f8b47949b6c2267a4f53fd92394de6a552 100644 (file)
--- a/bti.xml
+++ b/bti.xml
@@ -35,6 +35,7 @@
           <arg><option>--logfile LOGFILE</option></arg>
           <arg><option>--config CONFIGFILE</option></arg>
           <arg><option>--replyto ID</option></arg>
+          <arg><option>--retweet ID</option></arg>
           <arg><option>--page PAGENUMBER</option></arg>
           <arg><option>--bash</option></arg>
           <arg><option>--shrink-urls</option></arg>
               </para>
             </listitem>
           </varlistentry>
+          <varlistentry>
+            <term><option>--retweet ID</option></term>
+            <listitem>
+              <para>
+               Status ID of a single post which you want to retweet.
+             </para>
+            </listitem>
+          </varlistentry>
           <varlistentry>
             <term><option>--shrink-urls</option></term>
             <listitem>
                 more suitable for micro-blogging.
               </para>
               <para>
-                Currently, only http://2tu.us/ is used as a URL shrinking service.
+                The following URL shrinking services are available:
+                http://2tu.us/ (default) and http://bit.ly / http://j.mp
+              </para>
+              <para>
+                See the documentation for bti-shrink-urls for the configuration options.
               </para>
             </listitem>
           </varlistentry>