Class: Qiita::Sdk::Client

Inherits:
Object
  • Object
show all
Includes:
ApiActions
Defined in:
lib/qiita/sdk/client.rb

Constant Summary collapse

API_BASE_URL =
'https://qiita.com'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ApiActions

#attach_reaction_to_comment, #attach_reaction_to_item, #check_following, #check_item_stock, #check_tag_following, #delete_comment, #delete_comment_reaction, #delete_following, #delete_item, #delete_item_reaction, #delete_stock, #delete_tag_following, #fetch_authenticated_user, #fetch_comment, #fetch_comment_reactions, #fetch_followees, #fetch_followers, #fetch_following_tags, #fetch_item, #fetch_item_comments, #fetch_item_likes, #fetch_item_reactions, #fetch_item_stockers, #fetch_items, #fetch_my_items, #fetch_tag, #fetch_tag_items, #fetch_user, #fetch_user_items, #fetch_user_stocks, #fetch_users, #follow_tag, #follow_user, #post_comment, #post_item, #stock_item, #update_comment, #update_item

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Client

Returns a new instance of Client.

Yields:

  • (_self)

Yield Parameters:



15
16
17
18
19
20
# File 'lib/qiita/sdk/client.rb', line 15

def initialize(options = {})
  options.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
  yield(self) if block_given?
end

Instance Attribute Details

#access_tokenString

Returns:

  • (String)


11
12
13
# File 'lib/qiita/sdk/client.rb', line 11

def access_token
  @access_token
end

Instance Method Details

#credentialObject



22
23
24
# File 'lib/qiita/sdk/client.rb', line 22

def credential
  "Bearer #{@access_token}" if @access_token
end

#delete(path) ⇒ Object



61
62
63
64
65
# File 'lib/qiita/sdk/client.rb', line 61

def delete(path)
  url = endpoint + path
  httpclient = HTTPClient.new
  httpclient.delete(url)
end

#endpointObject



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

def endpoint
  @endpoint ||= API_BASE_URL
end

#get(path, params = {}) ⇒ Object



35
36
37
38
39
# File 'lib/qiita/sdk/client.rb', line 35

def get(path, params = {})
  url = endpoint + path
  httpclient = HTTPClient.new
  httpclient.get(url, params, headers)
end

#headersObject



26
27
28
29
30
31
32
33
# File 'lib/qiita/sdk/client.rb', line 26

def headers
  headers = {
    'Accept' => 'application/json',
    'Content-Type' => 'application/json'
  }
  headers['Authorization'] = credential if credential
  headers
end

#patch(path, params = {}) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/qiita/sdk/client.rb', line 41

def patch(path, params = {})
  url = endpoint + path
  httpclient = HTTPClient.new
  p '========'
  p params.to_json
  httpclient.patch(url, params.to_json, headers)
end

#post(path, params = {}) ⇒ Object



55
56
57
58
59
# File 'lib/qiita/sdk/client.rb', line 55

def post(path, params = {})
  url = endpoint + path
  httpclient = HTTPClient.new
  httpclient.post(url, params.to_json, headers)
end

#put(path, params = {}) ⇒ Object



49
50
51
52
53
# File 'lib/qiita/sdk/client.rb', line 49

def put(path, params = {})
  url = endpoint + path
  httpclient = HTTPClient.new
  httpclient.put(url, params)
end