Skip to content

Commit

Permalink
Merge branch 'master' into pull/691
Browse files Browse the repository at this point in the history
# Conflicts:
#	package-lock.json
#	package.json
  • Loading branch information
dilame committed Apr 4, 2019
2 parents 404b720 + 16138d0 commit ec3620c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 202 deletions.
118 changes: 1 addition & 117 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "instagram-private-api",
"description": "Instagram private API wrapper for full access to instagram",
"version": "0.9.0",
"version": "0.9.2",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
Expand Down Expand Up @@ -66,7 +66,6 @@
"faker": "^3.1.0",
"gm": "^1.23.1",
"husky": "^1.3.1",
"image-diff": "^1.6.3",
"inquirer": "^1.1.2",
"mkdirp": "^0.5.1",
"mocha": "^5.2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/core/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export class Request {
try {
// Sometimes we have numbers greater than Number.MAX_SAFE_INTEGER in json response
// To handle it we just wrap numbers with length > 15 it double quotes to get strings instead
const bigIntToString = /([\[:])?([\d.]{15,})([,}\]])/gi;
const bigIntToString = /([\[:])?(-?[\d.]{15,})(\s*?[,}\]])/gi;
response.body = JSON.parse(response.body.replace(bigIntToString, `$1"$2"$3`));
return response;
} catch (err) {
Expand Down
92 changes: 11 additions & 81 deletions tests/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ const mkdirp = require('mkdirp');
const support = require('./support');
const _ = require('lodash');
const fs = require('fs');
const imageDiff = require('image-diff');
const rp = require('request-promise');
let session;
let credentials; // [username, password, proxy]

Expand Down Expand Up @@ -56,22 +54,15 @@ describe('Sessions', () => {
it('should not be problem to create sessions', async done => {
const device = new Device({ username: credentials[0] });
const storage = new Client.CookieMemoryStorage();
try{
const session = await Client.Session.create(
device,
storage,
credentials[0],
credentials[1],
credentials[2],
);
try {
const session = await Client.Session.create(device, storage, credentials[0], credentials[1], credentials[2]);
module.exports.session = session;
console.log(session);
session.should.be.instanceOf(Client.Session);
done();
} catch (e) {
done(e);
}

});

describe('Basics', () => {
Expand Down Expand Up @@ -119,14 +110,12 @@ describe('Sessions', () => {
});

it('should not be problem to get media likers', done => {
Client.Media.likers(session, '1317759032287303554_25025320').then(
likers => {
_.each(likers, liker => {
liker.should.be.instanceOf(Client.Account);
});
done();
},
);
Client.Media.likers(session, '1317759032287303554_25025320').then(likers => {
_.each(likers, liker => {
liker.should.be.instanceOf(Client.Account);
});
done();
});
});

it('should be able to block user', done => {
Expand All @@ -146,7 +135,7 @@ describe('Sessions', () => {
});

it('should not be problem to access media location property', done => {
function shouldBeValidLocation (location) {
function shouldBeValidLocation(location) {
location.params.should.have.property('title');
location.params.should.have.property('id');
location.should.have.property('id');
Expand All @@ -155,10 +144,7 @@ describe('Sessions', () => {
Client.Location.search(session, 'New York')
.then(locations => {
_.each(locations, shouldBeValidLocation);
const locationFeed = new Client.Feed.LocationMedia(
session,
_.first(locations).id,
);
const locationFeed = new Client.Feed.LocationMedia(session, _.first(locations).id);
return locationFeed.get();
})
.then(media => {
Expand Down Expand Up @@ -195,13 +181,7 @@ describe('Sessions', () => {
it('should not be problem to use in memory cookies', done => {
const device = new Client.Device(credentials[0]);
const storage = new Client.CookieMemoryStorage();
const promise = Client.Session.create(
device,
storage,
credentials[0],
credentials[1],
credentials[2],
);
const promise = Client.Session.create(device, storage, credentials[0], credentials[1], credentials[2]);
promise
.then(sessionInstance => {
sessionInstance.should.be.instanceOf(Client.Session);
Expand All @@ -212,56 +192,6 @@ describe('Sessions', () => {
done();
});
});

it('should not be problem to upload profile picture', done => {
const device = new Client.Device(credentials[0]);
const storage = new Client.CookieMemoryStorage();
const catPath = `${__dirname}/cat.jpg`;
const catTmpPath = `${__dirname}/tmp/downloaded.jpg`;
const promise = Client.Session.create(
device,
storage,
credentials[0],
credentials[1],
credentials[2],
);
promise
.then(sessionInstance => {
sessionInstance.should.be.instanceOf(Client.Session);
return Client.Account.setProfilePicture(session, catPath);
})
.then(account => {
account.should.be.instanceOf(Client.Account);
const picture = account.params.picture;
return [rp.get(picture, { encoding: 'binary' }), account];
})
.spread(picture => {
fs.writeFileSync(
`${__dirname}/tmp/downloaded.jpg`,
picture,
'binary',
);
return new Promise((res, rej) => {
imageDiff.getFullResult(
{
actualImage: catTmpPath,
expectedImage: catPath,
},
(err, diff) => {
if (err) return rej(err);
return res(diff);
},
);
});
})
.then(diff => {
diff.percentage.should.be.below(0.1);
done();
})
.catch(reason => {
done(reason);
});
});
});

describe('Feeds', () => {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"allowSyntheticDefaultImports": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es2016",
"target": "ES2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
Expand Down

0 comments on commit ec3620c

Please sign in to comment.