by agate - Published: 2010-02-13 [1:00 下午] - Category: 程序编码

今天看到 google 出了一组很酷的图形 API

地址: http://code.google.com/apis/charttools/

目前提供:
1. Image charts - using a simple URL request to a Google chart server
2. Interactive charts - using a Google developed JavaScript library
具体的就是:
1 -- [图片型图标] 只是一个图片而已
2 -- [可视化图标] 是一个 javascript 实现的可视化图形组件, 提供动态显示和鼠标事件

具体可以到: http://code.google.com/apis/charttools/docs/choosing.html 看看二者的区别

Tags: [ , , ] - Comments: View Comments
by agate - Published: 2008-09-01 [7:45 下午] - Category: 程序编码

today i saw a Jason Torres said on http://www.mashupgarage.com/ that he write a Plurk Post API. it use the Mechanize on ruby! it's great! and thanks for the idea, i code a douban "i say" api by myself!

##
# Douban API Power by Mechanize
# http://agatezone.cn
# by agate.
#

require 'rubygems'
require 'mechanize'

class Douban

  @username = ''
  @password = ''

  @agent = nil

  def initialize(username, password)
	@username = username
	@password = password

	@agent = WWW::Mechanize.new { |a|
	  a.user_agent_alias = 'Mac Safari'
	}
  end

  def send_message(message)

	@agent.get('http://www.douban.com') do |douban|

	  my_page = douban.form_with(:action => '/login') do |form|
		form.form_email = @username
		form.form_password = @password
	  end.submit

	  post_params = { :mb_text => message }
	  @agent.post('http://www.douban.com/mine/miniblogs', post_params)

	end

  end

end

DOUBAN_USERNAME = 'your-email'
DOUBAN_PASSWORD = 'your-password'

# Usage
douban = Douban.new(DOUBAN_USERNAME, DOUBAN_PASSWORD)
douban.send_message('test')
Tags: [ , , , ] - Comments: View Comments
by agate - Published: 2008-06-15 [9:06 下午] - Category: 程序编码

power by ruby language:

require "net/http"

module SmallBlogSender
  def SmallBlogSender.send(username, password, web_server, message, param_name="status")
    url = URI.parse(web_server)
    req = Net::HTTP::Post.new(url.path)
    req.basic_auth username, password
    req.set_form_data({param_name => message}, ';')
    res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
    case res
    when Net::HTTPSuccess, Net::HTTPRedirection
      # OK
    else
      res.error!
    end
    return res
  end
  UPDATESERVERS = {
    "fanfou" => "http://api.fanfou.com/statuses/update.xml",
    "twitter" => "http://twitter.com/statuses/update.xml"
  }
end

puts "message:(less than 140 characters)"
message=gets
print "username: "
username=gets.delete("\n")
print "password: "
password=gets.delete("\n")
print "==== Now sending to Fanfou ===>"
response = SmallBlogSender.send(username, password, SmallBlogSender::UPDATESERVERS["fanfou"], message)
puts " OK." if response==Net::HTTPSuccess or Net::HTTPRedirection
print "==== Now sending to Twitter ===>"
response = SmallBlogSender.send(username, password, SmallBlogSender::UPDATESERVERS["twitter"], message)
puts " OK." if response==Net::HTTPSuccess or Net::HTTPRedirection

suggest to run on linux(unix or mac) bash!

Tags: [ , ] - Comments: View Comments