Class: IronWorkerNG::APIClient

Inherits:
IronCore::Client
  • Object
show all
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

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(options = {})
  default_options = {
    :scheme => 'https',
    :host => IronWorkerNG::APIClient::AWS_US_EAST_HOST,
    :port => 443,
    :api_version => 2,
    :user_agent => IronWorkerNG.full_version
  }

  super('iron', 'worker', options, default_options, [:project_id, :token, :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?

  check_id(@project_id, 'project_id')
end

Instance Method Details

#base_urlObject



33
34
35
# File 'lib/iron_worker_ng/api_client.rb', line 33

def base_url
  super + @api_version.to_s + '/'
end

#codes_create(name, file, runtime, runner, options) ⇒ Object



50
51
52
# File 'lib/iron_worker_ng/api_client.rb', line 50

def codes_create(name, file, runtime, runner, options)
  parse_response(post_file("projects/#{@project_id}/codes", :file, File.new(file, 'rb'), :data, {:name => name, :runtime => runtime, :file_name => runner}.merge(options)))
end

#codes_delete(id) ⇒ Object



54
55
56
57
# File 'lib/iron_worker_ng/api_client.rb', line 54

def codes_delete(id)
  check_id(id)
  parse_response(delete("projects/#{@project_id}/codes/#{id}"))
end

#codes_download(id, options = {}) ⇒ Object



64
65
66
67
# File 'lib/iron_worker_ng/api_client.rb', line 64

def codes_download(id, options = {})
  check_id(id)
  parse_response(get("projects/#{@project_id}/codes/#{id}/download", options), false)
end

#codes_get(id) ⇒ Object



45
46
47
48
# File 'lib/iron_worker_ng/api_client.rb', line 45

def codes_get(id)
  check_id(id)
  parse_response(get("projects/#{@project_id}/codes/#{id}"))
end

#codes_list(options = {}) ⇒ Object



41
42
43
# File 'lib/iron_worker_ng/api_client.rb', line 41

def codes_list(options = {})
  parse_response(get("projects/#{@project_id}/codes", options))
end

#codes_pause_task_queue(id, options = {}) ⇒ Object



69
70
71
72
# File 'lib/iron_worker_ng/api_client.rb', line 69

def codes_pause_task_queue(id, options = {})
  check_id(id)
  parse_response(post("projects/#{@project_id}/codes/#{id}/pause_task_queue", options))
end

#codes_resume_task_queue(id, options = {}) ⇒ Object



74
75
76
77
# File 'lib/iron_worker_ng/api_client.rb', line 74

def codes_resume_task_queue(id, options = {})
  check_id(id)
  parse_response(post("projects/#{@project_id}/codes/#{id}/resume_task_queue", options))
end

#codes_revisions(id, options = {}) ⇒ Object



59
60
61
62
# File 'lib/iron_worker_ng/api_client.rb', line 59

def codes_revisions(id, options = {})
  check_id(id)
  parse_response(get("projects/#{@project_id}/codes/#{id}/revisions", options))
end

#headersObject



29
30
31
# File 'lib/iron_worker_ng/api_client.rb', line 29

def headers
  super.merge({'Authorization' => "OAuth #{@token}"})
end

#projects_getObject



149
150
151
# File 'lib/iron_worker_ng/api_client.rb', line 149

def projects_get
  parse_response(get("projects/#{@project_id}"))
end

#schedules_cancel(id) ⇒ Object



144
145
146
147
# File 'lib/iron_worker_ng/api_client.rb', line 144

def schedules_cancel(id)
  check_id(id)
  parse_response(post("projects/#{@project_id}/schedules/#{id}/cancel"))
end

#schedules_create(code_name, payload, options = {}) ⇒ Object



132
133
134
135
136
137
# File 'lib/iron_worker_ng/api_client.rb', line 132

def schedules_create(code_name, payload, options = {})
  options[:start_at] = options[:start_at].iso8601 if (not options[:start_at].nil?) && options[:start_at].respond_to?(:iso8601)
  options[:end_at] = options[:end_at].iso8601 if (not options[:end_at].nil?) && options[:end_at].respond_to?(:iso8601)

  parse_response(post("projects/#{@project_id}/schedules", {:schedules => [{:code_name => code_name, :payload => payload}.merge(options)]}))
end

#schedules_get(id) ⇒ Object



127
128
129
130
# File 'lib/iron_worker_ng/api_client.rb', line 127

def schedules_get(id)
  check_id(id)
  parse_response(get("projects/#{@project_id}/schedules/#{id}"))
end

#schedules_list(options = {}) ⇒ Object



123
124
125
# File 'lib/iron_worker_ng/api_client.rb', line 123

def schedules_list(options = {})
  parse_response(get("projects/#{@project_id}/schedules", options))
end

#schedules_update(id, options = {}) ⇒ Object



139
140
141
142
# File 'lib/iron_worker_ng/api_client.rb', line 139

def schedules_update(id, options = {})
  check_id(id)
  parse_response(put("projects/#{@project_id}/schedules/#{id}", options))
end

#stacks_listObject



37
38
39
# File 'lib/iron_worker_ng/api_client.rb', line 37

def stacks_list
  parse_response(get("stacks"))
end

#tasks_cancel(id) ⇒ Object



92
93
94
95
# File 'lib/iron_worker_ng/api_client.rb', line 92

def tasks_cancel(id)
  check_id(id)
  parse_response(post("projects/#{@project_id}/tasks/#{id}/cancel"))
end

#tasks_cancel_all(id) ⇒ Object



97
98
99
100
# File 'lib/iron_worker_ng/api_client.rb', line 97

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



88
89
90
# File 'lib/iron_worker_ng/api_client.rb', line 88

def tasks_create(code_name, payload, options = {})
  parse_response(post("projects/#{@project_id}/tasks", {:tasks => [{:code_name => code_name, :payload => payload}.merge(options)]}))
end

#tasks_get(id) ⇒ Object



83
84
85
86
# File 'lib/iron_worker_ng/api_client.rb', line 83

def tasks_get(id)
  check_id(id)
  parse_response(get("projects/#{@project_id}/tasks/#{id}"))
end

#tasks_list(options = {}) ⇒ Object



79
80
81
# File 'lib/iron_worker_ng/api_client.rb', line 79

def tasks_list(options = {})
  parse_response(get("projects/#{@project_id}/tasks", options))
end

#tasks_log(id) ⇒ Object



102
103
104
105
106
107
108
109
110
111
# File 'lib/iron_worker_ng/api_client.rb', line 102

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



118
119
120
121
# File 'lib/iron_worker_ng/api_client.rb', line 118

def tasks_retry(id, options = {})
  check_id(id)
  parse_response(post("projects/#{@project_id}/tasks/#{id}/retry", options))
end

#tasks_set_progress(id, options = {}) ⇒ Object



113
114
115
116
# File 'lib/iron_worker_ng/api_client.rb', line 113

def tasks_set_progress(id, options = {})
  check_id(id)
  parse_response(post("projects/#{@project_id}/tasks/#{id}/progress", options))
end