この例に基づいて、十分に単純なビット実装を使用しています: http://www.appelsiini.net/2010/using-bitly-with-httparty
このファイルを lib フォルダー (bitly.rb) に配置します。
require 'rubygems'
require 'httparty'
class Bitly
include HTTParty
base_uri "api.bit.ly"
@@login = "goldhat"
@@api_key = "R_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
def self.shorten(url)
response = get("/v3/shorten?login=#{@@login}&apiKey=#{@@api_key}&longUrl=#{url}")
response["data"]["url"]
end
end
何らかの理由で、nil オブジェクトを取得しています。あたかもbitlyがデータでさえ応答しないかのように。コンソールとアプリでテストしたところ、同じエラーが発生しました。
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]
from c:/goldhat_production/lib/bitly.rb:9:in `shorten'
from (irb):1
何か案は?