Class: Qiita::Client
- Inherits:
-
Object
- Object
- Qiita::Client
- Includes:
- ResourceBasedMethods
- Defined in:
- lib/qiita/client.rb
Constant Summary collapse
- DEFAULT_ACCEPT =
"application/json"- DEFAULT_HOST =
"qiita.com"- DEFAULT_USER_AGENT =
"Qiita Ruby Gem #{Qiita::VERSION}"- DEFAULT_HEADERS =
{ "Accept" => DEFAULT_ACCEPT, "User-Agent" => DEFAULT_USER_AGENT, }
Instance Method Summary collapse
-
#connection ⇒ Object
Qiita::Client#connection Returns a Faraday::Connection to customize by your favorite middlewares.
-
#delete(path, params = nil, headers = nil) ⇒ Object
Qiita::Client#delete(path, params = nil, headers = nil) Sends DELETE request, then returns a Qiita::Response.
-
#get(path, params = nil, headers = nil) ⇒ Object
Qiita::Client#get(path, params = nil, headers = nil) Sends GET request with given parameters, then returns a
Qiita::Response. -
#initialize(access_token: nil, host: nil, ssl: true, team: nil) ⇒ Client
constructor
Qiita::Client.new(options = {}) Creates a new instance of
Qiita::Clientclass. -
#patch(path, params = nil, headers = nil) ⇒ Object
Qiita::Client#patch(path, params = nil, headers = nil) Sends PATCH request with given parameters, then returns a Qiita::Response.
-
#post(path, params = nil, headers = nil) ⇒ Object
Qiita::Client#post(path, params = nil, headers = nil) Sends POST request with given parameters, then returns a Qiita::Response.
-
#put(path, params = nil, headers = nil) ⇒ Object
Qiita::Client#put(path, params = nil, headers = nil) Sends PUT request, then returns a Qiita::Response.
Methods included from ResourceBasedMethods
#create_access_token, #create_comment_reaction, #create_expanded_template, #create_item, #create_item_comment, #create_item_reaction, #create_project, #create_project_reaction, #create_tagging, #create_template, #delete_access_token, #delete_comment, #delete_comment_reaction, #delete_item, #delete_item_reaction, #delete_project, #delete_project_reaction, #delete_tagging, #delete_template, #follow_tag, #follow_user, #get_authenticated_user, #get_comment, #get_item, #get_item_like, #get_item_stock, #get_project, #get_tag, #get_tag_following, #get_template, #get_user, #get_user_following, #like_item, #list_authenticated_user_items, #list_comment_reactions, #list_item_comments, #list_item_likes, #list_item_reactions, #list_item_stockers, #list_items, #list_project_reactions, #list_projects, #list_tag_items, #list_tags, #list_teams, #list_templates, #list_user_followees, #list_user_followers, #list_user_following_tags, #list_user_items, #list_user_stocks, #list_users, #stock_item, #thank_comment, #unfollow_tag, #unfollow_user, #unlike_item, #unstock_item, #unthank_comment, #update_comment, #update_item, #update_project, #update_template
Constructor Details
#initialize(access_token: nil, host: nil, ssl: true, team: nil) ⇒ Client
Qiita::Client.new(options = {})
Creates a new instance of Qiita::Client class.
options can have following key-values:
access_token- (String) Access token issued to authenticate and authorize user.host- (String) Hostname where this client accesses to.ssl- (Boolean) Use SSL verification. (default: true)team- (String) Team name to be used as subdomain.
Qiita::Client.new
Qiita::Client.new(access_token: "...")
Qiita::Client.new(host: "my-team-name.qiita.com")
Qiita::Client.new(team: "my-team-name")
38 39 40 41 42 43 |
# File 'lib/qiita/client.rb', line 38 def initialize(access_token: nil, host: nil, ssl: true, team: nil) @access_token = access_token @host = host @ssl = ssl @team = team end |
Instance Method Details
#connection ⇒ Object
Qiita::Client#connection
Returns a Faraday::Connection to customize by your favorite middlewares.
client.connection.response :logger
112 113 114 115 116 117 118 |
# File 'lib/qiita/client.rb', line 112 def connection @connection ||= Faraday.new() do |connection| connection.request :json connection.response :json connection.adapter Faraday.default_adapter end end |
#delete(path, params = nil, headers = nil) ⇒ Object
Qiita::Client#delete(path, params = nil, headers = nil)
Sends DELETE request, then returns a Qiita::Response.
params are url-encoded and used as URI query string.
client.delete("/api/v2/items/543efd13001e30837319/stock")
101 102 103 |
# File 'lib/qiita/client.rb', line 101 def delete(path, params = nil, headers = nil) process(:delete, path, params, headers) end |
#get(path, params = nil, headers = nil) ⇒ Object
Qiita::Client#get(path, params = nil, headers = nil)
Sends GET request with given parameters, then returns a Qiita::Response.
params are url-encoded and used as URI query string.
client.get("/api/v2/items", page: 2)
53 54 55 |
# File 'lib/qiita/client.rb', line 53 def get(path, params = nil, headers = nil) process(:get, path, params, headers) end |
#patch(path, params = nil, headers = nil) ⇒ Object
Qiita::Client#patch(path, params = nil, headers = nil)
Sends PATCH request with given parameters, then returns a Qiita::Response.
params are JSON-encoded and used as request body.
client.patch("/api/v2/items/543efd13001e30837319", title: "...", body: "...")
77 78 79 |
# File 'lib/qiita/client.rb', line 77 def patch(path, params = nil, headers = nil) process(:patch, path, params, headers) end |
#post(path, params = nil, headers = nil) ⇒ Object
Qiita::Client#post(path, params = nil, headers = nil)
Sends POST request with given parameters, then returns a Qiita::Response.
params are JSON-encoded and used as request body.
client.post("/api/v2/items", title: "...", body: "...")
65 66 67 |
# File 'lib/qiita/client.rb', line 65 def post(path, params = nil, headers = nil) process(:post, path, params, headers) end |
#put(path, params = nil, headers = nil) ⇒ Object
Qiita::Client#put(path, params = nil, headers = nil)
Sends PUT request, then returns a Qiita::Response.
params are JSON-encoded and used as request body.
client.put("/api/v2/items/543efd13001e30837319/stock")
89 90 91 |
# File 'lib/qiita/client.rb', line 89 def put(path, params = nil, headers = nil) process(:put, path, params, headers) end |