Class: TumblrApiWrapper
- Inherits:
-
Object
- Object
- TumblrApiWrapper
- Defined in:
- lib/tumblr_api_wrapper.rb
Overview
TumblrのAPIを簡単にラップしたクラス。 RESTful APIを用いて手軽にアクセスすることを目的とする。
Constant Summary
- API_BASE =
"http://api.tumblr.com/v2"
Instance Attribute Summary (collapse)
-
- (String) api_key
readonly
初期化時に設定したAPIキー.
Instance Method Summary (collapse)
-
- (Hash) get_blog_info(blog_domain) {|response| ... }
Tumblr ブログのドメインを渡すと、 そのブログの詳細な情報を返す。.
-
- (Object) get_blog_info_by_user_name(name)
deprecated
Deprecated.
昔のAPI。名前のみでは使いづらいため。 現バージョンでは #get_blog_info を利用せよ。
-
- (TumblrApiWrapper) initialize(api_key)
constructor
ラッパクラスの初期化メソッド。.
Constructor Details
- (TumblrApiWrapper) initialize(api_key)
ラッパクラスの初期化メソッド。
16 17 18 |
# File 'lib/tumblr_api_wrapper.rb', line 16 def initialize(api_key) @api_key = api_key end |
Instance Attribute Details
- (String) api_key (readonly)
初期化時に設定したAPIキー
21 22 23 |
# File 'lib/tumblr_api_wrapper.rb', line 21 def api_key @api_key end |
Instance Method Details
- (Hash) get_blog_info(blog_domain) {|response| ... }
Tumblr ブログのドメインを渡すと、 そのブログの詳細な情報を返す。
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tumblr_api_wrapper.rb', line 35 def get_blog_info(blog_domain) uri_string = \ "#{API_BASE}/blog/#{blog_domain}/info" + "?api_key=#{api_key}" json = Net::HTTP.get(URI.parse(uri_string)) response = JSON.parse(json) if response["meta"]["status"] != 200 raise "Something is wrong" end yield(response["response"]) if block_given? response["response"] end |
- (Object) get_blog_info_by_user_name(name)
Deprecated.
昔のAPI。名前のみでは使いづらいため。 現バージョンでは #get_blog_info を利用せよ。
50 51 52 |
# File 'lib/tumblr_api_wrapper.rb', line 50 def get_blog_info_by_user_name(name) get_blog_info("#{name}.tumblr.com") end |