Class: Turbot::API
- Inherits:
-
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
-
#create_bot(bot_id, config, env = nil) ⇒ Turbot::API::SuccessResponse, Turbot::API::FailureResponse
-
#create_draft_data(bot_id, batch) ⇒ Turbot::API::SuccessResponse, Turbot::API::FailureResponse
-
#destroy_draft_data(bot_id) ⇒ Turbot::API::SuccessResponse, Turbot::API::FailureResponse
-
#get_api_key ⇒ String
-
#get_api_key_for_credentials(user, password) ⇒ Hash
A hash with a single key “api_key”.
-
#get_user ⇒ Hash
A hash with the user’s details.
-
#initialize(params) ⇒ API
constructor
-
#list_bots ⇒ Turbot::API::SuccessResponse, Turbot::API::FailureResponse
-
#show_bot(bot_id) ⇒ Turbot::API::SuccessResponse, Turbot::API::FailureResponse
-
#show_manifest(bot_id) ⇒ Turbot::API::SuccessResponse, Turbot::API::FailureResponse
-
#start_run(bot_id) ⇒ Turbot::API::SuccessResponse, Turbot::API::FailureResponse
-
#stop_run(bot_id) ⇒ Turbot::API::SuccessResponse, Turbot::API::FailureResponse
-
#update_bot(bot_id, config, env = nil) ⇒ Turbot::API::SuccessResponse, Turbot::API::FailureResponse
-
#update_code(bot_id, archive) ⇒ Turbot::API::SuccessResponse, Turbot::API::FailureResponse
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
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
|
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
|
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_key ⇒ String
Returns 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”.
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,
})
JSON.load(response.body)
end
|
#get_user ⇒ Hash
Returns 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')
JSON.load(response.body)
end
|
42
43
44
|
# File 'lib/turbot/api.rb', line 42
def list_bots
request(:get, '/api/bots')
end
|
47
48
49
|
# File 'lib/turbot/api.rb', line 47
def show_bot(bot_id)
request(:get, "/api/bots/#{bot_id}")
end
|
62
63
64
|
# File 'lib/turbot/api.rb', line 62
def show_manifest(bot_id)
request(:get, "/api/bots/#{bot_id}/manifest")
end
|
82
83
84
|
# File 'lib/turbot/api.rb', line 82
def start_run(bot_id)
request(:post, "/api/bots/#{bot_id}/run/start")
end
|
87
88
89
|
# File 'lib/turbot/api.rb', line 87
def stop_run(bot_id)
request(:post, "/api/bots/#{bot_id}/run/stop")
end
|
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
|
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
|