mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-01-29 15:44:26 +00:00
Implement data.getText and data.setText shortcut functions
This commit is contained in:
parent
9f713395af
commit
d9bfd22909
@ -266,7 +266,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div id='footer'>
|
||||
December 08, 14 10:08:42 by
|
||||
December 09, 14 08:42:53 by
|
||||
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
|
||||
Codo
|
||||
</a>
|
||||
|
@ -87,7 +87,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div id='footer'>
|
||||
December 08, 14 10:08:42 by
|
||||
December 09, 14 08:42:54 by
|
||||
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
|
||||
Codo
|
||||
</a>
|
||||
|
@ -83,7 +83,7 @@ Error: Invalid configuration file: /opt/resin.conf
|
||||
</div>
|
||||
</div>
|
||||
<div id='footer'>
|
||||
December 08, 14 10:08:42 by
|
||||
December 09, 14 08:42:54 by
|
||||
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
|
||||
Codo
|
||||
</a>
|
||||
|
@ -70,7 +70,7 @@ Error: Invalid credentials
|
||||
</div>
|
||||
</div>
|
||||
<div id='footer'>
|
||||
December 08, 14 10:08:42 by
|
||||
December 09, 14 08:42:54 by
|
||||
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
|
||||
Codo
|
||||
</a>
|
||||
|
@ -83,7 +83,7 @@ Error: You don't have any applications
|
||||
</div>
|
||||
</div>
|
||||
<div id='footer'>
|
||||
December 08, 14 10:08:42 by
|
||||
December 09, 14 08:42:54 by
|
||||
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
|
||||
Codo
|
||||
</a>
|
||||
|
@ -83,7 +83,7 @@ Error: Couldn't find application
|
||||
</div>
|
||||
</div>
|
||||
<div id='footer'>
|
||||
December 08, 14 10:08:42 by
|
||||
December 09, 14 08:42:54 by
|
||||
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
|
||||
Codo
|
||||
</a>
|
||||
|
@ -47,9 +47,8 @@
|
||||
</span>
|
||||
<span class='note private title'>Private</span>
|
||||
<span class='desc'>
|
||||
Authenticate with the server <p>resin.auth.authenticate credentials, (error, token) ->
|
||||
throw error if error?
|
||||
console.log(token)</p>
|
||||
Authenticate with the server <pre><code>resin.auth.authenticate credentials, (error, token) -> throw error if error? console.log(token)
|
||||
</code></pre>
|
||||
</span>
|
||||
</li>
|
||||
<li>
|
||||
@ -135,9 +134,8 @@
|
||||
<strong>Note:</strong>
|
||||
You should use login() when possible, as it takes care of saving the token as well.
|
||||
</div>
|
||||
<p>Authenticate with the server</p><p>resin.auth.authenticate credentials, (error, token) ->
|
||||
throw error if error?
|
||||
console.log(token)</p>
|
||||
<p>Authenticate with the server</p><pre><code>resin.auth.authenticate credentials, (error, token) -> throw error if error? console.log(token)
|
||||
</code></pre>
|
||||
</div>
|
||||
<div class='tags'>
|
||||
<h3>Parameters:</h3>
|
||||
@ -358,6 +356,10 @@
|
||||
<br>
|
||||
</p>
|
||||
<div class='docstring'>
|
||||
<div class='note todo'>
|
||||
<strong>TODO:</strong>
|
||||
This should be moved somewhere else, as it only used by the auth actions
|
||||
</div>
|
||||
<p>Parse colon separated credentials</p><pre><code>resin.auth.parseCredentials 'johndoe:secret', (error, credentials) -> throw error if error? console.log(credentials.username) console.log(credentials.password)
|
||||
</code></pre>
|
||||
</div>
|
||||
@ -390,7 +392,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div id='footer'>
|
||||
December 08, 14 10:08:42 by
|
||||
December 09, 14 08:42:54 by
|
||||
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
|
||||
Codo
|
||||
</a>
|
||||
|
@ -119,7 +119,7 @@ console.log(contents.remoteUrl)
|
||||
</div>
|
||||
</div>
|
||||
<div id='footer'>
|
||||
December 08, 14 10:08:42 by
|
||||
December 09, 14 08:42:54 by
|
||||
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
|
||||
Codo
|
||||
</a>
|
||||
|
@ -169,7 +169,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div id='footer'>
|
||||
December 08, 14 10:08:42 by
|
||||
December 09, 14 08:42:54 by
|
||||
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
|
||||
Codo
|
||||
</a>
|
||||
|
@ -37,7 +37,7 @@
|
||||
</table>
|
||||
</div>
|
||||
<div id='footer'>
|
||||
December 08, 14 10:08:42 by
|
||||
December 09, 14 08:42:54 by
|
||||
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
|
||||
Codo
|
||||
</a>
|
||||
|
@ -50,20 +50,6 @@
|
||||
<span class='note private title'>Private</span>
|
||||
<span class='desc'>
|
||||
Check if valid path <pre><code>console.log isValidPath('/Users/me')
|
||||
</code></pre>
|
||||
</span>
|
||||
</li>
|
||||
<li>
|
||||
<span class='signature'>
|
||||
<a href='#isDirectory-'>
|
||||
~
|
||||
(void)
|
||||
<b>isDirectory</b><span>(directory, callback)</span>
|
||||
</a>
|
||||
</span>
|
||||
<span class='note private title'>Private</span>
|
||||
<span class='desc'>
|
||||
Check if path is directory <pre><code>console.log isDirectory('/usr/local/share')
|
||||
</code></pre>
|
||||
</span>
|
||||
</li>
|
||||
@ -112,51 +98,12 @@ console.log isValidPath([ 1, 2, 3 ]) # False
|
||||
<span class='desc'>is valid path </span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class='method_details'>
|
||||
<p class='signature' id='isDirectory-'>
|
||||
~
|
||||
(void)
|
||||
<b>isDirectory</b><span>(directory, callback)</span>
|
||||
<span class='note private'>Private</span>
|
||||
<br>
|
||||
</p>
|
||||
<div class='docstring'>
|
||||
<p>Check if path is directory</p><pre><code>console.log isDirectory('/usr/local/share') # True
|
||||
console.log isDirectory('/Users/me/app.js') # False
|
||||
</code></pre>
|
||||
</div>
|
||||
<div class='tags'>
|
||||
<h3>Parameters:</h3>
|
||||
<ul class='param'>
|
||||
<li>
|
||||
<span class='name'>directory</span>
|
||||
<span class='type'>
|
||||
(
|
||||
<tt>String</tt>
|
||||
)
|
||||
</span>
|
||||
—
|
||||
<span class='desc'>directory </span>
|
||||
</li>
|
||||
<li>
|
||||
<span class='name'>callback</span>
|
||||
<span class='type'>
|
||||
(
|
||||
<tt>Function</tt>
|
||||
)
|
||||
</span>
|
||||
—
|
||||
<span class='desc'>callback(error, isDirectory) </span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id='footer'>
|
||||
December 08, 14 10:08:42 by
|
||||
December 09, 14 08:42:54 by
|
||||
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
|
||||
Codo
|
||||
</a>
|
||||
|
@ -186,7 +186,7 @@ console.log(devices)
|
||||
</div>
|
||||
</div>
|
||||
<div id='footer'>
|
||||
December 08, 14 10:08:42 by
|
||||
December 09, 14 08:42:54 by
|
||||
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
|
||||
Codo
|
||||
</a>
|
||||
|
@ -94,7 +94,7 @@ resin.errors.handle(error, shouldExit)
|
||||
</div>
|
||||
</div>
|
||||
<div id='footer'>
|
||||
December 08, 14 10:08:42 by
|
||||
December 09, 14 08:42:54 by
|
||||
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
|
||||
Codo
|
||||
</a>
|
||||
|
@ -37,20 +37,6 @@
|
||||
</table>
|
||||
<h2>Method Summary</h2>
|
||||
<ul class='summary'>
|
||||
<li>
|
||||
<span class='signature'>
|
||||
<a href='#isAbsolutePath-'>
|
||||
~
|
||||
(Boolean)
|
||||
<b>isAbsolutePath</b><span>(p)</span>
|
||||
</a>
|
||||
</span>
|
||||
<span class='note private title'>Private</span>
|
||||
<span class='desc'>
|
||||
Check is path is absolute <pre><code>console.log isAbsolutePath('/usr')
|
||||
</code></pre>
|
||||
</span>
|
||||
</li>
|
||||
<li>
|
||||
<span class='signature'>
|
||||
<a href='#prefixObjectValuesWithPath-'>
|
||||
@ -71,46 +57,6 @@ console.log(object.dataPrefix)
|
||||
</ul>
|
||||
<h2>Method Details</h2>
|
||||
<div class='methods'>
|
||||
<div class='method_details'>
|
||||
<p class='signature' id='isAbsolutePath-'>
|
||||
~
|
||||
(Boolean)
|
||||
<b>isAbsolutePath</b><span>(p)</span>
|
||||
<span class='note private'>Private</span>
|
||||
<br>
|
||||
</p>
|
||||
<div class='docstring'>
|
||||
<p>Check is path is absolute</p><pre><code>console.log isAbsolutePath('/usr') # True
|
||||
console.log isAbsolutePath('../Music') # False
|
||||
</code></pre>
|
||||
</div>
|
||||
<div class='tags'>
|
||||
<h3>Parameters:</h3>
|
||||
<ul class='param'>
|
||||
<li>
|
||||
<span class='name'>path</span>
|
||||
<span class='type'>
|
||||
(
|
||||
<tt>String</tt>
|
||||
)
|
||||
</span>
|
||||
—
|
||||
<span class='desc'>path </span>
|
||||
</li>
|
||||
</ul>
|
||||
<h3>Returns:</h3>
|
||||
<ul class='return'>
|
||||
<li>
|
||||
<span class='type'></span>
|
||||
(
|
||||
<tt>Boolean</tt>
|
||||
)
|
||||
—
|
||||
<span class='desc'>is absolute </span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class='method_details'>
|
||||
<p class='signature' id='prefixObjectValuesWithPath-'>
|
||||
~
|
||||
@ -159,7 +105,7 @@ console.log(object.dataPrefix) # /opt/resin
|
||||
</div>
|
||||
</div>
|
||||
<div id='footer'>
|
||||
December 08, 14 10:08:42 by
|
||||
December 09, 14 08:42:54 by
|
||||
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
|
||||
Codo
|
||||
</a>
|
||||
|
@ -57,7 +57,7 @@
|
||||
</dl>
|
||||
</div>
|
||||
<div id='footer'>
|
||||
December 08, 14 10:08:42 by
|
||||
December 09, 14 08:42:54 by
|
||||
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
|
||||
Codo
|
||||
</a>
|
||||
|
@ -348,7 +348,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div id='footer'>
|
||||
December 08, 14 10:08:42 by
|
||||
December 09, 14 08:42:54 by
|
||||
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
|
||||
Codo
|
||||
</a>
|
||||
|
@ -47,7 +47,7 @@
|
||||
</table>
|
||||
</div>
|
||||
<div id='footer'>
|
||||
December 08, 14 10:08:42 by
|
||||
December 09, 14 08:42:54 by
|
||||
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
|
||||
Codo
|
||||
</a>
|
||||
|
@ -326,7 +326,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div id='footer'>
|
||||
December 08, 14 10:08:42 by
|
||||
December 09, 14 08:42:54 by
|
||||
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
|
||||
Codo
|
||||
</a>
|
||||
|
@ -316,7 +316,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div id='footer'>
|
||||
December 08, 14 10:08:42 by
|
||||
December 09, 14 08:42:54 by
|
||||
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
|
||||
Codo
|
||||
</a>
|
||||
|
@ -39,10 +39,10 @@
|
||||
<ul class='summary'>
|
||||
<li>
|
||||
<span class='signature'>
|
||||
<a href='#getAll-'>
|
||||
<a href='#getAllByApplication-'>
|
||||
~
|
||||
(void)
|
||||
<b>getAll</b><span>(applicationId, callback)</span>
|
||||
<b>getAllByApplication</b><span>(applicationId, callback)</span>
|
||||
</a>
|
||||
</span>
|
||||
<span class='desc'>
|
||||
@ -67,17 +67,13 @@
|
||||
<h2>Method Details</h2>
|
||||
<div class='methods'>
|
||||
<div class='method_details'>
|
||||
<p class='signature' id='getAll-'>
|
||||
<p class='signature' id='getAllByApplication-'>
|
||||
~
|
||||
(void)
|
||||
<b>getAll</b><span>(applicationId, callback)</span>
|
||||
<b>getAllByApplication</b><span>(applicationId, callback)</span>
|
||||
<br>
|
||||
</p>
|
||||
<div class='docstring'>
|
||||
<div class='note todo'>
|
||||
<strong>TODO:</strong>
|
||||
Rename this to getAllByApplication
|
||||
</div>
|
||||
<p>Get all environment variables by application</p><pre><code>resin.models.environmentVariables.getAll (error, environmentVariables) -> throw error if error? console.log(environmentVariables)
|
||||
</code></pre>
|
||||
</div>
|
||||
@ -158,7 +154,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div id='footer'>
|
||||
December 08, 14 10:08:42 by
|
||||
December 09, 14 08:42:54 by
|
||||
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
|
||||
Codo
|
||||
</a>
|
||||
|
@ -52,7 +52,7 @@
|
||||
</dl>
|
||||
</div>
|
||||
<div id='footer'>
|
||||
December 08, 14 10:08:42 by
|
||||
December 09, 14 08:42:54 by
|
||||
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
|
||||
Codo
|
||||
</a>
|
||||
|
@ -156,7 +156,7 @@ console.log(result)
|
||||
</div>
|
||||
</div>
|
||||
<div id='footer'>
|
||||
December 08, 14 10:08:42 by
|
||||
December 09, 14 08:42:54 by
|
||||
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
|
||||
Codo
|
||||
</a>
|
||||
|
@ -227,7 +227,7 @@ resin.server.request { method: 'GET' url: '/download' p
|
||||
</div>
|
||||
</div>
|
||||
<div id='footer'>
|
||||
December 08, 14 10:08:42 by
|
||||
December 09, 14 08:42:54 by
|
||||
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
|
||||
Codo
|
||||
</a>
|
||||
|
@ -77,7 +77,7 @@
|
||||
</dl>
|
||||
</div>
|
||||
<div id='footer'>
|
||||
December 08, 14 10:08:42 by
|
||||
December 09, 14 08:42:54 by
|
||||
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
|
||||
Codo
|
||||
</a>
|
||||
|
@ -235,7 +235,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div id='footer'>
|
||||
December 08, 14 10:08:42 by
|
||||
December 09, 14 08:42:54 by
|
||||
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
|
||||
Codo
|
||||
</a>
|
||||
|
File diff suppressed because one or more lines are too long
@ -66,14 +66,6 @@
|
||||
(lib/resin/token/token.coffee)
|
||||
</small>
|
||||
</li>
|
||||
<li>
|
||||
<a href='class/InvalidConfigFile.html#constructor-dynamic' target='main' title='constructor'>
|
||||
#constructor
|
||||
</a>
|
||||
<small>
|
||||
(InvalidConfigFile)
|
||||
</small>
|
||||
</li>
|
||||
<li>
|
||||
<a href='class/NotFound.html#constructor-dynamic' target='main' title='constructor'>
|
||||
#constructor
|
||||
@ -90,6 +82,14 @@
|
||||
(InvalidCredentials)
|
||||
</small>
|
||||
</li>
|
||||
<li>
|
||||
<a href='class/InvalidConfigFile.html#constructor-dynamic' target='main' title='constructor'>
|
||||
#constructor
|
||||
</a>
|
||||
<small>
|
||||
(InvalidConfigFile)
|
||||
</small>
|
||||
</li>
|
||||
<li>
|
||||
<a href='class/NotAny.html#constructor-dynamic' target='main' title='constructor'>
|
||||
#constructor
|
||||
@ -130,14 +130,6 @@
|
||||
(lib/resin/os/os.coffee)
|
||||
</small>
|
||||
</li>
|
||||
<li>
|
||||
<a href='file/lib/resin/models/device.coffee.html#get-' target='main' title='get'>
|
||||
~get
|
||||
</a>
|
||||
<small>
|
||||
(lib/resin/models/device.coffee)
|
||||
</small>
|
||||
</li>
|
||||
<li>
|
||||
<a href='file/lib/resin/data/data-prefix.coffee.html#get-' target='main' title='get'>
|
||||
~get
|
||||
@ -146,6 +138,14 @@
|
||||
(lib/resin/data/data-prefix.coffee)
|
||||
</small>
|
||||
</li>
|
||||
<li>
|
||||
<a href='file/lib/resin/models/device.coffee.html#get-' target='main' title='get'>
|
||||
~get
|
||||
</a>
|
||||
<small>
|
||||
(lib/resin/models/device.coffee)
|
||||
</small>
|
||||
</li>
|
||||
<li>
|
||||
<a href='file/lib/resin/models/application.coffee.html#get-' target='main' title='get'>
|
||||
~get
|
||||
@ -154,14 +154,6 @@
|
||||
(lib/resin/models/application.coffee)
|
||||
</small>
|
||||
</li>
|
||||
<li>
|
||||
<a href='file/lib/resin/models/environment-variables.coffee.html#getAll-' target='main' title='getAll'>
|
||||
~getAll
|
||||
</a>
|
||||
<small>
|
||||
(lib/resin/models/environment-variables.coffee)
|
||||
</small>
|
||||
</li>
|
||||
<li>
|
||||
<a href='file/lib/resin/models/application.coffee.html#getAll-' target='main' title='getAll'>
|
||||
~getAll
|
||||
@ -178,6 +170,14 @@
|
||||
(lib/resin/models/device.coffee)
|
||||
</small>
|
||||
</li>
|
||||
<li>
|
||||
<a href='file/lib/resin/models/environment-variables.coffee.html#getAllByApplication-' target='main' title='getAllByApplication'>
|
||||
~getAllByApplication
|
||||
</a>
|
||||
<small>
|
||||
(lib/resin/models/environment-variables.coffee)
|
||||
</small>
|
||||
</li>
|
||||
<li>
|
||||
<a href='file/lib/resin/models/device.coffee.html#getAllByApplication-' target='main' title='getAllByApplication'>
|
||||
~getAllByApplication
|
||||
@ -258,22 +258,6 @@
|
||||
(lib/resin/log/log.coffee)
|
||||
</small>
|
||||
</li>
|
||||
<li>
|
||||
<a href='file/lib/resin/helpers/helpers.coffee.html#isAbsolutePath-' target='main' title='isAbsolutePath'>
|
||||
~isAbsolutePath
|
||||
</a>
|
||||
<small>
|
||||
(lib/resin/helpers/helpers.coffee)
|
||||
</small>
|
||||
</li>
|
||||
<li>
|
||||
<a href='file/lib/resin/data/fs-utils/fs-utils.coffee.html#isDirectory-' target='main' title='isDirectory'>
|
||||
~isDirectory
|
||||
</a>
|
||||
<small>
|
||||
(lib/resin/data/fs-utils/fs-utils.coffee)
|
||||
</small>
|
||||
</li>
|
||||
<li>
|
||||
<a href='file/lib/resin/auth/auth.coffee.html#isLoggedIn-' target='main' title='isLoggedIn'>
|
||||
~isLoggedIn
|
||||
@ -346,14 +330,6 @@
|
||||
(lib/resin/helpers/helpers.coffee)
|
||||
</small>
|
||||
</li>
|
||||
<li>
|
||||
<a href='file/lib/resin/models/environment-variables.coffee.html#remove-' target='main' title='remove'>
|
||||
~remove
|
||||
</a>
|
||||
<small>
|
||||
(lib/resin/models/environment-variables.coffee)
|
||||
</small>
|
||||
</li>
|
||||
<li>
|
||||
<a href='file/lib/resin/models/device.coffee.html#remove-' target='main' title='remove'>
|
||||
~remove
|
||||
@ -370,6 +346,14 @@
|
||||
(lib/resin/models/application.coffee)
|
||||
</small>
|
||||
</li>
|
||||
<li>
|
||||
<a href='file/lib/resin/models/environment-variables.coffee.html#remove-' target='main' title='remove'>
|
||||
~remove
|
||||
</a>
|
||||
<small>
|
||||
(lib/resin/models/environment-variables.coffee)
|
||||
</small>
|
||||
</li>
|
||||
<li>
|
||||
<a href='file/lib/resin/server/server.coffee.html#request-' target='main' title='request'>
|
||||
~request
|
||||
|
@ -59,6 +59,23 @@ exports.get = haltIfNoPrefix (key, options, callback) ->
|
||||
keyPath = constructPath(key)
|
||||
fs.readFile(keyPath, options, callback)
|
||||
|
||||
# Get data by key as text
|
||||
#
|
||||
# @param {String} key path relative to dataPrefix
|
||||
# @param {Function} callback callback(error, value)
|
||||
#
|
||||
# @throw {Error} Will throw if data prefix was not previously set
|
||||
#
|
||||
# @note This is the same as get(), however it assumes utf8 encoding.
|
||||
#
|
||||
# @example Get text data
|
||||
# resin.data.getText 'myTextFile', (error, data) ->
|
||||
# throw error if error?
|
||||
# console.log(data)
|
||||
#
|
||||
exports.getText = haltIfNoPrefix (key, callback) ->
|
||||
exports.get(key, encoding: 'utf8', callback)
|
||||
|
||||
# Set/Update a data resource
|
||||
#
|
||||
# @param {String} key path relative to dataPrefix
|
||||
@ -79,6 +96,23 @@ exports.set = haltIfNoPrefix (key, value, options, callback) ->
|
||||
keyPath = constructPath(key)
|
||||
fs.writeFile(keyPath, value, options, callback)
|
||||
|
||||
# Set/Update a data resource as text
|
||||
#
|
||||
# @param {String} key path relative to dataPrefix
|
||||
# @param {String, Buffer} value key value
|
||||
# @param {Function} callback callback(error)
|
||||
#
|
||||
# @throw {Error} Will throw if data prefix was not previously set
|
||||
#
|
||||
# @note This is the same as set(), however it assumes utf8 encoding.
|
||||
#
|
||||
# @example Set text data
|
||||
# resin.data.setText 'greeting/en', 'Hello World!', (error) ->
|
||||
# throw error if error?
|
||||
#
|
||||
exports.setText = haltIfNoPrefix (key, value, callback) ->
|
||||
exports.set(key, value, encoding: 'utf8', callback)
|
||||
|
||||
# Check if value exists
|
||||
#
|
||||
# @param {String} key path relative to dataPrefix
|
||||
|
@ -1,6 +1,7 @@
|
||||
expect = require('chai').expect
|
||||
_ = require('lodash')
|
||||
fsPlus = require('fs-plus')
|
||||
sinon = require('sinon')
|
||||
mock = require('../../../tests/utils/mock')
|
||||
async = require('async')
|
||||
settings = require('../settings')
|
||||
@ -90,6 +91,29 @@ describe 'Data:', ->
|
||||
expect(value).to.be.undefined
|
||||
done()
|
||||
|
||||
describe '#getText()', ->
|
||||
|
||||
it 'should be able to read a valid key', (done) ->
|
||||
data.getText FILESYSTEM.text.key, (error, value) ->
|
||||
expect(error).to.not.exist
|
||||
expect(value).to.equal(FILESYSTEM.text.contents)
|
||||
done()
|
||||
|
||||
it 'should call get(), assumming utf8 encoding', (done) ->
|
||||
mock.fs.restore()
|
||||
dataGetSpy = sinon.spy(data, 'get')
|
||||
mock.fs.init(FILESYSTEM)
|
||||
|
||||
key = FILESYSTEM.text.key
|
||||
|
||||
callback = (error, value) ->
|
||||
expect(dataGetSpy).to.have.been.called
|
||||
expect(dataGetSpy).to.have.been.calledWith(key, encoding: 'utf8', callback)
|
||||
dataGetSpy.restore()
|
||||
done()
|
||||
|
||||
data.getText(key, callback)
|
||||
|
||||
describe '#has()', ->
|
||||
|
||||
it 'should return true if a file exists', (done) ->
|
||||
@ -147,6 +171,24 @@ describe 'Data:', ->
|
||||
it('should be able to write a file', writeAndCheckFixture(FILES_FIXTURES.hello))
|
||||
it('should be able to write a nested file', writeAndCheckFixture(FILES_FIXTURES.nested))
|
||||
|
||||
describe '#setText()', ->
|
||||
|
||||
it 'should call set(), assumming utf8 encoding', (done) ->
|
||||
mock.fs.restore()
|
||||
dataSetSpy = sinon.spy(data, 'set')
|
||||
mock.fs.init(FILESYSTEM)
|
||||
|
||||
key = FILESYSTEM.text.key
|
||||
contents = 'Hello World'
|
||||
|
||||
callback = (error, value) ->
|
||||
expect(dataSetSpy).to.have.been.called
|
||||
expect(dataSetSpy).to.have.been.calledWith(key, contents, encoding: 'utf8', callback)
|
||||
dataSetSpy.restore()
|
||||
done()
|
||||
|
||||
data.setText(key, contents, callback)
|
||||
|
||||
describe '#remove()', ->
|
||||
|
||||
removeAndCheckFile = (file) ->
|
||||
|
@ -19,7 +19,7 @@ TOKEN_KEY = 'token'
|
||||
# throw error if error?
|
||||
#
|
||||
exports.saveToken = (newToken, callback) ->
|
||||
data.set(TOKEN_KEY, newToken, encoding: 'utf8', callback)
|
||||
data.setText(TOKEN_KEY, newToken, callback)
|
||||
|
||||
# Check if we have any token saved
|
||||
#
|
||||
@ -48,7 +48,7 @@ exports.hasToken = (callback) ->
|
||||
# console.log("My token is: #{token}")
|
||||
#
|
||||
exports.getToken = (callback) ->
|
||||
data.get(TOKEN_KEY, encoding: 'utf8', callback)
|
||||
data.getText(TOKEN_KEY, callback)
|
||||
|
||||
# Remove token from the filesystem
|
||||
#
|
||||
|
Loading…
x
Reference in New Issue
Block a user