Class: Zillabyte::API::Components

Inherits:
Flows
  • Object
show all
Defined in:
lib/zillabyte/api/components.rb

Instance Method Summary collapse

Methods inherited from Flows

#create_delete, #create_kill, #delete, get_rich_meta_info_from_script, #poll_delete, #poll_kill, #pull_to_directory

Methods inherited from Base

#initialize, #request

Constructor Details

This class inherits a constructor from Zillabyte::API::Base

Instance Method Details

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

GET /components/id



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/zillabyte/api/components.rb', line 53

def get(id, options = {})

  options = {
    # TODO
  }.merge(options)
  
  res = @api.request(
    :expects  => 200,
    :method   => :get,
    :path     => "/components/#{id}",
    :body     => options.to_json 
  )
  
  res.body

end

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

GET /components/id/execute



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/zillabyte/api/components.rb', line 85

def get_rpc_results(id, options = {})

  res = @api.request(
    :expects  => 200,
    :method   => :get,
    :path     => "/components/#{id}/execute",
    :body     => options.to_json
  )

  res.body
end

#list(options = {}) ⇒ Object

GET /apps



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/zillabyte/api/components.rb', line 9

def list(options = {})

  options = {
    # TODO
  }.merge(options)
  
  res = @api.request(
    :expects  => 200,
    :method   => :get,
    :path     => "/components",
    :body     => options.to_json
  )

  body = res.body
  body.map do |component|
    next if component["schema"].nil?

    inputs = ""
    outputs = ""

    nodes = component["schema"]["nodes"]
    nodes.each do |node|
      if node["type"] == "source"
        inputs += "#{node["name"]}:\n"
        node["fields"].each do |field|
          inputs += "  (#{field.keys[0]}, #{field.values[0].upcase})\n"
        end
      elsif node["type"] == "sink"
        outputs += "#{node["name"]}:\n"
        node["columns"].each do |field|
          outputs += "  (#{field.keys[0]}, #{field.values[0].upcase})\n"
        end
      end
    end

    component["inputs"] = inputs
    component["outputs"] = outputs
  end

  body

end

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

POST /components/id/execute



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/zillabyte/api/components.rb', line 72

def rpc(id, options = {})

  res = @api.request(
    :expects  => 200,
    :method   => :post,
    :path     => "/components/#{id}/execute",
    :body     => options.to_json
  )

  res.body
end