Class: Qiitan::Client
- Inherits:
-
Object
- Object
- Qiitan::Client
- Includes:
- API::Items, API::Tags, API::Users
- Defined in:
- lib/qiitan.rb
Overview
ToDo 増えすぎたメソッドはModuleで分割する予定
Instance Attribute Summary collapse
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
-
#initialize(account) ⇒ Client
constructor
Args url_name passwordをキーにしたハッシュを指定する ==== Raise RuntimeError.
-
#rate_limit ⇒ Object
このメソッドを実行することで、APIの残りリクエスト数を取得することが出来る.
Methods included from API::Tags
Methods included from API::Items
#delete, #get_newly_post, #post
Methods included from API::Users
#get_user_info, #get_users_info, #posted_by, #stocked, #stocked_by
Constructor Details
#initialize(account) ⇒ Client
Args
url_name passwordをキーにしたハッシュを指定する
Raise
RuntimeError
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/qiitan.rb', line 57 def initialize(account) url = "#{API_BASE_URL}auth" res = Qiitan::HTTP.request(url, :post, true) do |req| req.set_form_data account end hashed = JSON.parse res.body raise 'auth error. check youre username and password' if hashed.key? 'error' @token = hashed['token'] end |
Instance Attribute Details
#token ⇒ Object (readonly)
Returns the value of attribute token.
49 50 51 |
# File 'lib/qiitan.rb', line 49 def token @token end |
Instance Method Details
#rate_limit ⇒ Object
このメソッドを実行することで、APIの残りリクエスト数を取得することが出来る
72 73 74 75 76 |
# File 'lib/qiitan.rb', line 72 def rate_limit url = "#{API_BASE_URL}rate_limit?token=#{@token}" res = Qiitan::HTTP.request(url, :get, true) JSON.parse res.body end |