Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

James Robertson http://www.r0bertson.co.uk

« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS 

Twitter and Jaiku from the command line

The following instructions make it easy to post to Twitter and Jaiku from the command line. The instructions were copied from the article "Ubuntu Unleashed: Howto Twitter From the Command Line in Ubuntu!" [ubuntu-unleashed.com] and modified to post via Rorbuilder's ProjectX API.

   1  sudo apt-get install curl

   1  sudo gedit /usr/bin/jaitwit

Now Paste this in gEdit and simply replace "YourUsername" with your username and "YourPassword" with your twitter passwd, then replace the Jaiku variables (YourUsername, YourPassword, YourCity, YourAccessKey) and ctrl-s to save, then alt-F4 to exit!
   1  
   2  curl http://rorbuilder.info/api/projectx.cgi?xml_project=%3Cproject%20name=%22micro_blog%22%3E%3Cmethods%3E%3Cmethod%20name=%22post2jaiku%22%3E%3Cparams%3E%3Cparam%20var=%22user%22%20val=%22YourUsername%22/%3E%3Cparam%20var=%22msg%22%20val=%22`echo $@|tr ' ' '+'`%22/%3E%3Cparam%20var=%22location%22%20val=%22YourCity%22/%3E%3Cparam%20var=%22apikey%22%20val=%22YourAccessKey%22/%3E%3C/params%3E%3C/method%3E%3Cmethod%20name=%22post2twitter%22%3E%3Cparams%3E%3Cparam%20var=%22user%22%20val=%22YourUsername%22/%3E%3Cparam%20var=%22msg%22%20val=%22`echo $@|tr ' ' '+'`%22/%3E%3Cparam%20var=%22password%22%20val=%22YourPassword%22/%3E%3C/params%3E%3C/method%3E%3C/methods%3E%3C/project%3E -o /dev/null
   3  echo Message Sent!

Then chmod for exec privileges:
   1  chmod +x /usr/bin/jaitwit

Then from the CLI type jaitwit followed by your message.
   1  jaitwit "message here without the quotes"

Post to Jaiku using PHP

This example uses the ProjectX API to post to Jaiku.com
   1  
   2  <?php
   3    $msg = 'this is just a test message using the ProjectX API for posting to Jaiku';
   4  
   5    $xml_result =  simplexml_load_file('http://rorbuilder.info/api/projectx.cgi?xml_project=<project name="jaiku"><methods><method name="post"><params><param var="user" val="jrobertson"/><param var="msg" val="' . $msg . '"/><param var="location" val="London"/><param var="apikey" val="9ee6ffd165r364492"/></params></method></methods></project>');
   6    $method_result = $xml_result->post2jaiku;
   7    echo 'result' . $method_result;
   8  ?>


Reference: SimpleXML processing with PHP [ibm.com]

Post to both Jaiku and Twitter

This XML code is the ProjectX API to post to both Twitter and Jaiku. This is a follow-up example from Post to Jaiku using ProjectX API [dzone.com]

   1  
   2  xml_project = <<PROJECT
   3  <project name='micro_blog'>
   4    <methods>
   5      <method name='post2jaiku'>
   6        <params>
   7          <param var='user' val='YourJaikuUserName'/>
   8          <param var='msg' val='YourMessage'/>
   9          <param var='location' val='YourCity'/>
  10          <param var='apikey' val='YourApiKey'/>
  11        </params>
  12      </method>
  13      <method name='post2twitter'>
  14        <params>
  15          <param var='user' val='YourTwitterUserName'/>
  16          <param var='msg' val='YourMessage'/>
  17          <param var='password' val='YourPassword'/>
  18        </params>
  19      </method>    
  20    </methods>
  21  </project>"
  22  PROJECT

Post to Jaiku using ProjectX API

This Ruby code uses the ProjectX API on rorbuilder.info to send a post to Jaiku.

Prerequisites:
1) You have a Jaiku account. see http://jaiku.com/
2) You know your Jaiku API key. see http://api.jaiku.com/

   1  
   2  #!/usr/bin/ruby
   3  # file: projectx_client.rb
   4  
   5  require 'net/http'
   6  require 'rexml/document'
   7  include REXML
   8  
   9  class ProjectXClient
  10    attr :doc
  11    def initialize(raw_url)
  12      url = URI.escape(raw_url)
  13      xml_data = Net::HTTP.get_response(URI.parse(url)).body
  14      @doc = Document.new(xml_data)
  15    end
  16    
  17  end
  18  
  19  if __FILE__ == $0
  20  
  21  xml_project = <<PROJECT
  22  <project name='jaiku'>
  23    <methods>
  24      <method name='post'>
  25        <params>
  26          <param var='user' val='YourJaikuUserName'/>
  27          <param var='msg' val='YourMessage'/>
  28          <param var='location' val='YourCity'/>
  29          <param var='apikey' val='YourApiKey'/>
  30        </params>
  31      </method>
  32    </methods>
  33  </project>"
  34  PROJECT
  35    
  36    pxc = ProjectXClient.new("http://rorbuilder.info/api/projectx.cgi?xml_project=" + xml_project)
  37    doc = pxc.doc
  38    puts doc
  39      
  40  end
  41  


You can also pass the url including xml into the address bar and it will post to Jaiku successfully.
eg.
http://rorbuilder.info/api/projectx.cgi?xml_project="<project name='jaiku'><methods><method name='post'><params><param var='user' val='jrobertson'/><param var='msg' val='testing 223'/><param var='location' val='London'/><param var='apikey' val='5ugr6ttr754y214445'/></params></method></methods></project>"

Note:
Your api key is not in any way stored by the website rorbuilder.info.
Rorbuilder.info is a 3rd party developer website which is not part of Jaiku.com.
« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS