Class: Qiita::Client

Inherits:
Object
  • Object
show all
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

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.

“‘rb Qiita::Client.new Qiita::Client.new(access_token: “…”) Qiita::Client.new(host: “my-team-name.qiita.com”) Qiita::Client.new(team: “my-team-name”) “`



39
40
41
42
43
44
# File 'lib/qiita/client.rb', line 39

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

#connectionObject

### Qiita::Client#connection Returns a Faraday::Connection to customize by your favorite middlewares.

“‘rb client.connection.response :logger “`



113
114
115
116
117
118
119
# File 'lib/qiita/client.rb', line 113

def connection
  @connection ||= Faraday.new(faraday_client_options) 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.

“‘rb client.delete(“/api/v2/items/543efd13001e30837319/stock”) “`



102
103
104
# File 'lib/qiita/client.rb', line 102

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.

“‘rb client.get(“/api/v2/items”, page: 2) “`



54
55
56
# File 'lib/qiita/client.rb', line 54

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.

“‘rb client.patch(“/api/v2/items/543efd13001e30837319”, title: “…”, body: “…”) “`



78
79
80
# File 'lib/qiita/client.rb', line 78

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.

“‘rb client.post(“/api/v2/items”, title: “…”, body: “…”) “`



66
67
68
# File 'lib/qiita/client.rb', line 66

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.

“‘rb client.put(“/api/v2/items/543efd13001e30837319/stock”) “`



90
91
92
# File 'lib/qiita/client.rb', line 90

def put(path, params = nil, headers = nil)
  process(:put, path, params, headers)
end