Class: MixinBot::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/mixin_bot/client.rb

Constant Summary collapse

SERVER_SCHEME =
'https'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/mixin_bot/client.rb', line 9

def initialize(config)
  @config = config || MixinBot.config
  @conn = Faraday.new(
    url: "#{SERVER_SCHEME}://#{config.api_host}",
    headers: {
      'Content-Type' => 'application/json',
      'User-Agent' => "mixin_bot/#{MixinBot::VERSION}"
    }
  ) do |f|
    f.request :json
    f.request :retry
    f.response :json
    f.response :logger if config.debug
  end
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/mixin_bot/client.rb', line 7

def config
  @config
end

#connObject (readonly)

Returns the value of attribute conn.



7
8
9
# File 'lib/mixin_bot/client.rb', line 7

def conn
  @conn
end

Instance Method Details

#get(path) ⇒ Object



25
26
27
# File 'lib/mixin_bot/client.rb', line 25

def get(path, *, **)
  request(:get, path, *, **)
end

#post(path) ⇒ Object



29
30
31
# File 'lib/mixin_bot/client.rb', line 29

def post(path, *, **)
  request(:post, path, *, **)
end