Skip to content

Commit a8d0207

Browse files
authored
Merge pull request #23 from Clarifai/release-9-1
Release 9/1/2017
2 parents 94226ef + a5064ed commit a8d0207

29 files changed

+1848
-77
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ out/*
77
docs
88
node_modules/*
99
examples/node_modules
10+
.babelrc

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ node_js:
44
cache:
55
directories:
66
- node_modules
7+
before_script:
8+
- chmod +x token.sh
79
script:
10+
- source token.sh
811
- npm run test
912
- npm run build
1013
deploy:

CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ This will create three folders:
1616

1717
* `npm run watch` - this will do an initial build, then build on any changes to *src*
1818
* `npm run test` - test JS files in the */spec* folder
19+
* tests require the following environment variables to be set:
20+
* `API_KEY`
21+
* `CLIENT_ID`
22+
* `CLIENT_SECRET`
23+
* `APP_ID`
24+
* `USER_ID`
25+
* `SESSION_TOKEN`
1926
* `npm run clean` - empty and remove the folders created on build
2027

2128
#### Command line optional params

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,6 @@ Dive right into code examples to get up and running as quickly as possible with
3333

3434
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/).
3535

36+
Check out the [JSDoc](https://sdk.clarifai.com/js/latest/index.html) for a deeper reference.
37+
3638
Looking for a different client? We have many languages available with lots of documentation [Technical Reference](https://developer.clarifai.com/reference/)

gulpfile.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ gulp.task(
130130
);
131131

132132
gulp.task('test', function() {
133-
return gulp.src('./spec/*.js')
133+
const spec = gutil.env.spec;
134+
const path = spec ? `./spec/${spec}-spec.js` : './spec/*.js';
135+
136+
return gulp.src(path)
134137
.pipe(jasmine({
135138
'includeStackTrace': true,
136139
'verbose': true,
@@ -142,7 +145,8 @@ gulp.task('test', function() {
142145
}
143146
}).on('end', function() {
144147
process.exit();
145-
}).on('error', function() {
148+
}).on('error', function(e) {
149+
console.log(e);
146150
process.exit(1);
147151
}));
148152
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "clarifai",
3-
"version": "2.2.0",
3+
"version": "2.3.0",
44
"description": "Official Clarifai Javascript SDK",
55
"main": "dist/index.js",
66
"repository": "https://github.com/Clarifai/clarifai-javascript",

spec/api-key-spec.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
const Clarifai = require('./../src');
2+
const {errorHandler} = require('./helpers');
3+
const {sampleImages} = require('./test-data');
4+
5+
describe('API key', () => {
6+
it('can initialize an app with an api key', done => {
7+
const anApp = new Clarifai.App({apiKey: process.env.API_KEY});
8+
expect(anApp._config.apiKey).toEqual(process.env.API_KEY);
9+
done();
10+
});
11+
12+
it('can make calls with an api key', done => {
13+
const anApp = new Clarifai.App({apiKey: process.env.API_KEY});
14+
anApp.models.predict(Clarifai.GENERAL_MODEL, [
15+
{
16+
'url': sampleImages[0]
17+
},
18+
{
19+
'url': sampleImages[1]
20+
}
21+
])
22+
.then(response => {
23+
expect(response.outputs).toBeDefined();
24+
const outputs = response.outputs;
25+
expect(outputs.length).toBe(2);
26+
const output = outputs[0];
27+
expect(output.id).toBeDefined();
28+
expect(output.status).toBeDefined();
29+
expect(output.input).toBeDefined();
30+
expect(output.model).toBeDefined();
31+
expect(output.created_at).toBeDefined();
32+
expect(output.data).toBeDefined();
33+
done();
34+
})
35+
.catch(errorHandler.bind(done));
36+
});
37+
38+
it('Sets a token with an object', done => {
39+
const token = {
40+
access_token: 'foo',
41+
token_type: 'Bearer',
42+
expires_in: 100000,
43+
scope: 'api_access_write api_access api_access_read'
44+
};
45+
const anApp = new Clarifai.App(null, null, {token: token});
46+
anApp._config.token()
47+
.then(response => {
48+
expect(response.accessToken).toEqual('foo');
49+
done();
50+
})
51+
.catch(errorHandler.bind(done));
52+
});
53+
54+
it('Sets a token with a string', done => {
55+
const anApp = new Clarifai.App(null, null, {token: 'bar'});
56+
anApp._config.token()
57+
.then(response => {
58+
expect(response.accessToken).toEqual('bar');
59+
done();
60+
})
61+
.catch(errorHandler.bind(done));
62+
});
63+
});

spec/node-test.js renamed to spec/archive/orig-test.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,9 @@ describe('Clarifai JS SDK', function() {
14771477
expect(output.created_at).toBeDefined();
14781478
expect(output.model).toBeDefined();
14791479
expect(output.model.model_version).toBeDefined();
1480-
done();
1480+
app.workflow.delete(testWorkflowId).then(response => {
1481+
done();
1482+
}).catch(errorHandler.bind(done));
14811483
}).catch(errorHandler.bind(done));
14821484
});
14831485
});
@@ -1487,7 +1489,7 @@ describe('Clarifai JS SDK', function() {
14871489
function pollStatus(fn) {
14881490
var getStatus = setInterval(function() {
14891491
fn(getStatus)
1490-
}, 100);
1492+
}, 1000);
14911493
}
14921494

14931495
function responseHandler(response) {
@@ -1498,7 +1500,11 @@ function responseHandler(response) {
14981500
function errorHandler(err) {
14991501
expect(err.status).toBe(true);
15001502
expect(err.data).toBe(true);
1501-
log(err);
1503+
if (err.data) {
1504+
log(err.data);
1505+
} else {
1506+
log(err);
1507+
}
15021508
this();
15031509
}
15041510

spec/concepts-spec.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const Clarifai = require('./../src');
2+
const {errorHandler} = require('./helpers');
3+
const langConceptId = '的な' + Date.now();
4+
const beerId = 'beer' + Date.now();
5+
const ferrariId = 'ferrari' + Date.now();
6+
7+
let app;
8+
9+
describe('Concepts', () => {
10+
const conceptsIds = [
11+
'porsche' + Date.now(),
12+
'rolls royce' + Date.now(),
13+
'lamborghini' + Date.now(),
14+
langConceptId,
15+
beerId,
16+
ferrariId
17+
];
18+
19+
beforeAll(() => {
20+
app = new Clarifai.App(
21+
process.env.CLIENT_ID,
22+
process.env.CLIENT_SECRET,
23+
{
24+
apiEndpoint: process.env.API_ENDPOINT,
25+
token: process.env.CLIENT_TOKEN
26+
}
27+
);
28+
});
29+
30+
it('creates concepts given a list of strings', done => {
31+
app.concepts.create(conceptsIds)
32+
.then(concepts => {
33+
expect(concepts).toBeDefined();
34+
expect(concepts.length).toBe(conceptsIds.length);
35+
expect(concepts[0].id).toBe(conceptsIds[0]);
36+
expect(concepts[1].id).toBe(conceptsIds[1]);
37+
expect(concepts[2].id).toBe(conceptsIds[2]);
38+
done();
39+
})
40+
.catch(errorHandler.bind(done));
41+
});
42+
43+
it('gets concept with id in a different language', done => {
44+
app.concepts.get(langConceptId)
45+
.then(concept => {
46+
expect(concept.id).toBe(langConceptId);
47+
expect(concept.name).toBe(langConceptId);
48+
done();
49+
})
50+
.catch(errorHandler.bind(done));
51+
});
52+
53+
it('search concepts', done => {
54+
app.concepts.search('lab*')
55+
.then(concepts => {
56+
expect(concepts.length).toBe(6);
57+
expect(concepts[0].name).toBe('label');
58+
done();
59+
})
60+
.catch(errorHandler.bind(done));
61+
});
62+
63+
it('search concepts in a different language', done => {
64+
app.concepts.search('狗*', 'zh')
65+
.then(concepts => {
66+
expect(concepts.length).toBe(3);
67+
return app.models.delete();
68+
})
69+
.then(response => {
70+
expect(response.status).toBeDefined();
71+
done();
72+
})
73+
.catch(errorHandler.bind(done));
74+
});
75+
});

0 commit comments

Comments
 (0)