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

2012年8月17日 星期五

Nokogiri

想不到 太久沒寫 Ruby

當時好用的 HTML Parser 工具 hpricot 已經終止了

不過還好還有 Nokogiri

以前使用過 hpricot 的朋友

可以完全無痛移植 Nokogiri

 C:\DevKit>gem install nokogiri
Fetching: nokogiri-1.5.5-x86-mingw32.gem (100%)
Successfully installed nokogiri-1.5.5-x86-mingw32
1 gem installed
Installing ri documentation for nokogiri-1.5.5-x86-mingw32...
Installing RDoc documentation for nokogiri-1.5.5-x86-mingw32...

一樣快速好用歐 並且支援 xpath, css, tag屬性 搜尋




require 'nokogiri'
require 'open-uri'

# Get a Nokogiri::HTML:Document for the page we’re interested in...

doc = Nokogiri::HTML(open('http://www.google.com/search?q=tenderlove'))

# Do funky things with it using Nokogiri::XML::Node methods...

####
# Search for nodes by css
doc.css('h3.r a').each do |link|
puts link.content
end

####
# Search for nodes by xpath
doc.xpath('//h3/a').each do |link|
puts link.content
end

####
# Or mix and match.
doc.search('h3.r a.l', '//h3/a').each do |link|
puts link.content
end




grocer - 另一個 APNS 選擇

https://github.com/highgroove/grocer

好處:支援中文,支援度、擴充性更高

C:\Users\APNS>gem install grocer
Fetching: grocer-0.1.0.gem (100%)
Successfully installed grocer-0.1.0
1 gem installed
Installing ri documentation for grocer-0.1.0...
Installing RDoc documentation for grocer-0.1.0...



$pusher = Grocer.pusher(
  certificate: 'C:\Users\Ruby\APNS\push_test.pem',
  gateway:     "gateway.sandbox.push.apple.com" # optional;  defaults to gateway.push.apple.com.
)


n = Grocer::Notification.new(
      device_token: '12345',
      alert:        "Hello iPhone!",
      badge:        1)
$pusher.push(n)

Gem for APNS

PS: 這個版本 目前送中文會有問題

A gem for the Apple Push Notification Service


C:\Users\user\>gem install apns
Fetching: apns-0.9.0.gem (100%)
Successfully installed apns-0.9.0
1 gem installed
Installing ri documentation for apns-0.9.0...
Installing RDoc documentation for apns-0.9.0...


push.rb
require 'rubygems'
require 'apns'
# https://github.com/jpoz/APNS
    # APNS.host = 'gateway.push.apple.com'
    # gateway.sandbox.push.apple.com is default
    # APNS.pem  = '/path/to/pem/file'
    # this is the file you just created
   
    # APNS.port = 2195
    # this is also the default. Shouldn't ever have to set this, but just in case Apple goes crazy, you can.
APNS.pem  = 'C:\Users\APNS\apns.pem'
    device_token = '123abc456def'
    APNS.send_notification(device_token, 'Hello iPhone!' )
    APNS.send_notification(device_token, :alert => 'Hello iPhone!', :badge => 1, :sound => 'default')