Class: CodePicnic::Console

Inherits:
Object
  • Object
show all
Includes:
APIRequest
Defined in:
lib/codepicnic/console.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIRequest

#get, included, #post, #url_to

Constructor Details

#initialize(opts = {}) ⇒ Console

Returns a new instance of Console.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/codepicnic/console.rb', line 8

def initialize(opts={})
  @id               = opts.delete("id")             || opts.delete(:id)
  @name             = opts.delete("name")           || opts.delete(:name)
  @container_name   = opts.delete("container_name") || opts.delete(:container_name)
  @container_type   = opts.delete("container_type") || opts.delete(:container_type)
  @custom_image     = opts.delete("custom_image")   || opts.delete(:custom_image)
  @created_at       = opts.delete("created_at")     || opts.delete(:created_at)
  @container_size   = opts.delete("container_size") || opts.delete(:container_size)
  @title            = @name || opts.delete("title") || opts.delete(:title)
  @hostname         = opts.delete("hostname")       || opts.delete(:hostname)
end

Class Attribute Details

.api_urlObject

Returns the value of attribute api_url.



67
68
69
# File 'lib/codepicnic/console.rb', line 67

def api_url
  @api_url
end

Instance Attribute Details

#container_nameObject

Returns the value of attribute container_name.



6
7
8
# File 'lib/codepicnic/console.rb', line 6

def container_name
  @container_name
end

#container_typeObject

Returns the value of attribute container_type.



6
7
8
# File 'lib/codepicnic/console.rb', line 6

def container_type
  @container_type
end

#created_atObject

Returns the value of attribute created_at.



6
7
8
# File 'lib/codepicnic/console.rb', line 6

def created_at
  @created_at
end

#custom_imageObject

Returns the value of attribute custom_image.



6
7
8
# File 'lib/codepicnic/console.rb', line 6

def custom_image
  @custom_image
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/codepicnic/console.rb', line 6

def id
  @id
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/codepicnic/console.rb', line 6

def name
  @name
end

Returns the value of attribute permalink.



6
7
8
# File 'lib/codepicnic/console.rb', line 6

def permalink
  @permalink
end

#urlObject

Returns the value of attribute url.



6
7
8
# File 'lib/codepicnic/console.rb', line 6

def url
  @url
end

Class Method Details

.allObject



69
70
71
# File 'lib/codepicnic/console.rb', line 69

def all
  get(url_to)["consoles"].map{|data| Console.new(data) }
end

.batch_exec(commands = [], container_names = []) ⇒ Object



73
74
75
# File 'lib/codepicnic/console.rb', line 73

def batch_exec(commands = [], container_names = [])
  post url_to(nil, "exec"), {commands: commands, container_names: container_names }
end

Instance Method Details

#exec(commands = []) ⇒ Object



53
54
55
# File 'lib/codepicnic/console.rb', line 53

def exec(commands = [])
  post url_to(@container_name, "exec"), {commands: commands}
end

#file_content(path = "") ⇒ Object



49
50
51
# File 'lib/codepicnic/console.rb', line 49

def file_content(path = "")
  get url_to(@container_name, path)
end

#filesObject



45
46
47
# File 'lib/codepicnic/console.rb', line 45

def files
  get url_to(@container_name, "files")
end

#forksObject



41
42
43
# File 'lib/codepicnic/console.rb', line 41

def forks
  get url_to(@container_name, "forks")
end

#restartObject



37
38
39
# File 'lib/codepicnic/console.rb', line 37

def restart
  post url_to(@container_name, "restart")
end

#saveObject



20
21
22
23
24
25
# File 'lib/codepicnic/console.rb', line 20

def save
  response = post(url_to, {console: cleaned_params})
  self.container_name = response["container_name"]
  self.url = response["url"]
  response
end

#startObject



27
28
29
30
31
# File 'lib/codepicnic/console.rb', line 27

def start
  result  = post(url_to(@container_name, "start"))
  @url    = result["url"]
  result
end

#stopObject



33
34
35
# File 'lib/codepicnic/console.rb', line 33

def stop
  post url_to(@container_name, "stop")
end