freelancer-kit 1.0.2 → 1.0.3
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.
- package/README.md +3 -3
- package/examples/post_project_fixed.js +33 -0
- package/examples/post_project_hourly.js +43 -0
- package/package.json +1 -1
- package/src/classes/PostProject.js +42 -0
- package/src/index.js +2 -0
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ npm install
|
|
|
34
34
|
### Authentication Example
|
|
35
35
|
|
|
36
36
|
```javascript
|
|
37
|
-
const { FreelancerAuth } = require("
|
|
37
|
+
const { FreelancerAuth } = require("freelancer-kit");
|
|
38
38
|
|
|
39
39
|
(async () => {
|
|
40
40
|
const clientId = "app_id";
|
|
@@ -70,7 +70,7 @@ const { FreelancerAuth } = require("../src/index");
|
|
|
70
70
|
### Self Profile Example
|
|
71
71
|
|
|
72
72
|
```javascript
|
|
73
|
-
const { SelfProfile } = require("
|
|
73
|
+
const { SelfProfile } = require("freelancer-kit");
|
|
74
74
|
(async () => {
|
|
75
75
|
try {
|
|
76
76
|
const profile = new SelfProfile({
|
|
@@ -94,7 +94,7 @@ const { SelfProfile } = require("../src/index");
|
|
|
94
94
|
### Search Projects Example
|
|
95
95
|
|
|
96
96
|
```javascript
|
|
97
|
-
const { SearchProjects } = require("
|
|
97
|
+
const { SearchProjects } = require("freelancer-kit");
|
|
98
98
|
|
|
99
99
|
const projects = new SearchProjects({
|
|
100
100
|
accessToken: "access_token",
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const { PostProject } = require("../src/index");
|
|
2
|
+
|
|
3
|
+
(async () => {
|
|
4
|
+
try {
|
|
5
|
+
const postProject = new PostProject({
|
|
6
|
+
accessToken: "acess token", // set your token
|
|
7
|
+
sandbox: true,
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const project = await postProject.create({
|
|
11
|
+
title: "Build my Super Website!",
|
|
12
|
+
description: "I need a modern responsive website built with React.",
|
|
13
|
+
currency: { id: 1 }, // USD
|
|
14
|
+
budget: {
|
|
15
|
+
minimum: 20,
|
|
16
|
+
maximum: 80,
|
|
17
|
+
currency_id: 1,
|
|
18
|
+
},
|
|
19
|
+
jobs: [
|
|
20
|
+
{ id: 7 }, // JAVA
|
|
21
|
+
],
|
|
22
|
+
type: "FIXED",
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
console.log("Project created successfully!");
|
|
26
|
+
console.log(project);
|
|
27
|
+
|
|
28
|
+
} catch (err) {
|
|
29
|
+
console.error("Failed to create project");
|
|
30
|
+
console.error("Status:", err.status);
|
|
31
|
+
console.error("Details:", err.details || err.message);
|
|
32
|
+
}
|
|
33
|
+
})();
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const { PostProject } = require("../src/index");
|
|
2
|
+
|
|
3
|
+
(async () => {
|
|
4
|
+
try {
|
|
5
|
+
const postProject = new PostProject({
|
|
6
|
+
accessToken: "access_token",
|
|
7
|
+
sandbox: true,
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const project = await postProject.create({
|
|
11
|
+
title: "Build my Super Website!",
|
|
12
|
+
description: "I need a modern responsive website built with React.",
|
|
13
|
+
currency: { id: 1 },
|
|
14
|
+
|
|
15
|
+
budget: {
|
|
16
|
+
minimum: 20,
|
|
17
|
+
maximum: 80,
|
|
18
|
+
currency_id: 1,
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
jobs: [
|
|
22
|
+
{ id: 7 }, // job id
|
|
23
|
+
],
|
|
24
|
+
|
|
25
|
+
type: "HOURLY",
|
|
26
|
+
|
|
27
|
+
hourly_project_info: {
|
|
28
|
+
commitment: {
|
|
29
|
+
hours: 20,
|
|
30
|
+
interval: "MONTH", // MONTH or WEEK
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
console.log("Project created successfully!");
|
|
36
|
+
console.log(project);
|
|
37
|
+
|
|
38
|
+
} catch (err) {
|
|
39
|
+
console.error("Failed to create project");
|
|
40
|
+
console.error("Status:", err.status);
|
|
41
|
+
console.error("Details:", err.details || err.message);
|
|
42
|
+
}
|
|
43
|
+
})();
|
package/package.json
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const fetch = require("node-fetch");
|
|
2
|
+
|
|
3
|
+
class PostProject {
|
|
4
|
+
constructor({ accessToken, sandbox = false }) {
|
|
5
|
+
if (!accessToken) {
|
|
6
|
+
throw new Error("accessToken is required");
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
this.accessToken = accessToken;
|
|
10
|
+
this.baseUrl = sandbox
|
|
11
|
+
? "https://www.freelancer-sandbox.com/api/projects/0.1"
|
|
12
|
+
: "https://www.freelancer.com/api/projects/0.1";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async create(projectData) {
|
|
16
|
+
if (!projectData || typeof projectData !== "object") {
|
|
17
|
+
throw new Error("projectData must be an object");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const res = await fetch(`${this.baseUrl}/projects/`, {
|
|
21
|
+
method: "POST",
|
|
22
|
+
headers: {
|
|
23
|
+
"Content-Type": "application/json",
|
|
24
|
+
"freelancer-oauth-v1": this.accessToken,
|
|
25
|
+
},
|
|
26
|
+
body: JSON.stringify(projectData),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const data = await res.json();
|
|
30
|
+
|
|
31
|
+
if (!res.ok) {
|
|
32
|
+
const error = new Error(data.message || "Freelancer API Error");
|
|
33
|
+
error.status = res.status;
|
|
34
|
+
error.details = data;
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return data;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = PostProject;
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const SelfProfile = require("./classes/SelfProfile");
|
|
2
2
|
const Token = require("./classes/Token");
|
|
3
3
|
const SearchProjects = require("./classes/SearchProjects");
|
|
4
|
+
const PostProject = require("./classes/PostProject");
|
|
4
5
|
const FreelancerAuth = require("./classes/FreelancerAuth");
|
|
5
6
|
const Bid = require("./classes/Bid")
|
|
6
7
|
|
|
@@ -8,6 +9,7 @@ module.exports = {
|
|
|
8
9
|
SelfProfile,
|
|
9
10
|
Token,
|
|
10
11
|
SearchProjects,
|
|
12
|
+
PostProject,
|
|
11
13
|
FreelancerAuth,
|
|
12
14
|
Bid,
|
|
13
15
|
};
|