Class: Onebot::Client
- Inherits:
-
Object
- Object
- Onebot::Client
- 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
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Attributes included from ApiHelper
Instance Method Summary collapse
-
#initialize(host, token = nil, **options) ⇒ Client
constructor
A new instance of Client.
- #request(action, body = {}) ⇒ Object
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, **) @server = host || "http://localhost:5700" @token = token || [:token] Excon.defaults[:headers].merge({"Authorization" => "Bearer #{@token}"}) if @token @client = Excon.new(@server) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
9 10 11 |
# File 'lib/onebot/client.rb', line 9 def client @client end |
#server ⇒ Object (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 |