Class: Onebot::Client

Inherits:
Object
  • Object
show all
Includes:
ApiHelper
Defined in:
lib/onebot/client.rb,
lib/onebot/client/api_helper.rb

Defined Under Namespace

Modules: ApiHelper

Constant Summary

Constants included from ApiHelper

ApiHelper::METHODS_LIST_FILE

Instance Attribute Summary collapse

Attributes included from ApiHelper

#func_list

Instance Method Summary collapse

Methods included from ApiHelper

define_helpers, get_default, methods_list, parse_param

Constructor Details

#initialize(host, token = nil, **options) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
16
# File 'lib/onebot/client.rb', line 11

def initialize(host, token = nil, **options)
  @server = host || "http://localhost:5700"
  @token = token || options[:token]
  Excon.defaults[:headers].merge({"Authorization" => "Bearer #{@token}"}) if @token
  @client = Excon.new(@server)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



9
10
11
# File 'lib/onebot/client.rb', line 9

def client
  @client
end

#serverObject (readonly)

Returns the value of attribute server.



9
10
11
# File 'lib/onebot/client.rb', line 9

def server
  @server
end

Instance Method Details

#request(action, body = {}) ⇒ Object



18
19
20
21
22
23
# File 'lib/onebot/client.rb', line 18

def request(action, body = {})
  pp body
  response = client.get(path: action, query: body)
  # raise self.class.error_for_response(response) if response.status >= 300
  JSON.parse(response.body)
end