Class: Turbot::API

Inherits:
Object
  • Object
show all
Defined in:
lib/turbot/api.rb,
lib/turbot/api/version.rb,
lib/turbot/api/response.rb

Defined Under Namespace

Classes: FailureResponse, Response, SuccessResponse

Constant Summary collapse

VERSION =
'0.0.17'

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ API

Returns a new instance of API.



10
11
12
13
14
15
# File 'lib/turbot/api.rb', line 10

def initialize(params)
  @host = params[:host]
  @port = params[:port]
  @scheme = params[:scheme]
  @api_key = params[:api_key] || get_api_key_for_credentials(params[:username], params[:password])['api_key']
end

Instance Method Details

#create_bot(bot_id, config, env = nil) ⇒ Turbot::API::SuccessResponse, Turbot::API::FailureResponse



52
53
54
# File 'lib/turbot/api.rb', line 52

def create_bot(bot_id, config, env = nil)
  request(:post, '/api/bots', :bot => {:bot_id => bot_id, :config => config, :env => env})
end

#create_draft_data(bot_id, batch) ⇒ Turbot::API::SuccessResponse, Turbot::API::FailureResponse



67
68
69
# File 'lib/turbot/api.rb', line 67

def create_draft_data(bot_id, batch)
  request(:post, "/api/bots/#{bot_id}/draft_data", :batch => batch)
end

#destroy_draft_data(bot_id) ⇒ Turbot::API::SuccessResponse, Turbot::API::FailureResponse



72
73
74
# File 'lib/turbot/api.rb', line 72

def destroy_draft_data(bot_id)
  request(:delete, "/api/bots/#{bot_id}/draft_data")
end

#get_api_keyString

Returns the user’s API key.

Returns:

  • (String)

    the user’s API key



26
27
28
# File 'lib/turbot/api.rb', line 26

def get_api_key
  get_user['api_key']
end

#get_api_key_for_credentials(user, password) ⇒ Hash

Returns a hash with a single key “api_key”.

Returns:

  • (Hash)

    a hash with a single key “api_key”



31
32
33
34
35
36
37
38
39
# File 'lib/turbot/api.rb', line 31

def get_api_key_for_credentials(user, password)
  response = request(:get, '/api/user/api_key', {
    :email => user,
    :password => password,
  })

  # For backwards compatibility, this method must return a Hash, not a SuccessResponse.
  JSON.load(response.body)
end

#get_userHash

Returns a hash with the user’s details.

Returns:

  • (Hash)

    a hash with the user’s details



18
19
20
21
22
23
# File 'lib/turbot/api.rb', line 18

def get_user
  response = request(:get, '/api/user')

  # For backwards compatibility, this method must return a Hash, not a SuccessResponse.
  JSON.load(response.body)
end

#list_botsTurbot::API::SuccessResponse, Turbot::API::FailureResponse



42
43
44
# File 'lib/turbot/api.rb', line 42

def list_bots
  request(:get, '/api/bots')
end

#show_bot(bot_id) ⇒ Turbot::API::SuccessResponse, Turbot::API::FailureResponse



47
48
49
# File 'lib/turbot/api.rb', line 47

def show_bot(bot_id)
  request(:get, "/api/bots/#{bot_id}")
end

#show_manifest(bot_id) ⇒ Turbot::API::SuccessResponse, Turbot::API::FailureResponse



62
63
64
# File 'lib/turbot/api.rb', line 62

def show_manifest(bot_id)
  request(:get, "/api/bots/#{bot_id}/manifest")
end

#start_run(bot_id) ⇒ Turbot::API::SuccessResponse, Turbot::API::FailureResponse



82
83
84
# File 'lib/turbot/api.rb', line 82

def start_run(bot_id)
  request(:post, "/api/bots/#{bot_id}/run/start")
end

#stop_run(bot_id) ⇒ Turbot::API::SuccessResponse, Turbot::API::FailureResponse



87
88
89
# File 'lib/turbot/api.rb', line 87

def stop_run(bot_id)
  request(:post, "/api/bots/#{bot_id}/run/stop")
end

#update_bot(bot_id, config, env = nil) ⇒ Turbot::API::SuccessResponse, Turbot::API::FailureResponse



57
58
59
# File 'lib/turbot/api.rb', line 57

def update_bot(bot_id, config, env = nil)
  request(:put, "/api/bots/#{bot_id}", :bot => {:config => config, :env => env})
end

#update_code(bot_id, archive) ⇒ Turbot::API::SuccessResponse, Turbot::API::FailureResponse



77
78
79
# File 'lib/turbot/api.rb', line 77

def update_code(bot_id, archive)
  request(:put, "/api/bots/#{bot_id}/code", {:archive => archive}, false)
end