turbot-api 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTZjMjQ2MWVlYjEwMGU4YmUyN2M0NWZmMDhmNTE3ZmYxOTEzYWU3NQ==
4
+ M2RmZWNmYTlkNTJlNzc1YTk3NzUzMGZlNDVmMzVlMzM0M2I3NWUyNw==
5
5
  data.tar.gz: !binary |-
6
- N2Q3NTc4NzQ1YzczYTc5ZGFlYjgxMWZhZjA5NGQyMWU5NjcwNWVhOA==
6
+ YzQyOTg0ZDQzZjY1OTNiMDBkYjI2ZWNiMDUyMDhlNGNmMzkyZmRkZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NWE0OTU4ZDAzNjQ1ODk2ZWRmODU5OTZjMmJjOTU4MjRmOGYxYzM0OTIzYWUz
10
- MzBmZWVlYzg4NjAxNGE1MjU5NmM3NDgyZDI1ODJkMjg4MjQ4YWM4YmVjNTZj
11
- YmUwNDNhMWQ3YzlmMTM0MWI5ZTA0ZGU5Mjc1ODc3OTE3ZmIwZTc=
9
+ OWVjYjE2Y2ViYmVkNmUwYWJhMzQ1YzE1MWJjMjYwMzM0MzMxMTBhMmIxMmE0
10
+ ODhmMjIyNjNkYmQxZTg1MGFiYzQ2ZWU4N2IzNWQyOTNjOWRiYmNjOWMwMmRj
11
+ ODBlM2NjMTQ4ZTE1M2ZlNmQ1ZjdiYzY3ZTk0YmRjZTE4N2ExZGI=
12
12
  data.tar.gz: !binary |-
13
- MmRlNTE4ODQ1YWZlMmYzMTk4YmE1MDZmMGQyY2MzOGJhOTExZWRiNWFhN2Qx
14
- NWVjMTJhNDdhNTE3YThiNDBkODI3MjlmOTI4NmEyNDUxMDg0M2JjN2E0MDA5
15
- MWM0YjVlZmZiN2E0YzIyMDcyY2IxNjY2NTM1MGI0ZGUyYTBjZmI=
13
+ NmM1NWVhNDJjNTllNTVhZWQ4NDIxZjg2NDFjNzVjMWIxNGI4M2E1YzEzODVm
14
+ ZWY2NDVjNjhhYjNjNTcxN2UzNDU2NDNjZjVhODI5Y2JlM2JlYTE1MDJlZGRl
15
+ NGM0OTU2YTU4YTJjZmQzNTMyZTVhYjA3NzNlMzYzODhiMDNhM2E=
@@ -1,3 +1,5 @@
1
+ require 'action_dispatch'
2
+ require 'debugger'
1
3
  require 'json'
2
4
  require 'rest_client'
3
5
 
@@ -12,10 +14,29 @@ module Turbot
12
14
  @scheme = params[:scheme]
13
15
  @ssl_verify_peer = params[:ssl_verify_peer]
14
16
  @api_key = params[:api_key] || get_api_key_for_credentials(@username, @password)["api_key"]
17
+
18
+ @routes = ActionDispatch::Routing::RouteSet.new
19
+
20
+ @routes.draw do
21
+ namespace :api do
22
+ resources :bots, :only => [:index, :create] do
23
+ resource :code, :only => [:update], :controller => 'code'
24
+ resource :draft_data, :only => [:update]
25
+ end
26
+
27
+ resource :user, :only => [:show] do
28
+ resource :api_key, :only => [:show]
29
+ end
30
+ end
31
+ end
32
+
33
+ @routes.default_url_options[:host] = @host
34
+ @routes.default_url_options[:port] = @port
15
35
  end
16
36
 
17
37
  def get_user
18
- response = RestClient.get(server_req("/users/get_user"))
38
+ # TODO move away from using RestClient directly
39
+ response = RestClient.get(server_req("/api/user"))
19
40
  JSON.parse(response)
20
41
  end
21
42
 
@@ -24,85 +45,39 @@ module Turbot
24
45
  end
25
46
 
26
47
  def get_api_key_for_credentials(user, password)
