class Crowi::Client

Public Class Methods

new(base_url: nil, access_token: nil) click to toggle source
# File lib/crowi/client.rb, line 8
def initialize(base_url: nil, access_token: nil)
  @base_url = base_url
  @access_token = access_token
end

Public Instance Methods

delete(path, params = nil, headers = nil) click to toggle source
# File lib/crowi/client.rb, line 29
def delete(path, params = nil, headers = nil)
  send_request(:delete, path, params, headers)
end
get(path, params = nil, headers = nil) click to toggle source
# File lib/crowi/client.rb, line 13
def get(path, params = nil, headers = nil)
  send_request(:get, path, params, headers)
end
patch(path, params = nil, headers = nil) click to toggle source
# File lib/crowi/client.rb, line 25
def patch(path, params = nil, headers = nil)
  send_request(:patch, path, params, headers)
end
post(path, params = nil, headers = nil) click to toggle source
# File lib/crowi/client.rb, line 17
def post(path, params = nil, headers = nil)
  send_request(:post, path, params, headers)
end
put(path, params = nil, headers = nil) click to toggle source
# File lib/crowi/client.rb, line 21
def put(path, params = nil, headers = nil)
  send_request(:put, path, params, headers)
end
send_request(method, path, params = {}, headers = nil) click to toggle source
# File lib/crowi/client.rb, line 33
def send_request(method, path, params = {}, headers = nil)
  # TODO Crowi does not support Authorization: Bearer
  params[:access_token] = @access_token
  Crowi::Response.new(connection.send(method, path, params, headers))
end

Private Instance Methods

connection() click to toggle source
# File lib/crowi/client.rb, line 40
def connection
  @connection ||= Faraday.new(faraday_options) do |connection|
     connection.request :json
     connection.response :json
     connection.adapter Faraday.default_adapter
  end
end
faraday_options() click to toggle source
# File lib/crowi/client.rb, line 48
def faraday_options
  {
     url: @base_url,
     headers: headers
  }
end
headers() click to toggle source
# File lib/crowi/client.rb, line 55
def headers
  {
    'Accept' => 'application/json',
    'User-Agent' => "Crowi Ruby Gem #{Crowi::VERSION}"
  }
end