Class: IronWorkerNG::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/iron_worker_ng/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ Client

Returns a new instance of Client.



27
28
29
30
31
32
33
# File 'lib/iron_worker_ng/client.rb', line 27

def initialize(options = {}, &block)
  @api = IronWorkerNG::APIClient.new(options)

  unless block.nil?
    instance_eval(&block)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/iron_worker_ng/client.rb', line 43

def method_missing(name, *args, &block)
  if args.length == 0
    IronWorkerNG::ClientProxyCaller.new(self, name)
  else
    super
  end
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



25
26
27
# File 'lib/iron_worker_ng/client.rb', line 25

def api
  @api
end

Instance Method Details

#codes_create(code, options = {}) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/iron_worker_ng/client.rb', line 59

def codes_create(code, options = {})
  zip_file = code.create_zip

  if code.remote_build_command.nil?
    res = @api.codes_create(code.name, zip_file, 'sh', '__runner__.sh', options)
  else
    builder_code_name = code.name + 'Builder'

    @api.codes_create(builder_code_name, zip_file, 'sh', '__runner__.sh', options)

    builder_task_id = tasks.create(builder_code_name, :iron_token => token, :iron_project_id => project_id, :code_name => code.name, :codes_create_options => options.to_json).id
    task = tasks.wait_for(builder_task_id)

    if task.status != 'complete'
      raise IronCore::IronError.new("Error while remote building: \"#{tasks.log(task.id)}\"")
    end

    res = JSON.parse(task.msg)
  end

  File.unlink(zip_file)

  OpenStruct.new(res)
end

#codes_delete(code_id) ⇒ Object



84
85
86
87
88
# File 'lib/iron_worker_ng/client.rb', line 84

def codes_delete(code_id)
  @api.codes_delete(code_id)

  true
end

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



94
95
96
# File 'lib/iron_worker_ng/client.rb', line 94

def codes_download(code_id, options = {})
  @api.codes_download(code_id, options)
end

#codes_get(code_id) ⇒ Object



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

def codes_get(code_id)
  OpenStruct.new(@api.codes_get(code_id))
end

#codes_list(options = {}) ⇒ Object



51
52
53
# File 'lib/iron_worker_ng/client.rb', line 51

def codes_list(options = {})
  @api.codes_list(options)['codes'].map { |c| OpenStruct.new(c) }
end

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



90
91
92
# File 'lib/iron_worker_ng/client.rb', line 90

def codes_revisions(code_id, options = {})
  @api.codes_revisions(code_id, options)['revisions'].map { |c| OpenStruct.new(c) }
end

#project_idObject



39
40
41
# File 'lib/iron_worker_ng/client.rb', line 39

def project_id
  @api.project_id
end

#schedules_cancel(schedule_id) ⇒ Object



174
175
176
177
178
# File 'lib/iron_worker_ng/client.rb', line 174

def schedules_cancel(schedule_id)
  @api.schedules_cancel(schedule_id)

  true
end

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



162
163
164
165
166
# File 'lib/iron_worker_ng/client.rb', line 162

def schedules_create(code_name, params = {}, options = {})
  res = @api.schedules_create(code_name, params.class == String ? params : params.to_json, options)

  OpenStruct.new(res['schedules'][0])
end

#schedules_create_legacy(code_name, params = {}, options = {}) ⇒ Object



168
169
170
171
172
# File 'lib/iron_worker_ng/client.rb', line 168

def schedules_create_legacy(code_name, params = {}, options = {})
  res = @api.schedules_create(code_name, params_for_legacy(code_name, params), options)

  OpenStruct.new(res['schedules'][0])
end

#schedules_get(schedule_id) ⇒ Object



158
159
160
# File 'lib/iron_worker_ng/client.rb', line 158

def schedules_get(schedule_id)
  OpenStruct.new(@api.schedules_get(schedule_id))
end

#schedules_list(options = {}) ⇒ Object



154
155
156
# File 'lib/iron_worker_ng/client.rb', line 154

def schedules_list(options = {})
  @api.schedules_list(options)['schedules'].map { |s| OpenStruct.new(s) }
end

#tasks_cancel(task_id) ⇒ Object



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

def tasks_cancel(task_id)
  @api.tasks_cancel(task_id)

  true
end

#tasks_cancel_all(code_id) ⇒ Object



124
125
126
127
128
# File 'lib/iron_worker_ng/client.rb', line 124

def tasks_cancel_all(code_id)
  @api.tasks_cancel_all(code_id)

  true
end

#tasks_create(code_name, params = {}, options = {}) ⇒ Object



106
107
108
109
110
# File 'lib/iron_worker_ng/client.rb', line 106

def tasks_create(code_name, params = {}, options = {})
  res = @api.tasks_create(code_name, params.class == String ? params : params.to_json, options)

  OpenStruct.new(res['tasks'][0])
end

#tasks_create_legacy(code_name, params = {}, options = {}) ⇒ Object



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

def tasks_create_legacy(code_name, params = {}, options = {})
  res = @api.tasks_create(code_name, params_for_legacy(code_name, params), options)

  OpenStruct.new(res['tasks'][0])
end

#tasks_get(task_id) ⇒ Object



102
103
104
# File 'lib/iron_worker_ng/client.rb', line 102

def tasks_get(task_id)
  OpenStruct.new(@api.tasks_get(task_id))
end

#tasks_list(options = {}) ⇒ Object



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

def tasks_list(options = {})
  @api.tasks_list(options)['tasks'].map { |t| OpenStruct.new(t) }
end

#tasks_log(task_id) ⇒ Object



130
131
132
# File 'lib/iron_worker_ng/client.rb', line 130

def tasks_log(task_id)
  @api.tasks_log(task_id)
end

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



134
135
136
137
138
# File 'lib/iron_worker_ng/client.rb', line 134

def tasks_set_progress(task_id, options = {})
  @api.tasks_set_progress(task_id, options)

  true
end

#tasks_wait_for(task_id, options = {}) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/iron_worker_ng/client.rb', line 140

def tasks_wait_for(task_id, options = {})
  options[:sleep] ||= options['sleep'] || 5

  task = tasks_get(task_id)

  while task.status == 'queued' || task.status == 'running'
    yield task if block_given?
    sleep options[:sleep]
    task = tasks_get(task_id)
  end

  task
end

#tokenObject



35
36
37
# File 'lib/iron_worker_ng/client.rb', line 35

def token
  @api.token
end