Class: Qiitan::Client

Inherits:
Object
  • Object
show all
Includes:
API::Items, API::Tags, API::Users
Defined in:
lib/qiitan.rb

Overview

ToDo 増えすぎたメソッドはModuleで分割する予定

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from API::Tags

#tags_list

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()
	url = "#{API_BASE_URL}auth"
	res = Qiitan::HTTP.request(url, :post, true) do |req|
		req.set_form_data 
	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

#tokenObject (readonly)

Returns the value of attribute token.



49
50
51
# File 'lib/qiitan.rb', line 49

def token
  @token
end

Instance Method Details

#rate_limitObject

このメソッドを実行することで、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