Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to API v3 #418

Merged
merged 3 commits into from
Oct 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ node_modules


.DS_Store
.env
.env*
.vscode

# Ignore all build output
Expand Down
3 changes: 1 addition & 2 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ in the SDK.
resin.pine.get({
resource: 'build/$count',
options: {
filter: { application: applicationId }
filter: { belongs_to__application: applicationId }
}
});
```
Expand Down Expand Up @@ -3670,7 +3670,6 @@ startup and before any calls to `fromSharedOptions()` are made.
resin.setSharedOptions({
apiUrl: 'https://api.resin.io/',
imageMakerUrl: 'https://img.resin.io/',
apiVersion: 'v2',
isBrowser: true,
});
```
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ var resin = require('resin-sdk')({

Where the factory method accepts the following options:
* `apiUrl`, string, *optional*, is the resin.io API url. Defaults to `https://api.resin.io/`,
* `apiVersion`, string, *optional*, is the version of the API to talk to, like `v2`. Defaults to the current stable version: `v2`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, removing this makes a lot of sense

* `apiKey`, string, *optional*, is the API key to make the requests with,
* `imageMakerUrl`, string, *optional*, is the resin.io image maker url. Defaults to `https://img.resin.io/`,
* `dataDirectory`, string, *optional*, *ignored in the browser*, is the directory where the user settings are stored, normally retrieved like `require('resin-settings-client').get('dataDirectory')`. Defaults to `$HOME/.resin`,
Expand Down
14 changes: 7 additions & 7 deletions lib/models/application.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ getApplicationModel = (deps, opts) ->
exports._getId = getId

normalizeApplication = (application) ->
if isArray(application.device)
forEach application.device, (device) ->
if isArray(application.owns__device)
forEach application.owns__device, (device) ->
normalizeDeviceOsVersion(device)
return application

Expand Down Expand Up @@ -354,7 +354,7 @@ getApplicationModel = (deps, opts) ->
throw new errors.ResinDiscontinuedDeviceType(deviceType)

extraOptions = if parentApplication
application: parentApplication.id
depends_on__application: parentApplication.id
else {}

return pine.post
Expand Down Expand Up @@ -598,7 +598,7 @@ getApplicationModel = (deps, opts) ->
is_web_accessible: true
options:
filter:
application: id
belongs_to__application: id
.asCallback(callback)

###*
Expand Down Expand Up @@ -630,7 +630,7 @@ getApplicationModel = (deps, opts) ->
is_web_accessible: false
options:
filter:
application: id
belongs_to__application: id
.asCallback(callback)

###*
Expand Down Expand Up @@ -663,7 +663,7 @@ getApplicationModel = (deps, opts) ->
return pine.patch
resource: 'application'
id: applicationId
body: support_expiry_date: expiryTimestamp
body: is_accessible_by_support_until__date: expiryTimestamp
.catch(notFoundResponse, treatAsMissingApplication(nameOrId))
.asCallback(callback)

Expand Down Expand Up @@ -693,7 +693,7 @@ getApplicationModel = (deps, opts) ->
return pine.patch
resource: 'application'
id: applicationId
body: support_expiry_date: null
body: is_accessible_by_support_until__date: null
.catch(notFoundResponse, treatAsMissingApplication(nameOrId))
.asCallback(callback)

Expand Down
2 changes: 1 addition & 1 deletion lib/models/build.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ getBuildModel = (deps, opts) ->
options:
mergePineOptions
filter:
application: id
belongs_to__application: id
select: [
'id'
'created_at'
Expand Down
34 changes: 17 additions & 17 deletions lib/models/device.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ getDeviceModel = (deps, opts) ->

applicationModel().get(nameOrId, select: 'id').then ({ id }) ->
exports.getAll(mergePineOptions(
filter: application: id
filter: belongs_to__application: id
options
), callback)

Expand Down Expand Up @@ -235,7 +235,7 @@ getDeviceModel = (deps, opts) ->

exports.get(parentUuidOrId, select: 'id').then ({ id }) ->
exports.getAll(mergePineOptions(
filter: device: id
filter: is_managed_by__device: id
options
), callback)

Expand Down Expand Up @@ -393,9 +393,9 @@ getDeviceModel = (deps, opts) ->
exports.getApplicationName = (uuidOrId, callback) ->
exports.get uuidOrId,
select: 'id'
expand: application: $select: 'app_name'
expand: belongs_to__application: $select: 'app_name'
.then (device) ->
device.application[0].app_name
device.belongs_to__application[0].app_name
.asCallback(callback)

###*
Expand Down Expand Up @@ -428,7 +428,7 @@ getDeviceModel = (deps, opts) ->
exports.getApplicationInfo = (uuidOrId, callback) ->
exports.get(uuidOrId).then (device) ->
ensureSupervisorCompatibility(device.supervisor_version, MIN_SUPERVISOR_APPS_API).then ->
appId = device.application[0].id
appId = device.belongs_to__application[0].id
return request.send
method: 'POST'
url: "/supervisor/v1/apps/#{appId}"
Expand Down Expand Up @@ -782,7 +782,7 @@ getDeviceModel = (deps, opts) ->
return pine.patch
resource: 'device'
body:
application: application.id
belongs_to__application: application.id
options:
filter:
uuid: device.uuid
Expand Down Expand Up @@ -819,7 +819,7 @@ getDeviceModel = (deps, opts) ->
exports.startApplication = (uuidOrId, callback) ->
exports.get(uuidOrId).then (device) ->
ensureSupervisorCompatibility(device.supervisor_version, MIN_SUPERVISOR_APPS_API).then ->
appId = device.application[0].id
appId = device.belongs_to__application[0].id
return request.send
method: 'POST'
url: "/supervisor/v1/apps/#{appId}/start"
Expand Down Expand Up @@ -862,7 +862,7 @@ getDeviceModel = (deps, opts) ->
exports.stopApplication = (uuidOrId, callback) ->
exports.get(uuidOrId).then (device) ->
ensureSupervisorCompatibility(device.supervisor_version, MIN_SUPERVISOR_APPS_API).then ->
appId = device.application[0].id
appId = device.belongs_to__application[0].id
return request.send
method: 'POST'
url: "/supervisor/v1/apps/#{appId}/stop"
Expand Down Expand Up @@ -989,7 +989,7 @@ getDeviceModel = (deps, opts) ->
baseUrl: apiUrl
body:
deviceId: device.id
appId: device.application[0].id
appId: device.belongs_to__application[0].id
data:
force: Boolean(options.force)
.catch (err) ->
Expand Down Expand Up @@ -1031,9 +1031,9 @@ getDeviceModel = (deps, opts) ->
baseUrl: apiUrl
body:
deviceId: device.id
appId: device.application[0].id
appId: device.belongs_to__application[0].id
data:
appId: device.application[0].id
appId: device.belongs_to__application[0].id
.catch (err) ->
if err.statusCode == LOCKED_STATUS_CODE
throw new errors.ResinSupervisorLockedError()
Expand Down Expand Up @@ -1078,7 +1078,7 @@ getDeviceModel = (deps, opts) ->
baseUrl: apiUrl
body:
deviceId: device.id
appId: device.application[0].id
appId: device.belongs_to__application[0].id
data:
force: Boolean(options.force)
.asCallback(callback)
Expand Down Expand Up @@ -1530,7 +1530,7 @@ getDeviceModel = (deps, opts) ->
baseUrl: apiUrl
data:
deviceId: device.id
appId: device.application[0].id
appId: device.belongs_to__application[0].id
.get('body')
.asCallback(callback)

Expand Down Expand Up @@ -1567,7 +1567,7 @@ getDeviceModel = (deps, opts) ->
baseUrl: apiUrl
data:
deviceId: device.id
appId: device.application[0].id
appId: device.belongs_to__application[0].id
.get('body')
.asCallback(callback)

Expand Down Expand Up @@ -1604,7 +1604,7 @@ getDeviceModel = (deps, opts) ->
body:
method: 'GET'
deviceId: device.id
appId: device.application[0].id
appId: device.belongs_to__application[0].id
.asCallback(callback)

###*
Expand Down Expand Up @@ -1664,7 +1664,7 @@ getDeviceModel = (deps, opts) ->
return pine.patch
resource: 'device'
id: id
body: support_expiry_date: expiryTimestamp
body: is_accessible_by_support_until__date: expiryTimestamp
.asCallback(callback)

###*
Expand Down Expand Up @@ -1693,7 +1693,7 @@ getDeviceModel = (deps, opts) ->
return pine.patch
resource: 'device'
id: id
body: support_expiry_date: null
body: is_accessible_by_support_until__date: null
.asCallback(callback)

###*
Expand Down
2 changes: 1 addition & 1 deletion lib/models/environment-variables.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ getEnvironmentVariablesModel = (deps, opts) ->
device:
$any:
$alias: 'd',
$expr: d: application: id
$expr: d: belongs_to__application: id
orderby: 'env_var_name asc'
.map(fixDeviceEnvVarNameKey)
.asCallback(callback)
Expand Down
7 changes: 4 additions & 3 deletions lib/resin.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ getSdk = (opts = {}) ->
defaults opts,
apiUrl: 'https://api.resin.io/'
imageMakerUrl: 'https://img.resin.io/'
apiVersion: 'v2'
isBrowser: window?

# You cannot externally set the API version (as SDK implementation depends on it)
opts.apiVersion = 'v3'

if opts.isBrowser
settings =
get: notImplemented
Expand Down Expand Up @@ -205,7 +207,7 @@ getSdk = (opts = {}) ->
# resin.pine.get({
# resource: 'build/$count',
# options: {
# filter: { application: applicationId }
# filter: { belongs_to__application: applicationId }
# }
# });
###
Expand Down Expand Up @@ -255,7 +257,6 @@ getSdk = (opts = {}) ->
# resin.setSharedOptions({
# apiUrl: 'https://api.resin.io/',
# imageMakerUrl: 'https://img.resin.io/',
# apiVersion: 'v2',
# isBrowser: true,
# });
###
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/models/application.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe 'Application Model', ->
.then ->
resin.models.application.getAll()
.then ([ parentApplication, childApplication ]) ->
m.chai.expect(childApplication.application.__id).to.equal(parentApplication.id)
m.chai.expect(childApplication.depends_on__application.__id).to.equal(parentApplication.id)

it 'should be rejected if the device type is invalid', ->
promise = resin.models.application.create('FooBar', 'foobarbaz')
Expand Down Expand Up @@ -256,7 +256,7 @@ describe 'Application Model', ->
.then =>
resin.models.application.get(@application.id)
.then (app) ->
Date.parse(app.support_expiry_date)
Date.parse(app.is_accessible_by_support_until__date)

m.chai.expect(promise).to.eventually.equal(expiryTime)

Expand All @@ -269,7 +269,7 @@ describe 'Application Model', ->
.then =>
resin.models.application.get(@application.id)
.then (app) ->
app.support_expiry_date
app.is_accessible_by_support_until__date

m.chai.expect(promise).to.eventually.equal(null)

14 changes: 7 additions & 7 deletions tests/integration/models/device.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,11 @@ describe 'Device Model', ->
resin.pine.post
resource: 'device'
body:
user: userId
application: @childApplication.id
belongs_to__user: userId
belongs_to__application: @childApplication.id
device_type: @childApplication.device_type
uuid: resin.models.device.generateUniqueKey()
device: @device.id
is_managed_by__device: @device.id
.then (device) =>
@childDevice = device

Expand Down Expand Up @@ -738,8 +738,8 @@ describe 'Device Model', ->
promise = resin.models.device.grantSupportAccess(@device.id, expiryTimestamp)
.then =>
resin.models.device.get(@device.id)
.then ({ support_expiry_date }) ->
Date.parse(support_expiry_date)
.then ({ is_accessible_by_support_until__date }) ->
Date.parse(is_accessible_by_support_until__date)

m.chai.expect(promise).to.eventually.equal(expiryTimestamp)

Expand All @@ -750,8 +750,8 @@ describe 'Device Model', ->
resin.models.device.revokeSupportAccess(@device.id)
.then =>
resin.models.device.get(@device.id)
.then ({ support_expiry_date }) ->
m.chai.expect(support_expiry_date).to.be.null
.then ({ is_accessible_by_support_until__date }) ->
m.chai.expect(is_accessible_by_support_until__date).to.be.null

describe 'given a single application with a device id whose shorter uuid is only numbers', ->

Expand Down
1 change: 0 additions & 1 deletion tests/integration/setup.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ else
dataDirectory: settings.get('dataDirectory')

_.assign opts,
apiVersion: 'v2'
apiKey: null
isBrowser: IS_BROWSER,
retries: 3
Expand Down