Class: Turbot::API
- Inherits:
-
Object
show all
- Defined in:
- lib/turbot_api/api.rb,
lib/turbot_api/errors.rb
Defined Under Namespace
Modules: Errors
Classes: FailureResponse, SuccessResponse
Instance Method Summary
collapse
Constructor Details
#initialize(params) ⇒ API
Returns a new instance of API.
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/turbot_api/api.rb', line 7
def initialize(params)
@headers = params[:headers]
@host = params[:host]
@port = params[:port]
@username = params[:username]
@password = params[:password]
@scheme = params[:scheme]
@ssl_verify_peer = params[:ssl_verify_peer]
@api_key = params[:api_key] || get_api_key_for_credentials(@username, @password)["api_key"]
end
|
Instance Method Details
#create_bot(bot_id, config) ⇒ Object
45
46
47
|
# File 'lib/turbot_api/api.rb', line 45
def create_bot(bot_id, config)
request(:post, "/api/bots", :bot => {:bot_id => bot_id, :config => config})
end
|
#create_draft_data(bot_id, batch) ⇒ Object
53
54
55
|
# File 'lib/turbot_api/api.rb', line 53
def create_draft_data(bot_id, batch)
request(:post, "/api/bots/#{bot_id}/draft_data", :batch => batch)
end
|
#destroy_draft_data(bot_id) ⇒ Object
57
58
59
|
# File 'lib/turbot_api/api.rb', line 57
def destroy_draft_data(bot_id)
request(:delete, "/api/bots/#{bot_id}/draft_data")
end
|
#get_api_key ⇒ Object
24
25
26
|
# File 'lib/turbot_api/api.rb', line 24
def get_api_key
get_user["api_key"]
end
|
#get_api_key_for_credentials(user, password) ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/turbot_api/api.rb', line 28
def get_api_key_for_credentials(user, password)
url = server_req("/api/user/api_key",
:email => user,
:password => password)
response = RestClient.get(url)
JSON.parse(response)
end
|
#get_ssh_keys ⇒ Object
80
81
82
|
# File 'lib/turbot_api/api.rb', line 80
def get_ssh_keys
[]
end
|
#get_user ⇒ Object
18
19
20
21
22
|
# File 'lib/turbot_api/api.rb', line 18
def get_user
response = RestClient.get(server_req("/api/user"))
JSON.parse(response)
end
|
#list_bots ⇒ Object
37
38
39
|
# File 'lib/turbot_api/api.rb', line 37
def list_bots
request(:get, "/api/bots")
end
|
#post_key(key) ⇒ Object
84
85
|
# File 'lib/turbot_api/api.rb', line 84
def post_key(key)
end
|
#show_bot(bot_id) ⇒ Object
41
42
43
|
# File 'lib/turbot_api/api.rb', line 41
def show_bot(bot_id)
request(:get, "/api/bots/#{bot_id}")
end
|
#start_run(bot_id) ⇒ Object
72
73
74
|
# File 'lib/turbot_api/api.rb', line 72
def start_run(bot_id)
request(:post, "/api/bots/#{bot_id}/run/start")
end
|
#stop_run(bot_id) ⇒ Object
76
77
78
|
# File 'lib/turbot_api/api.rb', line 76
def stop_run(bot_id)
request(:post, "/api/bots/#{bot_id}/run/stop")
end
|
#update_bot(bot_id, config) ⇒ Object
49
50
51
|
# File 'lib/turbot_api/api.rb', line 49
def update_bot(bot_id, config)
request(:put, "/api/bots/#{bot_id}", :bot => {:config => config})
end
|
#update_code(bot_id, archive) ⇒ Object
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/turbot_api/api.rb', line 61
def update_code(bot_id, archive)
url = build_url("/api/bots/#{bot_id}/code")
begin
response = RestClient.put(url, :api_key => @api_key, :archive => archive)
SuccessResponse.new(response)
rescue RestClient::Exception => e
FailureResponse.new(e.response)
end
end
|