Skip to content

Commit

Permalink
Merge pull request #34 from upwork/v2.3.0
Browse files Browse the repository at this point in the history
v2.3.0
  • Loading branch information
mnovozhylov authored Nov 27, 2024
2 parents 1983e1c + a374506 commit 80bf6a6
Show file tree
Hide file tree
Showing 36 changed files with 122 additions and 160 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
node: [ '14', '16' ]
node: [ '16', '18' ]

name: Node ${{ matrix.node }}
steps:
Expand Down
49 changes: 5 additions & 44 deletions example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ var config = {

//var UpworkApi = require('../') // uncomment to use inside current package/sources
var UpworkApi = require('node-upwork-oauth2') // use if package is installed via npm
// , Auth = require('../lib/routers/auth').Auth // uncomment to use inside current package/sources
, Auth = require('node-upwork-oauth2/lib/routers/auth').Auth // use if package is installed via npm
, Messages = require('node-upwork-oauth2/lib/routers/messages').Messages // use if package is installed via npm
, Graphql = require('node-upwork-oauth2/lib/routers/graphql').Graphql // use if package is installed via npm
, rl = require('readline');

Expand Down Expand Up @@ -78,34 +75,6 @@ function getAccessTokenPair(api, callback) {
// end Client Credentials Grant
};

// get my data
function getUserData(api, callback) {
// make a call
var auth = new Auth(api);
auth.getUserInfo(function(error, httpStatus, data) {
// check error and httpStatus if needed and run your own error handler
debug(httpStatus, 'response status');
debug(data, 'received response');
callback(data);
});
}

// post a message
function sendMessageToRoom(api, callback) {
// make a call
var messages = new Messages(api);
var params = {
'story': '{"message": "a test message", "userId": "~01xxxxxxxx"}'
};
// NOTE: parameters are wrong - the response will produce an error, for instance
messages.sendMessageToRoom('company_id', 'room_id', params, (error, httpStatus, data) => {
// check error and httpStatus if needed and run your own error handler
debug(httpStatus, 'response status');
debug(data, 'received response');
callback(data);
});
}

// send GraphQL query
function sendGraphqlQuery(api, callback) {
// make a call
Expand Down Expand Up @@ -149,10 +118,10 @@ function sendGraphqlQuery(api, callback) {
// store access/refresh token data in the safe place!

api.setNewAccessTokenPair(tokenPair, function(tokenPair) {
// get my auth data
getUserData(api, (data) => {
debug(data, 'response');
console.log('Hello: ' + data.auth_user.first_name);
// send graphql request
sendGraphqlQuery(api, (data) => {
// do smth here with the data
console.log(data);
});
});
});
Expand All @@ -165,17 +134,9 @@ function sendGraphqlQuery(api, callback) {
// in case it's expired, i.e. expires_at < time(). Make sure you replace the
// old token accordingly in your security storage. Simply, compare the old
// access token with the new one returned in tokenPair to sync-up the data
getUserData(api, (data) => {
// first_name
console.log('Hello: ' + data.auth_user.first_name);
});
sendMessageToRoom(api, (data) => {
// do smth here with the data
console.log(data);
});
sendGraphqlQuery(api, (data) => {
// do smth here with the data
console.log(data);
console.log(data);
});
});
}
Expand Down
6 changes: 3 additions & 3 deletions lib/routers/activities/engagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ exports.Engagement = function(api) {
*/
exports.Engagement.prototype.getSpecific = function(engagementRef, callback) {
debug('running request');
this.api.client.get('tasks/v2/tasks/contracts/' + engagementRef, {}, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}

/**
Expand All @@ -56,7 +56,7 @@ exports.Engagement.prototype.getSpecific = function(engagementRef, callback) {
*/
exports.Engagement.prototype.assign = function(company, team, engagementRef, params, callback) {
debug('running request');
this.api.client.put('otask/v1/tasks/companies/' + company + '/teams/' + team + '/engagements/' + engagementRef + '/tasks', params, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}

/**
Expand All @@ -70,5 +70,5 @@ exports.Engagement.prototype.assign = function(company, team, engagementRef, par
*/
exports.Engagement.prototype.assignToEngagement = function(engagementRef, params, callback) {
debug('running request');
this.api.client.put('tasks/v2/tasks/contracts/' + engagementRef, params, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}
16 changes: 8 additions & 8 deletions lib/routers/activities/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var _getUrlByType = function(company, team, code) {
_url = '/' + code;
}

return 'otask/v1/tasks/companies/' + company + '/teams/' + team + '/tasks' + _url;
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}

/**
Expand All @@ -61,7 +61,7 @@ var _getUrlByType = function(company, team, code) {
*/
exports.Team.prototype.getList = function(company, team, callback) {
debug('running request');
this.api.client.get(_getUrlByType(company, team), {}, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}

/**
Expand All @@ -76,7 +76,7 @@ exports.Team.prototype.getList = function(company, team, callback) {
*/
exports.Team.prototype.getSpecificList = function(company, team, code, callback) {
debug('running request');
this.api.client.get(_getUrlByType(company, team, code), {}, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}

/**
Expand All @@ -90,7 +90,7 @@ exports.Team.prototype.getSpecificList = function(company, team, code, callback)
*/
exports.Team.prototype.addActivity = function(company, team, params, callback) {
debug('running request');
this.api.client.post(_getUrlByType(company, team), params, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}

/**
Expand All @@ -106,7 +106,7 @@ exports.Team.prototype.addActivity = function(company, team, params, callback) {
*/
exports.Team.prototype.updateActivity = function(company, team, code, params, callback) {
debug('running request');
this.api.client.put(_getUrlByType(company, team, code), params, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}

/**
Expand All @@ -121,7 +121,7 @@ exports.Team.prototype.updateActivity = function(company, team, code, params, ca
*/
exports.Team.prototype.archiveActivity = function(company, team, code, callback) {
debug('running request');
this.api.client.put('otask/v1/tasks/companies/' + company + '/teams/' + team + '/archive/' + code, {}, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}

/**
Expand All @@ -136,7 +136,7 @@ exports.Team.prototype.archiveActivity = function(company, team, code, callback)
*/
exports.Team.prototype.unarchiveActivity = function(company, team, code, callback) {
debug('running request');
this.api.client.put('otask/v1/tasks/companies/' + company + '/teams/' + team + '/unarchive/' + code, {}, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}

/**
Expand All @@ -149,5 +149,5 @@ exports.Team.prototype.unarchiveActivity = function(company, team, code, callbac
*/
exports.Team.prototype.updateBatch = function(company, params, callback) {
debug('running request');
this.api.client.put('otask/v1/tasks/companies/' + company + '/tasks/batch', params, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}
2 changes: 1 addition & 1 deletion lib/routers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ exports.Auth = function(api) {
*/
exports.Auth.prototype.getUserInfo = function(callback) {
debug('running request');
this.api.client.get('auth/v1/info', {}, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}
4 changes: 2 additions & 2 deletions lib/routers/freelancers/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ exports.Profile = function(api) {
*/
exports.Profile.prototype.getSpecific = function(key, callback) {
debug('running request');
this.api.client.get('profiles/v1/providers/' + key, {}, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}

/**
Expand All @@ -53,5 +53,5 @@ exports.Profile.prototype.getSpecific = function(key, callback) {
*/
exports.Profile.prototype.getSpecificBrief = function(key, callback) {
debug('running request');
this.api.client.get('profiles/v1/providers/' + key + '/brief', {}, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}
2 changes: 1 addition & 1 deletion lib/routers/freelancers/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ exports.Search = function(api) {
*/
exports.Search.prototype.find = function(params, callback) {
debug('running request');
this.api.client.get('profiles/v2/search/providers', params, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}
4 changes: 2 additions & 2 deletions lib/routers/hr/clients/applications.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ exports.Applications = function(api) {
*/
exports.Applications.prototype.getList = function(params, callback) {
debug('running request');
this.api.client.get('hr/v4/clients/applications', params, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}

/**
Expand All @@ -54,5 +54,5 @@ exports.Applications.prototype.getList = function(params, callback) {
*/
exports.Applications.prototype.getSpecific = function(reference, params, callback) {
debug('running request');
this.api.client.get('hr/v4/clients/applications' + reference, params, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}
6 changes: 3 additions & 3 deletions lib/routers/hr/clients/offers.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ exports.Offers = function(api) {
*/
exports.Offers.prototype.getList = function(params, callback) {
debug('running request');
this.api.client.get('offers/v1/clients/offers', params, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}

/**
Expand All @@ -54,7 +54,7 @@ exports.Offers.prototype.getList = function(params, callback) {
*/
exports.Offers.prototype.getSpecific = function(reference, params, callback) {
debug('running request');
this.api.client.get('offers/v1/clients/offers/' + reference, params, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}

/**
Expand All @@ -67,5 +67,5 @@ exports.Offers.prototype.getSpecific = function(reference, params, callback) {
*/
exports.Offers.prototype.makeOffer = function(params, callback) {
debug('running request');
this.api.client.post('offers/v1/clients/offers', params, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}
6 changes: 3 additions & 3 deletions lib/routers/hr/contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ exports.Contracts = function(api) {
*/
exports.Contracts.prototype.suspendContract = function(reference, params, callback) {
debug('running request');
this.api.client.put('hr/v2/contracts/' + reference + '/suspend', params, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}

/**
Expand All @@ -55,7 +55,7 @@ exports.Contracts.prototype.suspendContract = function(reference, params, callba
*/
exports.Contracts.prototype.restartContract = function(reference, params, callback) {
debug('running request');
this.api.client.put('hr/v2/contracts/' + reference + '/restart', params, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}

/**
Expand All @@ -69,5 +69,5 @@ exports.Contracts.prototype.restartContract = function(reference, params, callba
*/
exports.Contracts.prototype.endContract = function(reference, params, callback) {
debug('running request');
this.api.client.delete('hr/v2/contracts/' + reference, params, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}
4 changes: 2 additions & 2 deletions lib/routers/hr/engagements.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ exports.Engagements = function(api) {
*/
exports.Engagements.prototype.getList = function(params, callback) {
debug('running request');
this.api.client.get('hr/v2/engagements', params, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}

/**
Expand All @@ -53,5 +53,5 @@ exports.Engagements.prototype.getList = function(params, callback) {
*/
exports.Engagements.prototype.getSpecific = function(reference, callback) {
debug('running request');
this.api.client.get('hr/v2/engagements/' + reference, {}, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}
4 changes: 2 additions & 2 deletions lib/routers/hr/freelancers/applications.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ exports.Applications = function(api) {
*/
exports.Applications.prototype.getList = function(params, callback) {
debug('running request');
this.api.client.get('hr/v4/contractors/applications', params, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}

/**
Expand All @@ -53,5 +53,5 @@ exports.Applications.prototype.getList = function(params, callback) {
*/
exports.Applications.prototype.getSpecific = function(reference, callback) {
debug('running request');
this.api.client.get('hr/v4/contractors/applications' + reference, {}, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}
6 changes: 3 additions & 3 deletions lib/routers/hr/freelancers/offers.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ exports.Offers = function(api) {
*/
exports.Offers.prototype.getList = function(params, callback) {
debug('running request');
this.api.client.get('offers/v1/contractors/offers', params, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}

/**
Expand All @@ -53,7 +53,7 @@ exports.Offers.prototype.getList = function(params, callback) {
*/
exports.Offers.prototype.getSpecific = function(reference, callback) {
debug('running request');
this.api.client.get('offers/v1/contractors/offers/' + reference, {}, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}

/**
Expand All @@ -67,5 +67,5 @@ exports.Offers.prototype.getSpecific = function(reference, callback) {
*/
exports.Offers.prototype.actions = function(reference, params, callback) {
debug('running request');
this.api.client.post('offers/v1/contractors/actions/' + reference, params, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}
2 changes: 1 addition & 1 deletion lib/routers/hr/interviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ exports.Interviews = function(api) {
*/
exports.Interviews.prototype.invite = function(jobKey, params, callback) {
debug('running request');
this.api.client.post('hr/v1/jobs/' + jobKey + '/candidates', params, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}
10 changes: 5 additions & 5 deletions lib/routers/hr/jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ exports.Jobs = function(api) {
*/
exports.Jobs.prototype.getList = function(params, callback) {
debug('running request');
this.api.client.get('hr/v2/jobs', params, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}

/**
Expand All @@ -53,7 +53,7 @@ exports.Jobs.prototype.getList = function(params, callback) {
*/
exports.Jobs.prototype.getSpecific = function(key, callback) {
debug('running request');
this.api.client.get('hr/v2/jobs/' + key, {}, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}

/**
Expand All @@ -66,7 +66,7 @@ exports.Jobs.prototype.getSpecific = function(key, callback) {
*/
exports.Jobs.prototype.postJob = function(params, callback) {
debug('running request');
this.api.client.post('hr/v2/jobs', params, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}

/**
Expand All @@ -80,7 +80,7 @@ exports.Jobs.prototype.postJob = function(params, callback) {
*/
exports.Jobs.prototype.editJob = function(key, params, callback) {
debug('running request');
this.api.client.put('hr/v2/jobs/' + key, params, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}

/**
Expand All @@ -94,5 +94,5 @@ exports.Jobs.prototype.editJob = function(key, params, callback) {
*/
exports.Jobs.prototype.deleteJob = function(key, params, callback) {
debug('running request');
this.api.client.delete('hr/v2/jobs/' + key, params, callback);
throw new Error('The legacy API was deprecated. Please, use GraphQL call - see example in this library.');
}
Loading

0 comments on commit 80bf6a6

Please sign in to comment.