codequiry 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +225 -16
  2. package/index.js +125 -125
  3. package/package.json +35 -35
package/README.md CHANGED
@@ -1,16 +1,225 @@
1
- ## NodeJS Wrapper for Codequiry API
2
-
3
- Codequiry is a commercial grade plagiarism and similarity detection software for source code files. Submissions are checked with billions of sources on the web as well as checked locally against provided submissions. This is a NodeJS example application for the API to check code plagiarism and similarity.
4
-
5
- The API allows us to run multiple different tests on source code files:
6
- 1. Peer Check - Given a group of submissions as individual zip files, all lines of code are compared to each other and relative similarity scores are computed, as well as matched snippets.
7
- 2. Database Check - Checks submissions against popular repositories and public sources of code.
8
- 3. Web Check - Does a full check of code with over 2 billion public sources on the web.
9
-
10
- Checks return us tons of data such as similarity scores, individual file scores, cluster graphs, similarity histograms, highlights results, matched snippets, percentage plagiarised and similar, and a ton more...
11
-
12
- Main Website:
13
- https://codequiry.com
14
-
15
- API Docs:
16
- https://codequiry.com/usage/api
1
+ # NodeJS SDK for Codequiry API
2
+
3
+ Codequiry is a commercial grade plagiarism and similarity detection software for source code files. Submissions are checked with billions of sources on the web as well as checked locally against provided submissions. This is a NodeJS example application for the API to check code plagiarism and similarity.
4
+
5
+ The API allows us to run multiple different tests on source code files:
6
+ 1. Peer Check - Given a group of submissions as individual zip files, all lines of code are compared to each other and relative similarity scores are computed, as well as matched snippets.
7
+ 2. Database Check - Checks submissions against popular repositories and public sources of code.
8
+ 3. Web Check - Does a full check of code with over 2 billion public sources on the web.
9
+
10
+ Checks return us tons of data such as similarity scores, individual file scores, cluster graphs, similarity histograms, highlights results, matched snippets, percentage plagiarised and similar, and a ton more...
11
+
12
+ Main Website:
13
+ https://codequiry.com
14
+
15
+ Full API Docs:
16
+ https://codequiry.com/usage/api
17
+
18
+ ## Installation
19
+
20
+ ```
21
+ npm install codequiry
22
+ ```
23
+ #### Initializing
24
+ ```
25
+ var Codequiry = require('codequiry')
26
+ ```
27
+
28
+ #### Setting your API Key
29
+ ```
30
+ Codequiry.setAPIKey('YOUR_API_KEY')
31
+ ```
32
+ ## Usage
33
+ #### Getting account information
34
+ ```javascript
35
+ Codequiry.account(function(data, err)) {
36
+ if (!err) console.log(data);
37
+ else console.log(err)
38
+ });
39
+ ```
40
+ #### Getting checks
41
+ ```javascript
42
+ Codequiry.checks(function(data, err)) {
43
+ if (!err) console.log(data);
44
+ else console.log(err)
45
+ });
46
+ ```
47
+ #### Creating checks (specify name and programming language)
48
+ Examples:
49
+ ```
50
+ {
51
+ "error": "Invalid programming language, must be a valid language ID",
52
+ "available_languages": [
53
+ {
54
+ "id": 13,
55
+ "language": "Java (.java)"
56
+ },
57
+ {
58
+ "id": 14,
59
+ "language": "Python (.py)"
60
+ },
61
+ {
62
+ "id": 16,
63
+ "language": "C (.c/.h)"
64
+ },
65
+ {
66
+ "id": 17,
67
+ "language": "C/C++ (.cc/.c/.h/.cpp/.hpp)"
68
+ },
69
+ {
70
+ "id": 18,
71
+ "language": "C# (.cs)"
72
+ },
73
+ {
74
+ "id": 20,
75
+ "language": "Perl (.pl/.sh)"
76
+ },
77
+ {
78
+ "id": 21,
79
+ "language": "PHP (.php)"
80
+ },
81
+ {
82
+ "id": 22,
83
+ "language": "SQL (.sql)"
84
+ },
85
+ {
86
+ "id": 23,
87
+ "language": "VB (.vb/.bas)"
88
+ },
89
+ {
90
+ "id": 24,
91
+ "language": "XML (.xml)"
92
+ },
93
+ {
94
+ "id": 28,
95
+ "language": "Haskell (.hs/.lhs)"
96
+ },
97
+ {
98
+ "id": 29,
99
+ "language": "Pascal (.pas/.inc)"
100
+ },
101
+ {
102
+ "id": 30,
103
+ "language": "Go (.go)"
104
+ },
105
+ {
106
+ "id": 31,
107
+ "language": "Matlab (.m)"
108
+ },
109
+ {
110
+ "id": 32,
111
+ "language": "Lisp (.el)"
112
+ },
113
+ {
114
+ "id": 33,
115
+ "language": "Ruby (.rb)"
116
+ },
117
+ {
118
+ "id": 34,
119
+ "language": "Assembly (.asm/.s)"
120
+ },
121
+ {
122
+ "id": 38,
123
+ "language": "HTML Javascript (.html/.htm/.xhtml)"
124
+ },
125
+ {
126
+ "id": 39,
127
+ "language": "Javascript (.js/.ts)"
128
+ },
129
+ {
130
+ "id": 40,
131
+ "language": "HTML (.html/.htm/.xhtml)"
132
+ },
133
+ {
134
+ "id": 41,
135
+ "language": "Plain Text/ASCII (.txt)"
136
+ },
137
+ {
138
+ "id": 42,
139
+ "language": "Plain Text by Character (.txt)"
140
+ },
141
+ {
142
+ "id": 43,
143
+ "language": "Swift (.swift)"
144
+ },
145
+ {
146
+ "id": 44,
147
+ "language": "Kotlin (.kt/.kts)"
148
+ },
149
+ {
150
+ "id": 45,
151
+ "language": "Yacc (.y,.yy,.ypp,.yxx)"
152
+ },
153
+ {
154
+ "id": 46,
155
+ "language": "Lex (.l,.ll)"
156
+ },
157
+ {
158
+ "id": 47,
159
+ "language": "Elixir (.ex, .exs)"
160
+ },
161
+ {
162
+ "id": 48,
163
+ "language": "Python Jupyter Notebook (.ipynb)"
164
+ },
165
+ {
166
+ "id": 49,
167
+ "language": "Dart (.dart)"
168
+ }
169
+ ]
170
+ }
171
+ ```
172
+
173
+
174
+ ```javascript
175
+ Codequiry.createCheck('CheckNameHere', '13', function(data, err) {
176
+ if (!err) console.log(data);
177
+ else console.log(err)
178
+ });
179
+ ```
180
+ #### Uploading to a check (specify check_id and file (must be a zip file))
181
+ ```javascript
182
+ Codequiry.uploadFile(CHECK_ID, './test.zip', function(data, err) {
183
+ if (!err) console.log(data);
184
+ else console.log(err)
185
+ });
186
+ ```
187
+ #### Starting a check (specify check_id and if running database check or web check)
188
+ ```javascript
189
+ Codequiry.startCheck(CHECK_ID, false, false, function(data, err) {
190
+ if (!err) console.log(data);
191
+ else console.log(err)
192
+ });
193
+ ```
194
+ #### Getting a check information/status
195
+ ```javascript
196
+ Codequiry.getCheck(CHECK_ID, function(data, err) {
197
+ if (!err) console.log(data);
198
+ else console.log(err)
199
+ });
200
+ ```
201
+ #### Getting results overview
202
+ ```javascript
203
+ Codequiry.getOverview(CHECK_ID, function(data, err) {
204
+ if (!err) console.log(data);
205
+ else console.log(err)
206
+ });
207
+ ```
208
+ #### Getting specific results of a submission
209
+ ```javascript
210
+ Codequiry.getResults(CHECK_ID, SUBMISSION_ID function(data, err) {
211
+ if (!err) console.log(data);
212
+ else console.log(err)
213
+ });
214
+ ```
215
+ ## Realtime checking progress - SocketIO
216
+ This is an example of the listener, you can call this after getting a check status or after starting a check (both will reutrn a job ID, which you can listen to). Here we will listen to specific CHECK_ID.
217
+ ```javascript
218
+ Codequiry.getCheck(CHECK_ID, function(data) {
219
+ console.log(data.check.job_id);
220
+ Codequiry.checkListen(data.check.job_id);
221
+ Codequiry.emitter.on('update', function(data) {
222
+ console.log(data);
223
+ });
224
+ });
225
+ ```
package/index.js CHANGED
@@ -1,126 +1,126 @@
1
- const axios = require('axios');
2
- var api_key;
3
- var request = require('request');
4
- var fs = require('fs');
5
- var events = require('events');
6
- var io = require('socket.io-client');
7
- var em = new events.EventEmitter();
8
- exports.checkListen = function(job_id) {
9
- var socket = io('https://api.codequiry.com/');
10
- if (job_id != 0) {
11
- socket.emit('job-check', {
12
- jobid: job_id
13
- });
14
- socket.on('job-status', function(data) {
15
- em.emit('update', data);
16
- if (data.error == 1 || data.percent == 100) {
17
- socket.disconnect();
18
- }
19
- });
20
- }
21
- };
22
- exports.emitter = em;
23
- exports.setAPIKey = function(api) {
24
- api_key = api;
25
- };
26
- // Other stuff...
27
- exports.account = function(callback) {
28
- runner('account', {}, function(data, err) {
29
- callback(data, err)
30
- });
31
- };
32
- exports.checks = function(callback) {
33
- runner('checks', {}, function(data, err) {
34
- callback(data, err)
35
- });
36
- };
37
- exports.createCheck = function(checkname, lang, callback) {
38
- runner('check/create', {
39
- name: checkname,
40
- language: lang
41
- }, function(data, err) {
42
- callback(data, err)
43
- });
44
- };
45
- exports.startCheck = function(checkid, db, web, callback) {
46
- if (db) db = 1
47
- if (web) web = 1
48
- runner('check/start', {
49
- check_id: checkid,
50
- webcheck: web,
51
- dbcheck: db
52
- }, function(data, err) {
53
- callback(data, err)
54
- });
55
- };
56
- exports.uploadFile = function(checkid, filein, callback) {
57
- var params = {
58
- check_id: checkid,
59
- file: fs.createReadStream(filein)
60
- };
61
- var headersWebex = {
62
- "Access-Control-Allow-Origin": "*",
63
- 'apikey': api_key,
64
- 'Content-Type': 'multipart/form-data'
65
- }
66
- request.post({
67
- headers: headersWebex,
68
- url: 'https://codequiry.com/api/v1/check/upload',
69
- method: 'POST',
70
- formData: params
71
- }, function(error, response, body) {
72
- if (error) callback(null, error)
73
- if (JSON.parse(body).error) {
74
- callback(null, JSON.parse(body).error)
75
- } else {
76
- callback(JSON.parse(body));
77
- }
78
- });
79
- };
80
- exports.getCheck = function(checkid, callback) {
81
- runner('check/get', {
82
- check_id: checkid
83
- }, function(data, err) {
84
- callback(data, err)
85
- });
86
- };
87
- exports.getOverview = function(checkid, callback) {
88
- runner('check/overview', {
89
- check_id: checkid
90
- }, function(data, err) {
91
- callback(data, err)
92
- });
93
- };
94
- exports.getResults = function(checkid, sid, callback) {
95
- runner('check/results', {
96
- check_id: checkid,
97
- submission_id: sid
98
- }, function(data, err) {
99
- callback(data, err)
100
- });
101
- };
102
-
103
- function runner(route, postdata, callback) {
104
- if (api_key != null) {
105
- var postData = postdata;
106
- var contentType;
107
- let axiosConfig = {
108
- headers: {
109
- 'Content-Type': 'application/json',
110
- "Access-Control-Allow-Origin": "*",
111
- 'apikey': api_key,
112
- }
113
- };
114
- axios.post('https://codequiry.com/api/v1/' + route, postData, axiosConfig).then((res) => {
115
- if (res.data.error) {
116
- callback(null, res.data.error)
117
- } else {
118
- callback(res.data)
119
- }
120
- }).catch((err) => {
121
- callback(null, err.response.data.error);
122
- })
123
- } else {
124
- callback(null, 'No API Key was set');
125
- }
1
+ const axios = require('axios');
2
+ var api_key;
3
+ var request = require('request');
4
+ var fs = require('fs');
5
+ var events = require('events');
6
+ var io = require('socket.io-client');
7
+ var em = new events.EventEmitter();
8
+ exports.checkListen = function(job_id) {
9
+ var socket = io('https://api.codequiry.com/');
10
+ if (job_id != 0) {
11
+ socket.emit('job-check', {
12
+ jobid: job_id
13
+ });
14
+ socket.on('job-status', function(data) {
15
+ em.emit('update', data);
16
+ if (data.error == 1 || data.percent == 100) {
17
+ socket.disconnect();
18
+ }
19
+ });
20
+ }
21
+ };
22
+ exports.emitter = em;
23
+ exports.setAPIKey = function(api) {
24
+ api_key = api;
25
+ };
26
+ // Other stuff...
27
+ exports.account = function(callback) {
28
+ runner('account', {}, function(data, err) {
29
+ callback(data, err)
30
+ });
31
+ };
32
+ exports.checks = function(callback) {
33
+ runner('checks', {}, function(data, err) {
34
+ callback(data, err)
35
+ });
36
+ };
37
+ exports.createCheck = function(checkname, lang, callback) {
38
+ runner('check/create', {
39
+ name: checkname,
40
+ language: lang
41
+ }, function(data, err) {
42
+ callback(data, err)
43
+ });
44
+ };
45
+ exports.startCheck = function(checkid, db, web, callback) {
46
+ if (db) db = 1
47
+ if (web) web = 1
48
+ runner('check/start', {
49
+ check_id: checkid,
50
+ webcheck: web,
51
+ dbcheck: db
52
+ }, function(data, err) {
53
+ callback(data, err)
54
+ });
55
+ };
56
+ exports.uploadFile = function(checkid, filein, callback) {
57
+ var params = {
58
+ check_id: checkid,
59
+ file: fs.createReadStream(filein)
60
+ };
61
+ var headersWebex = {
62
+ "Access-Control-Allow-Origin": "*",
63
+ 'apikey': api_key,
64
+ 'Content-Type': 'multipart/form-data'
65
+ }
66
+ request.post({
67
+ headers: headersWebex,
68
+ url: 'https://codequiry.com/api/v1/check/upload',
69
+ method: 'POST',
70
+ formData: params
71
+ }, function(error, response, body) {
72
+ if (error) callback(null, error)
73
+ if (JSON.parse(body).error) {
74
+ callback(null, JSON.parse(body).error)
75
+ } else {
76
+ callback(JSON.parse(body));
77
+ }
78
+ });
79
+ };
80
+ exports.getCheck = function(checkid, callback) {
81
+ runner('check/get', {
82
+ check_id: checkid
83
+ }, function(data, err) {
84
+ callback(data, err)
85
+ });
86
+ };
87
+ exports.getOverview = function(checkid, callback) {
88
+ runner('check/overview', {
89
+ check_id: checkid
90
+ }, function(data, err) {
91
+ callback(data, err)
92
+ });
93
+ };
94
+ exports.getResults = function(checkid, sid, callback) {
95
+ runner('check/results', {
96
+ check_id: checkid,
97
+ submission_id: sid
98
+ }, function(data, err) {
99
+ callback(data, err)
100
+ });
101
+ };
102
+
103
+ function runner(route, postdata, callback) {
104
+ if (api_key != null) {
105
+ var postData = postdata;
106
+ var contentType;
107
+ let axiosConfig = {
108
+ headers: {
109
+ 'Content-Type': 'application/json',
110
+ "Access-Control-Allow-Origin": "*",
111
+ 'apikey': api_key,
112
+ }
113
+ };
114
+ axios.post('https://codequiry.com/api/v1/' + route, postData, axiosConfig).then((res) => {
115
+ if (res.data.error) {
116
+ callback(null, res.data.error)
117
+ } else {
118
+ callback(res.data)
119
+ }
120
+ }).catch((err) => {
121
+ callback(null, err.response.data);
122
+ })
123
+ } else {
124
+ callback(null, 'No API Key was set');
125
+ }
126
126
  };
package/package.json CHANGED
@@ -1,35 +1,35 @@
1
- {
2
- "name": "codequiry",
3
- "version": "1.0.2",
4
- "description": "Node JS SDK for Codequiry's Plagiarism Checking API ",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/cqchecker/codequiry-sdk.git"
12
- },
13
- "keywords": [
14
- "codequiry",
15
- "codequiry nodejs",
16
- "code plagiarism checker",
17
- "code similarity api",
18
- "moss api",
19
- "code plagiarism api",
20
- "detect code plagiarism",
21
- "code check api"
22
- ],
23
- "author": "Codequiry",
24
- "license": "ISC",
25
- "bugs": {
26
- "url": "https://github.com/cqchecker/codequiry-sdk/issues"
27
- },
28
- "homepage": "https://github.com/cqchecker/codequiry-sdk#readme",
29
- "dependencies": {
30
- "axios": "^0.19.0",
31
- "events": "^3.0.0",
32
- "request": "^2.88.0",
33
- "socket.io-client": "^2.2.0"
34
- }
35
- }
1
+ {
2
+ "name": "codequiry",
3
+ "version": "1.0.4",
4
+ "description": "Node JS SDK for Codequiry's Plagiarism Checking API ",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/cqchecker/codequiry-sdk.git"
12
+ },
13
+ "keywords": [
14
+ "codequiry",
15
+ "codequiry nodejs",
16
+ "code plagiarism checker",
17
+ "code similarity api",
18
+ "moss api",
19
+ "code plagiarism api",
20
+ "detect code plagiarism",
21
+ "code check api"
22
+ ],
23
+ "author": "Codequiry",
24
+ "license": "ISC",
25
+ "bugs": {
26
+ "url": "https://github.com/cqchecker/codequiry-sdk/issues"
27
+ },
28
+ "homepage": "https://github.com/cqchecker/codequiry-sdk#readme",
29
+ "dependencies": {
30
+ "axios": "^0.19.0",
31
+ "events": "^3.0.0",
32
+ "request": "^2.88.0",
33
+ "socket.io-client": "^2.2.0"
34
+ }
35
+ }