Skip to content

Commit

Permalink
Merge pull request #23 from Clarifai/release-9-1
Browse files Browse the repository at this point in the history
Release 9/1/2017
  • Loading branch information
jhickey authored Sep 1, 2017
2 parents 94226ef + a5064ed commit a8d0207
Show file tree
Hide file tree
Showing 29 changed files with 1,848 additions and 77 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ out/*
docs
node_modules/*
examples/node_modules
.babelrc
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ node_js:
cache:
directories:
- node_modules
before_script:
- chmod +x token.sh
script:
- source token.sh
- npm run test
- npm run build
deploy:
Expand Down
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ This will create three folders:

* `npm run watch` - this will do an initial build, then build on any changes to *src*
* `npm run test` - test JS files in the */spec* folder
* tests require the following environment variables to be set:
* `API_KEY`
* `CLIENT_ID`
* `CLIENT_SECRET`
* `APP_ID`
* `USER_ID`
* `SESSION_TOKEN`
* `npm run clean` - empty and remove the folders created on build

#### Command line optional params
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ Dive right into code examples to get up and running as quickly as possible with

Learn the basics — predicting the contents of an image, searching across a collection and creating your own models with our [Guide](https://developer.clarifai.com/guide/).

Check out the [JSDoc](https://sdk.clarifai.com/js/latest/index.html) for a deeper reference.

Looking for a different client? We have many languages available with lots of documentation [Technical Reference](https://developer.clarifai.com/reference/)
8 changes: 6 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ gulp.task(
);

gulp.task('test', function() {
return gulp.src('./spec/*.js')
const spec = gutil.env.spec;
const path = spec ? `./spec/${spec}-spec.js` : './spec/*.js';

return gulp.src(path)
.pipe(jasmine({
'includeStackTrace': true,
'verbose': true,
Expand All @@ -142,7 +145,8 @@ gulp.task('test', function() {
}
}).on('end', function() {
process.exit();
}).on('error', function() {
}).on('error', function(e) {
console.log(e);
process.exit(1);
}));
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clarifai",
"version": "2.2.0",
"version": "2.3.0",
"description": "Official Clarifai Javascript SDK",
"main": "dist/index.js",
"repository": "https://github.com/Clarifai/clarifai-javascript",
Expand Down
63 changes: 63 additions & 0 deletions spec/api-key-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const Clarifai = require('./../src');
const {errorHandler} = require('./helpers');
const {sampleImages} = require('./test-data');

describe('API key', () => {
it('can initialize an app with an api key', done => {
const anApp = new Clarifai.App({apiKey: process.env.API_KEY});
expect(anApp._config.apiKey).toEqual(process.env.API_KEY);
done();
});

it('can make calls with an api key', done => {
const anApp = new Clarifai.App({apiKey: process.env.API_KEY});
anApp.models.predict(Clarifai.GENERAL_MODEL, [
{
'url': sampleImages[0]
},
{
'url': sampleImages[1]
}
])
.then(response => {
expect(response.outputs).toBeDefined();
const outputs = response.outputs;
expect(outputs.length).toBe(2);
const output = outputs[0];
expect(output.id).toBeDefined();
expect(output.status).toBeDefined();
expect(output.input).toBeDefined();
expect(output.model).toBeDefined();
expect(output.created_at).toBeDefined();
expect(output.data).toBeDefined();
done();
})
.catch(errorHandler.bind(done));
});

it('Sets a token with an object', done => {
const token = {
access_token: 'foo',
token_type: 'Bearer',
expires_in: 100000,
scope: 'api_access_write api_access api_access_read'
};
const anApp = new Clarifai.App(null, null, {token: token});
anApp._config.token()
.then(response => {
expect(response.accessToken).toEqual('foo');
done();
})
.catch(errorHandler.bind(done));
});

it('Sets a token with a string', done => {
const anApp = new Clarifai.App(null, null, {token: 'bar'});
anApp._config.token()
.then(response => {
expect(response.accessToken).toEqual('bar');
done();
})
.catch(errorHandler.bind(done));
});
});
12 changes: 9 additions & 3 deletions spec/node-test.js → spec/archive/orig-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,9 @@ describe('Clarifai JS SDK', function() {
expect(output.created_at).toBeDefined();
expect(output.model).toBeDefined();
expect(output.model.model_version).toBeDefined();
done();
app.workflow.delete(testWorkflowId).then(response => {
done();
}).catch(errorHandler.bind(done));
}).catch(errorHandler.bind(done));
});
});
Expand All @@ -1487,7 +1489,7 @@ describe('Clarifai JS SDK', function() {
function pollStatus(fn) {
var getStatus = setInterval(function() {
fn(getStatus)
}, 100);
}, 1000);
}

function responseHandler(response) {
Expand All @@ -1498,7 +1500,11 @@ function responseHandler(response) {
function errorHandler(err) {
expect(err.status).toBe(true);
expect(err.data).toBe(true);
log(err);
if (err.data) {
log(err.data);
} else {
log(err);
}
this();
}

Expand Down
75 changes: 75 additions & 0 deletions spec/concepts-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const Clarifai = require('./../src');
const {errorHandler} = require('./helpers');
const langConceptId = '的な' + Date.now();
const beerId = 'beer' + Date.now();
const ferrariId = 'ferrari' + Date.now();

let app;

describe('Concepts', () => {
const conceptsIds = [
'porsche' + Date.now(),
'rolls royce' + Date.now(),
'lamborghini' + Date.now(),
langConceptId,
beerId,
ferrariId
];

beforeAll(() => {
app = new Clarifai.App(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
{
apiEndpoint: process.env.API_ENDPOINT,
token: process.env.CLIENT_TOKEN
}
);
});

it('creates concepts given a list of strings', done => {
app.concepts.create(conceptsIds)
.then(concepts => {
expect(concepts).toBeDefined();
expect(concepts.length).toBe(conceptsIds.length);
expect(concepts[0].id).toBe(conceptsIds[0]);
expect(concepts[1].id).toBe(conceptsIds[1]);
expect(concepts[2].id).toBe(conceptsIds[2]);
done();
})
.catch(errorHandler.bind(done));
});

it('gets concept with id in a different language', done => {
app.concepts.get(langConceptId)
.then(concept => {
expect(concept.id).toBe(langConceptId);
expect(concept.name).toBe(langConceptId);
done();
})
.catch(errorHandler.bind(done));
});

it('search concepts', done => {
app.concepts.search('lab*')
.then(concepts => {
expect(concepts.length).toBe(6);
expect(concepts[0].name).toBe('label');
done();
})
.catch(errorHandler.bind(done));
});

it('search concepts in a different language', done => {
app.concepts.search('狗*', 'zh')
.then(concepts => {
expect(concepts.length).toBe(3);
return app.models.delete();
})
.then(response => {
expect(response.status).toBeDefined();
done();
})
.catch(errorHandler.bind(done));
});
});
Loading

0 comments on commit a8d0207

Please sign in to comment.