• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

http://tinyurl.com/を見て気がついたのですが、paypalのほかにAmazon Honor Systemというのもあるようです。

手軽なマネタイズ方法としてつけることも検討してみよう

posted by Png satoko on Tue 26 Feb 2008 at 07:38

下記URLから入手できます。
http://svn.s21g.com/public/rails/plugins/tinyurl_helper/

仕様

URLを渡すとTinyURLに変換してリンクを作ります。

使い方

  • application_helper.rbでinclude
       1  module ApplicationHelper
       2    include TinyurlHelper
       3  end
    
  • View内で
       1  <%= link_to_tinyurl "http://www.yahoo.co.jp" %>
    

作り方

  1. 類似するプラグインを探してコーディングの検討をつける
  2. script/generateする
       1  script/generate plugin tinyurl_helper
    
  3. 上で生成されたlib/tinyurl_helper.rbを編集
       1  require 'net/http'
       2  
       3  module TinyurlHelper
       4    def link_to_tinyurl(url, html_options = nil)
       5      uri = 'http://tinyurl.com/api-create.php?url=' + url
       6      uri = URI.parse(uri)
       7      tiny_url = Net::HTTP.get_response(uri).body
       8      options = {:title => url, :alt => url}
       9      options = html_options.nil? ? options : options.merge(html_options)
      10      link_to tiny_url, tiny_url, options
      11    end
      12  end
    
  4. テストを書く(アプリテスト、プラグイン単体テスト両方通るように書くと吉)

       1  -
       2  require 'test/unit'
       3  require File.expand_path(File.dirname(__FILE__) + "/../lib/tinyurl_helper")
       4  
       5  class TinyurlHelperTest < Test::Unit::TestCase
       6    include TinyurlHelper
       7  
       8    #dummy link_to
       9    def link_to(name, options = {}, html_options = nil)
      10      [name, html_options[:title]]
      11    end
      12  
      13    def test_link_to_tinyurl
      14      url = 'http://www.yahoo.co.jp/'
      15      tiny_url, title = link_to_tinyurl(url)
      16      assert_equal 'http://tinyurl.com/910', tiny_url
      17      assert_equal url, title
      18    end
      19  
      20    def test_link_to_tinyurl_with_title
      21      url = 'http://www.yahoo.co.jp/'
      22      tiny_url, title = link_to_tinyurl(url, {:title => 'title'})
      23      assert_equal 'http://tinyurl.com/910', tiny_url
      24      assert_equal 'title', title
      25    end
      26  end
    

  5. README, MIT-LICENSEを書く

    • READMEは名前と、概要・使い方を書く
    • MIT-LICENSEは名前だけ変更
  6. 公開用リポジトリにコミット

  7. pluginディレクトリに登録する

Tips

  • プラグインはweb serverを再起動しないとリロードされない
  • helperを使えるようにする方法は2つ
    1. app/helper/application_helper.rbでinclude(上でやった方法)
    2. plugins/tinyurl_helper/init.rbでsendする
         1   ActionView::Base.send :include, TinyurlHelper
      
posted by Png satoko on Tue 26 Feb 2008 at 05:12
Contents
寄付の募り方
シンプルなHelperプラグインを書く:TinyURLHelper
Comments
KingofSmack: Here also good reads for this mobile applicatio... '14-5
satoko: stackoverflowでも同じエラーを挙げている人がいたので、1.3でアップロードしたよっ... '10-12
ujihisa: :%s/blog/glob/g '10-7
satoko: しゅが〜様 返事が遅くなって申し訳ありません。また、投稿百景ご購入ありがとうございます。 ... '09-10
しゅが~: こんにちは。投稿百景を発売日翌日から利用しています。本当にいいAppを作っていただきました。罫... '09-10
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