Class: FlockOs::Client

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

Constant Summary collapse

BASE_URL =
'https://api.flock.co/v1'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|config| ... } ⇒ Client

Returns a new instance of Client.

Yields:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/flock_os/client.rb', line 31

def initialize(options = {})
  config = FlockOs::Configuration.new(options)

  yield config if block_given?

  @connection = Faraday.new(url: BASE_URL) do |conn|
    conn.params[:token] = config.token
    conn.request :json
    conn.response :json
    
    # conn.use ::Middleware::HandleResponseException
    conn.adapter Faraday.default_adapter
  end
end

Instance Method Details

#channelsObject



46
47
48
# File 'lib/flock_os/client.rb', line 46

def channels
  @channels ||= FlockOs::Api::Channels.new(self)
end

#chatObject



50
51
52
# File 'lib/flock_os/client.rb', line 50

def chat
  @chat ||= FlockOs::Api::Chat.new(self)
end

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



62
63
64
65
# File 'lib/flock_os/client.rb', line 62

def post(url, params = {})
  response = @connection.post(url, params)
  response.body
end

#roosterObject



54
55
56
# File 'lib/flock_os/client.rb', line 54

def rooster
  @rooster ||= FlockOs::Api::Rooster.new(self)
end

#usersObject



58
59
60
# File 'lib/flock_os/client.rb', line 58

def users
  @users ||= FlockOs::Api::Users.new(self)
end