Module: Helium::Client::HeliumScripts

Included in:
Helium::Client
Defined in:
lib/helium/client/helium_scripts.rb

Instance Method Summary collapse

Instance Method Details

#create_library(name, file_content) ⇒ Object



20
21
22
23
# File 'lib/helium/client/helium_scripts.rb', line 20

def create_library(name, file_content)
  contents = Base64.strict_encode64(file_content)
  Library.create({ name: name , contents: contents }, client: self)
end

#create_package(script, libraries = [], name = nil) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/helium/client/helium_scripts.rb', line 41

def create_package(script, libraries = [], name = nil)
  library_rels = Array(libraries).map do |lib|
    { id: lib.id, type: 'library' }
  end
  body = {
    data: {
      attributes: {
        name: name
      },
      type: 'package',
      relationships: {
        script: {
          data: {
            id: script.id,
            type: 'script'
          }
        },
        library: {
          data: library_rels
        }
      }
    }
  }

  response = post('/package', body: body)
  resource_data = JSON.parse(response.body)["data"]
  Package.new(client: self, params: resource_data)
end

#create_script(name, file_content) ⇒ Object



7
8
9
10
# File 'lib/helium/client/helium_scripts.rb', line 7

def create_script(name, file_content)
  contents = Base64.strict_encode64(file_content)
  Script.create({ name: name , contents: contents }, client: self)
end

#create_sensor_package(sensor, package) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/helium/client/helium_scripts.rb', line 78

def create_sensor_package(sensor, package)
  body = {
    data: {
      type: 'sensor-package',
      relationships: {
        package: {
          data: {
            id: package.id,
            type: 'package'
          }
        },
        sensor: {
          data: {
            id: sensor.id,
            type: 'sensor'
          }
        }
      }
    }
  }

  response = post('/sensor-package', body: body)
  resource_data = JSON.parse(response.body)["data"]
  SensorPackage.new(client: self, params: resource_data)
end

#librariesObject



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

def libraries
  Library.all(client: self)
end

#library(id) ⇒ Object



29
30
31
# File 'lib/helium/client/helium_scripts.rb', line 29

def library(id)
  Library.find(id, client: self)
end

#package(id) ⇒ Object



37
38
39
# File 'lib/helium/client/helium_scripts.rb', line 37

def package(id)
  Package.find(id, client: self)
end

#packagesObject



33
34
35
# File 'lib/helium/client/helium_scripts.rb', line 33

def packages
  Package.all(client: self)
end

#script(id) ⇒ Object



16
17
18
# File 'lib/helium/client/helium_scripts.rb', line 16

def script(id)
  Script.find(id, client: self)
end

#scriptsObject



12
13
14
# File 'lib/helium/client/helium_scripts.rb', line 12

def scripts
  Script.all(client: self)
end

#sensor_package(id) ⇒ Object



74
75
76
# File 'lib/helium/client/helium_scripts.rb', line 74

def sensor_package(id)
  SensorPackage.find(id, client: self)
end

#sensor_packagesObject



70
71
72
# File 'lib/helium/client/helium_scripts.rb', line 70

def sensor_packages
  SensorPackage.all(client: self)
end