Class: DiscourseApi::Client

Inherits:
Object
  • Object
show all
Includes:
API::Categories, API::Search, API::Topics, API::Users
Defined in:
lib/discourse_api/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from API::Users

#activate, #create_user, #toggle_avatar, #update_avatar, #update_email, #update_user, #update_username, #user

Methods included from API::Topics

#hot_topics, #invite_user_to_topic, #latest_topics, #new_topics, #topic, #topics_by

Methods included from API::Search

#search

Methods included from API::Categories

#categories

Constructor Details

#initialize(host, api_key = nil, api_username = nil) ⇒ Client

Returns a new instance of Client.



20
21
22
23
24
# File 'lib/discourse_api/client.rb', line 20

def initialize(host, api_key=nil, api_username=nil)
  @host = host
  @api_key = api_key
  @api_username = api_username
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



12
13
14
# File 'lib/discourse_api/client.rb', line 12

def api_key
  @api_key
end

#api_usernameObject

Returns the value of attribute api_username.



12
13
14
# File 'lib/discourse_api/client.rb', line 12

def api_username
  @api_username
end

#hostObject (readonly)

Returns the value of attribute host.



13
14
15
# File 'lib/discourse_api/client.rb', line 13

def host
  @host
end

Instance Method Details

#connection_optionsObject



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

def connection_options
  @connection_options ||= {
      url: @host,
      headers: {
          accept: 'application/json',
          user_agent: user_agent,
      }
  }
end

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



36
37
38
# File 'lib/discourse_api/client.rb', line 36

def delete(path, params={})
  request(:delete, path, params)
end

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



40
41
42
# File 'lib/discourse_api/client.rb', line 40

def get(path, params={})
  request(:get, path, params)
end

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



44
45
46
# File 'lib/discourse_api/client.rb', line 44

def post(path, params={})
  request(:post, path, params)
end

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



48
49
50
# File 'lib/discourse_api/client.rb', line 48

def put(path, params={})
  request(:put, path, params)
end

#user_agentObject



52
53
54
# File 'lib/discourse_api/client.rb', line 52

def user_agent
  @user_agent ||= "DiscourseAPI Ruby Gem #{DiscourseApi::VERSION}"
end