27
- url = server_req("/users/api_key",
48
+ # TODO move away from using RestClient directly
49
+ url = server_req("/api/user/api_key",
28
50
  :email => user,
29
51
  :password => password)
30
52
  response = RestClient.get(url)
31
53
  JSON.parse(response)
32
54
  end
33
55
 
34
- def get_keys
35
- # return an array of ssh keys
36
- ["jkjk"]
37
- end
38
-
39
- def get_ssh_keys
40
- # return an array of ssh keys
41
- ["jkjk"]
42
- end
43
-
44
- def post_key(key)
45
- # receive ssh key and associate with account
56
+ def list_bots
57
+ request(:get, :bots)
46
58
  end
47
59
 
48
- def delete_key(key)
60
+ def show_bot(bot_id)
61
+ request(:get, :bot, :bot_id => bot_id)
49
62
  end
50
63
 
51
- def delete_keys
64
+ def create_bot(bot_id, config)
65
+ request(:post, :bots, :bot => {:bot_id => bot_id, :config => config})
52
66
  end
53
67
 
54
- def read_logs(bot, opts={})
55
- url = server_req("/users/read_logs", :bot => bot)
56
- JSON.parse(RestClient.get(url))
68
+ def update_draft_data(bot_id, config, batch)
69
+ request(:put, :bot_draft_data, :bot_id => bot_id, :config => config, :batch => batch)
57
70
  end
58
71
 
59
- def post_bot(data)
60
- url = server_req("/users/post_bot")
61
- begin
62
- RestClient.post(url, data)
63
- rescue => e
64
- if e.response.match(/Gitlab::Error::NotFound/)
65
- puts "That bot already exists!"
66
- exit 0
67
- elsif e.response.match(/MissingManifest/)
68
- puts "ERROR: You didn't provide a manifest.json"
69
- exit 1
70
- else
71
- raise
72
- end
73
- end
74
- puts "Created bot #{data['bot_id']}"
75
- end
76
-
77
- def delete_bot(bot)
78
- RestClient.delete(server_req("/users/delete_bot", {:bot => bot}))
72
+ def update_code(bot_id, archive)
73
+ request(:put, :bot_code, :bot_id => bot_id, :archive => archive)
79
74
  end
80
75
 
81
- def get_bots
82
- JSON.parse(RestClient.get(server_req("/users/get_bots")).body)
83
- end
84
-
85
- def get_bot(bot)
86
- JSON.parse(RestClient.get(server_req("/users/get_bot", :bot => bot)).body)
87
- end
88
-
89
- def put_config_vars(bot, vars)
90
- JSON.parse(RestClient.post(server_req("/users/config_vars", :bot => bot, :vars => vars)).body)
91
- end
92
-
93
- def get_config_vars(bot)
94
- JSON.parse(RestClient.get(server_req("/users/config_vars", :bot => bot)).body)
95
- end
96
-
97
- def delete_config_var(bot, key)
98
- JSON.parse(RestClient.delete(server_req("/users/config_vars", :bot => bot, :key => key)).body)
76
+ def get_ssh_keys
77
+ []
99
78
  end
100
79
 
101
- def send_drafts_to_angler(bot, batch)
102
- RestClient.post(
103
- server_req("/users/send_drafts_to_angler"),
104
- {:bot => bot,
105
- :batch => batch}).body
80
+ def post_key(key)
106
81
  end
107
82
 
108
83
  private
@@ -120,5 +95,27 @@ module Turbot
120
95
  args[:query] = query_string unless query_string.empty?
121
96
  URI::HTTP.build(args).to_s
122
97
  end
98
+
99
+ def request(method, named_route, params={})
100
+ begin
101
+ url = @routes.url_helpers.send("api_#{named_route}_url")
102
+ rescue ActionController::UrlGenerationError
103
+ url = @routes.url_helpers.send("api_#{named_route}_url", :bot_id => params[:bot_id])
104
+ end
105
+
106
+ if method == :get
107
+ response = RestClient.send(method, url, :params => params.merge(:api_key => @api_key))
108
+ else
109
+ response = RestClient.send(method, url, params.merge(:api_key => @api_key))
110
+ end
111
+
112
+ # TODO work out what to do here - wrap response in APIResponse?
113
+ debugger
114
+ if response.body.blank?
115
+ {}
116
+ else
117
+ JSON.parse(response.body)
118
+ end
119
+ end
123
120
  end
124
121
  end
@@ -1,3 +1,3 @@
1
1
  module Turbot
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbot-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Turbot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-27 00:00:00.000000000 Z
11
+ date: 2014-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: actionpack
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 4.0.3
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 4.0.3
41
55
  description: Client library to deploy apps on Turbot.
42
56
  email: support@opencorporates.com
43
57
  executables: []
@@ -74,3 +88,4 @@ signing_key:
74
88
  specification_version: 4
75
89
  summary: Client library to deploy apps on Turbot.
76
90
  test_files: []
91
+ has_rdoc: