Class: IronWorkerNG::APIClient
- Inherits:
-
IronCore::Client
- Object
- IronCore::Client
- IronWorkerNG::APIClient
- Defined in:
- lib/iron_worker_ng/api_client.rb
Constant Summary collapse
- AWS_US_EAST_HOST =
'worker-aws-us-east-1.iron.io'
Instance Method Summary collapse
- #base_url ⇒ Object
- #clusters_create(options = {}) ⇒ Object
- #clusters_credentials(cluster_id) ⇒ Object
- #clusters_delete(cluster_id) ⇒ Object
- #clusters_get(cluster_id) ⇒ Object
- #clusters_list(options = {}) ⇒ Object
- #clusters_share(cluster_id, options = {}) ⇒ Object
- #clusters_unshare(cluster_id, user_id) ⇒ Object
- #clusters_update(cluster_id, options = {}) ⇒ Object
- #codes_create(name, file, runtime, runner, options) ⇒ Object
- #codes_delete(id) ⇒ Object
- #codes_download(id, options = {}) ⇒ Object
- #codes_get(id) ⇒ Object
- #codes_list(options = {}) ⇒ Object
- #codes_pause_task_queue(id, options = {}) ⇒ Object
- #codes_resume_task_queue(id, options = {}) ⇒ Object
- #codes_revisions(id, options = {}) ⇒ Object
- #headers ⇒ Object
-
#initialize(options = {}) ⇒ APIClient
constructor
A new instance of APIClient.
- #projects_get ⇒ Object
- #schedules_cancel(id, options = {}) ⇒ Object
- #schedules_create(code_name, payload, options = {}) ⇒ Object
- #schedules_get(id) ⇒ Object
- #schedules_list(options = {}) ⇒ Object
- #schedules_update(id, options = {}) ⇒ Object
- #stacks_list ⇒ Object
- #tasks_cancel(id) ⇒ Object
- #tasks_cancel_all(id) ⇒ Object
- #tasks_create(code_name, payload, options = {}) ⇒ Object
- #tasks_get(id) ⇒ Object
- #tasks_list(options = {}) ⇒ Object
- #tasks_log(id) ⇒ Object
- #tasks_retry(id, options = {}) ⇒ Object
- #tasks_set_progress(id, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ APIClient
Returns a new instance of APIClient.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/iron_worker_ng/api_client.rb', line 9 def initialize( = {}) = { :scheme => 'https', :host => IronWorkerNG::APIClient::AWS_US_EAST_HOST, :port => 443, :api_version => 2, :user_agent => IronWorkerNG.full_version } super('iron', 'worker', , , [:project_id, :token, :jwt, :api_version]) #puts "nhp.proxy yo #{rest.wrapper.http.proxy_uri}" if defined? Net::HTTP::Persistent #puts "RestClient.proxy yo #{RestClient.proxy}" if defined? RestClient #puts "InternalClient.proxy yo #{Rest::InternalClient.proxy}" if defined? Rest::InternalClient IronCore::Logger.error 'IronWorkerNG', "Token is not set", IronCore::Error if @token.nil? && @jwt.nil? check_id(@project_id, 'project_id') end |
Instance Method Details
#base_url ⇒ Object
37 38 39 |
# File 'lib/iron_worker_ng/api_client.rb', line 37 def base_url super + @api_version.to_s + '/' end |
#clusters_create(options = {}) ⇒ Object
171 172 173 |
# File 'lib/iron_worker_ng/api_client.rb', line 171 def clusters_create( = {}) parse_response(post("clusters", )) end |
#clusters_credentials(cluster_id) ⇒ Object
167 168 169 |
# File 'lib/iron_worker_ng/api_client.rb', line 167 def clusters_credentials(cluster_id) parse_response(get("clusters/#{cluster_id}/credentials")) end |
#clusters_delete(cluster_id) ⇒ Object
179 180 181 |
# File 'lib/iron_worker_ng/api_client.rb', line 179 def clusters_delete(cluster_id) parse_response(delete("clusters/#{cluster_id}")) end |
#clusters_get(cluster_id) ⇒ Object
163 164 165 |
# File 'lib/iron_worker_ng/api_client.rb', line 163 def clusters_get(cluster_id) parse_response(get("clusters/#{cluster_id}")) end |
#clusters_list(options = {}) ⇒ Object
159 160 161 |
# File 'lib/iron_worker_ng/api_client.rb', line 159 def clusters_list( = {}) parse_response(get("clusters", )) end |
#clusters_share(cluster_id, options = {}) ⇒ Object
183 184 185 |
# File 'lib/iron_worker_ng/api_client.rb', line 183 def clusters_share(cluster_id, = {}) parse_response(post("clusters/#{cluster_id}/share", )) end |
#clusters_unshare(cluster_id, user_id) ⇒ Object
187 188 189 |
# File 'lib/iron_worker_ng/api_client.rb', line 187 def clusters_unshare(cluster_id, user_id) parse_response(post("clusters/#{cluster_id}/unshare/#{user_id}")) end |
#clusters_update(cluster_id, options = {}) ⇒ Object
175 176 177 |
# File 'lib/iron_worker_ng/api_client.rb', line 175 def clusters_update(cluster_id, = {}) parse_response(put("clusters/#{cluster_id}", )) end |
#codes_create(name, file, runtime, runner, options) ⇒ Object
54 55 56 57 58 |
# File 'lib/iron_worker_ng/api_client.rb', line 54 def codes_create(name, file, runtime, runner, ) file_instance = file.to_s.strip == '' ? '' : File.new(file, 'rb') = {:name => name, :runtime => runtime, :file_name => runner}.merge() parse_response(post_file("projects/#{@project_id}/codes", :file, file_instance, :data, )) end |
#codes_delete(id) ⇒ Object
60 61 62 63 |
# File 'lib/iron_worker_ng/api_client.rb', line 60 def codes_delete(id) check_id(id) parse_response(delete("projects/#{@project_id}/codes/#{id}")) end |
#codes_download(id, options = {}) ⇒ Object
70 71 72 73 |
# File 'lib/iron_worker_ng/api_client.rb', line 70 def codes_download(id, = {}) check_id(id) parse_response(get("projects/#{@project_id}/codes/#{id}/download", ), false) end |
#codes_get(id) ⇒ Object
49 50 51 52 |
# File 'lib/iron_worker_ng/api_client.rb', line 49 def codes_get(id) check_id(id) parse_response(get("projects/#{@project_id}/codes/#{id}")) end |
#codes_list(options = {}) ⇒ Object
45 46 47 |
# File 'lib/iron_worker_ng/api_client.rb', line 45 def codes_list( = {}) parse_response(get("projects/#{@project_id}/codes", )) end |
#codes_pause_task_queue(id, options = {}) ⇒ Object
75 76 77 78 |
# File 'lib/iron_worker_ng/api_client.rb', line 75 def codes_pause_task_queue(id, = {}) check_id(id) parse_response(post("projects/#{@project_id}/codes/#{id}/pause_task_queue", )) end |
#codes_resume_task_queue(id, options = {}) ⇒ Object
80 81 82 83 |
# File 'lib/iron_worker_ng/api_client.rb', line 80 def codes_resume_task_queue(id, = {}) check_id(id) parse_response(post("projects/#{@project_id}/codes/#{id}/resume_task_queue", )) end |
#codes_revisions(id, options = {}) ⇒ Object
65 66 67 68 |
# File 'lib/iron_worker_ng/api_client.rb', line 65 def codes_revisions(id, = {}) check_id(id) parse_response(get("projects/#{@project_id}/codes/#{id}/revisions", )) end |
#headers ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/iron_worker_ng/api_client.rb', line 29 def headers if !@jwt.nil? super.merge({'Authorization' => "JWT #{@jwt}"}) else super.merge({'Authorization' => "OAuth #{@token}"}) end end |
#projects_get ⇒ Object
155 156 157 |
# File 'lib/iron_worker_ng/api_client.rb', line 155 def projects_get parse_response(get("projects/#{@project_id}")) end |
#schedules_cancel(id, options = {}) ⇒ Object
150 151 152 153 |
# File 'lib/iron_worker_ng/api_client.rb', line 150 def schedules_cancel(id, = {}) check_id(id) parse_response(post("projects/#{@project_id}/schedules/#{id}/cancel", )) end |
#schedules_create(code_name, payload, options = {}) ⇒ Object
138 139 140 141 142 143 |
# File 'lib/iron_worker_ng/api_client.rb', line 138 def schedules_create(code_name, payload, = {}) [:start_at] = [:start_at].iso8601 if (not [:start_at].nil?) && [:start_at].respond_to?(:iso8601) [:end_at] = [:end_at].iso8601 if (not [:end_at].nil?) && [:end_at].respond_to?(:iso8601) parse_response(post("projects/#{@project_id}/schedules", {:schedules => [{:code_name => code_name, :payload => payload}.merge()]})) end |
#schedules_get(id) ⇒ Object
133 134 135 136 |
# File 'lib/iron_worker_ng/api_client.rb', line 133 def schedules_get(id) check_id(id) parse_response(get("projects/#{@project_id}/schedules/#{id}")) end |
#schedules_list(options = {}) ⇒ Object
129 130 131 |
# File 'lib/iron_worker_ng/api_client.rb', line 129 def schedules_list( = {}) parse_response(get("projects/#{@project_id}/schedules", )) end |
#schedules_update(id, options = {}) ⇒ Object
145 146 147 148 |
# File 'lib/iron_worker_ng/api_client.rb', line 145 def schedules_update(id, = {}) check_id(id) parse_response(put("projects/#{@project_id}/schedules/#{id}", )) end |
#stacks_list ⇒ Object
41 42 43 |
# File 'lib/iron_worker_ng/api_client.rb', line 41 def stacks_list parse_response(get("stacks")) end |
#tasks_cancel(id) ⇒ Object
98 99 100 101 |
# File 'lib/iron_worker_ng/api_client.rb', line 98 def tasks_cancel(id) check_id(id) parse_response(post("projects/#{@project_id}/tasks/#{id}/cancel")) end |
#tasks_cancel_all(id) ⇒ Object
103 104 105 106 |
# File 'lib/iron_worker_ng/api_client.rb', line 103 def tasks_cancel_all(id) check_id(id) parse_response(post("projects/#{@project_id}/codes/#{id}/cancel_all")) end |
#tasks_create(code_name, payload, options = {}) ⇒ Object
94 95 96 |
# File 'lib/iron_worker_ng/api_client.rb', line 94 def tasks_create(code_name, payload, = {}) parse_response(post("projects/#{@project_id}/tasks", {:tasks => [{:code_name => code_name, :payload => payload}.merge()]})) end |
#tasks_get(id) ⇒ Object
89 90 91 92 |
# File 'lib/iron_worker_ng/api_client.rb', line 89 def tasks_get(id) check_id(id) parse_response(get("projects/#{@project_id}/tasks/#{id}")) end |
#tasks_list(options = {}) ⇒ Object
85 86 87 |
# File 'lib/iron_worker_ng/api_client.rb', line 85 def tasks_list( = {}) parse_response(get("projects/#{@project_id}/tasks", )) end |
#tasks_log(id) ⇒ Object
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/iron_worker_ng/api_client.rb', line 108 def tasks_log(id) check_id(id) if block_given? stream_get("projects/#{@project_id}/tasks/#{id}/log") do |chunk| yield chunk end else parse_response(get("projects/#{@project_id}/tasks/#{id}/log"), false) end end |
#tasks_retry(id, options = {}) ⇒ Object
124 125 126 127 |
# File 'lib/iron_worker_ng/api_client.rb', line 124 def tasks_retry(id, = {}) check_id(id) parse_response(post("projects/#{@project_id}/tasks/#{id}/retry", )) end |
#tasks_set_progress(id, options = {}) ⇒ Object
119 120 121 122 |
# File 'lib/iron_worker_ng/api_client.rb', line 119 def tasks_set_progress(id, = {}) check_id(id) parse_response(post("projects/#{@project_id}/tasks/#{id}/progress", )) end |