對抗垃圾信!請您點這裡:

我的E-mail:
我的Skype:My status

顯示具有 api 標籤的文章。 顯示所有文章
顯示具有 api 標籤的文章。 顯示所有文章

2008年4月17日

Yahoo-LifeType-API (Yahoo!奇摩生活+ Ruby API)

今天剛看到生活+釋出API(其實早就釋出了,API網址:http://tw.developer.yahoo.com/lifestyle_api.html)後,就開始把NetBeans打開來寫程式了XD
現在RubyForge的專案還沒開,倒是GoogleCode的已經開了(網址:http://code.google.com/p/yahoo-lifetype-api/)
程式是BSD授權,忘記怎樣包裝Gem檔,等到哪天想起來再包XD
程式使用範例(列出生活+的分類):

#!/usr/bin/env ruby
APPID = "NhYX9XjV34FPxdq7zD8T7wwc4QGI5VWu_48NHh03zbPYUfPpcWrpZzhcVDKFQsH9dQ--"
require 'lifetype'
require 'rexml/document'
include REXML

puts "獲取生活+類別中... 請稍後"
doc = Document.new(LifeType::Class.new(APPID).listClasses)
puts "獲取類別結束"
puts "類別總數: " + doc.get_elements("//rsp/ClassList")[0].attribute("count").to_s
puts "列出類別中... 請稍後"
doc.elements.each("//rsp/ClassList/Class") do |ele|
puts "ID: #{ele.attributes["id"]} -- #{ele.get_elements("Title")[0].text}"
end
puts "列出類別結束"
很簡單的就可以使用了,還有doc喔!
有Bug可以丟到GoogleCode的Issues或者丟到我信箱內
謝謝^^


2007年2月24日

51個Rails影片跟展示

網址是:http://www.bestechvideos.com/category/development/ruby/

這邊有51個不同的展示影片,也有介紹影片,非常值得去看看

2007年2月20日

Win32API Sample: MessageBox

require 'Win32API'

=begin
Message Box:
Coded by CFC Zuso Security
CFC
2007/2/16
=end

class Msgbox
def initialize(lpText="", lpCaption="", wType = 0)
Win32API.new('user32', 'MessageBox', %w(p p p i), 'i').call(0,lpText,lpCaption,wType)
end
end

def Msgbox(lpText="", lpCaption="", wType = 0)
Win32API.new('user32', 'MessageBox', %w(p p p i), 'i').call(0,lpText,lpCaption,wType)
end

採用MIT授權條款
Usage:
Msgbox.new("Hi", "Hello, world")
Msgbox.new("XD", "Hello!", 1)
Msgbox("Hi", "Hello!")

如何透過Ruby呼叫Win32API

研究了一下.. 寫出來當Memo..
我先以一個簡單的例子來解說,就用大家最愛的MessageBox吧!

require 'win32api'
msgbox = Win32API.new('user32', 'MessageBox', %w(p p p i), 'i')
msgbox.call(0, "Message body", "Messagebox title", 1) # hwnd, lpText, lpCaption, wType => Come from API Viewer (API檢視員)

OK.. 開始來講解
1. require 'win32api'
這是將win32api.rb給引入的意思,跟C的#include用意相同

2. msgbox = Win32API.new('user32', 'MessageBox', %w(p p p i), 'i')
實體化一個Win32API物件,第一個是dllname,第二個是要呼叫的東西,第三個是API參數傳遞時的資料型態,第四個是要回傳的資料型態
如果保持nil(也就是null)的話,就表示不會有傳入或回傳

3. msgbox.call(0, "Message body", "Messagebox title", 1)
透過這個物件呼叫,hwnd傳入0,lpText傳入"Message body"接著以此類推

我來張貼一下常數表

# type flag
MB_OK = 0
MB_OKCANCEL = 1
MB_ABORTRETRYIGNORE = 2
MB_YESNOCANCEL = 3
MB_YESNO = 4
MB_RETRYCANCEL = 5

# return values
IDOK = 1
IDCANCEL = 2
IDABORT = 3
IDRETRY = 4
IDIGNORE = 5
IDYES = 6
IDNO = 7