turbot-api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MTZjMjQ2MWVlYjEwMGU4YmUyN2M0NWZmMDhmNTE3ZmYxOTEzYWU3NQ==
5
+ data.tar.gz: !binary |-
6
+ N2Q3NTc4NzQ1YzczYTc5ZGFlYjgxMWZhZjA5NGQyMWU5NjcwNWVhOA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NWE0OTU4ZDAzNjQ1ODk2ZWRmODU5OTZjMmJjOTU4MjRmOGYxYzM0OTIzYWUz
10
+ MzBmZWVlYzg4NjAxNGE1MjU5NmM3NDgyZDI1ODJkMjg4MjQ4YWM4YmVjNTZj
11
+ YmUwNDNhMWQ3YzlmMTM0MWI5ZTA0ZGU5Mjc1ODc3OTE3ZmIwZTc=
12
+ data.tar.gz: !binary |-
13
+ MmRlNTE4ODQ1YWZlMmYzMTk4YmE1MDZmMGQyY2MzOGJhOTExZWRiNWFhN2Qx
14
+ NWVjMTJhNDdhNTE3YThiNDBkODI3MjlmOTI4NmEyNDUxMDg0M2JjN2E0MDA5
15
+ MWM0YjVlZmZiN2E0YzIyMDcyY2IxNjY2NTM1MGI0ZGUyYTBjZmI=
data/README.md ADDED
File without changes
@@ -0,0 +1,124 @@
1
+ require 'json'
2
+ require 'rest_client'
3
+
4
+ module Turbot
5
+ class API
6
+ def initialize(params)
7
+ @headers = params[:headers]
8
+ @host = params[:host]
9
+ @port = params[:port]
10
+ @username = params[:username]
11
+ @password = params[:password]
12
+ @scheme = params[:scheme]
13
+ @ssl_verify_peer = params[:ssl_verify_peer]
14
+ @api_key = params[:api_key] || get_api_key_for_credentials(@username, @password)["api_key"]
15
+ end
16
+
17
+ def get_user
18
+ response = RestClient.get(server_req("/users/get_user"))
19
+ JSON.parse(response)
20
+ end
21
+
22
+ def get_api_key
23
+ get_user["api_key"]
24
+ end
25
+
26
+ def get_api_key_for_credentials(user, password)
27
+ url = server_req("/users/api_key",
28
+ :email => user,
29
+ :password => password)
30
+ response = RestClient.get(url)
31
+ JSON.parse(response)
32
+ end
33
+
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
46
+ end
47
+
48
+ def delete_key(key)
49
+ end
50
+
51
+ def delete_keys
52
+ end
53
+
54
+ def read_logs(bot, opts={})
55
+ url = server_req("/users/read_logs", :bot => bot)
56
+ JSON.parse(RestClient.get(url))
57
+ end
58
+
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}))
79
+ end
80
+
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)
99
+ end
100
+
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
106
+ end
107
+
108
+ private
109
+
110
+ def server_req(path, params={})
111
+ query_string = params.update(:api_key => @api_key).map do |k, v|
112
+ "#{k}=#{v}" if v
113
+ end.compact.join("&")
114
+ args = {
115
+ :host => @host,
116
+ :port => @port,
117
+ :scheme => @scheme,
118
+ :path => path.strip
119
+ }
120
+ args[:query] = query_string unless query_string.empty?
121
+ URI::HTTP.build(args).to_s
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,28 @@
1
+ module Turbot
2
+ class API
3
+ module Errors
4
+ class Error < StandardError; end
5
+
6
+ class ErrorWithResponse < Error
7
+ attr_reader :response
8
+
9
+ def initialize(message, response=nil)
10
+ message = message << "\nbody: #{response.body.inspect}" if response
11
+ super message
12
+ @response = response
13
+ end
14
+ end
15
+
16
+ class Unauthorized < ErrorWithResponse; end
17
+ class VerificationRequired < ErrorWithResponse; end
18
+ class Forbidden < ErrorWithResponse; end
19
+ class NotFound < ErrorWithResponse; end
20
+ class Timeout < ErrorWithResponse; end
21
+ class Locked < ErrorWithResponse; end
22
+ class RateLimitExceeded < ErrorWithResponse; end
23
+ class RequestFailed < ErrorWithResponse; end
24
+ class NilApp < ErrorWithResponse; end
25
+ class MissingManifest < ErrorWithResponse; end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module Turbot
2
+ VERSION = "0.0.1"
3
+ end
data/lib/turbot_api.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'turbot_api/api'
2
+ require 'turbot_api/errors'
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: turbot-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Turbot
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubyzip
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Client library to deploy apps on Turbot.
42
+ email: support@opencorporates.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - README.md
48
+ - lib/turbot_api.rb
49
+ - lib/turbot_api/api.rb
50
+ - lib/turbot_api/errors.rb
51
+ - lib/turbot_api/version.rb
52
+ homepage: http://opencorporates.com/
53
+ licenses:
54
+ - MIT
55
+ metadata: {}
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 2.2.2
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: Client library to deploy apps on Turbot.
76
+ test_files: []