Skip to content

Commit

Permalink
@Timeline yapılıyor...
Browse files Browse the repository at this point in the history
  • Loading branch information
numano authored and numano committed Aug 19, 2018
1 parent 9ab9d73 commit 1ba0a82
Show file tree
Hide file tree
Showing 20 changed files with 390 additions and 129 deletions.
12 changes: 9 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
{
"type": "node",
"request": "attach",
"name": "Attach by Process ID",
"name": "Attach by PROCESS ID",
"processId": "${command:PickProcess}",
// "outFiles": ["${workspaceRoot}/dist/**/*.js"],
"protocol": "inspector"
"outFiles": ["${workspaceRoot}/dist/**/*.js"],
"protocol": "inspector",
"sourceMaps": true,
"sourceMapPathOverrides": {
"webpack:///./~/*": "${workspaceRoot}/node_modules/*",
"webpack:///./*": "${workspaceRoot}/*",
"webpack:///*": "*"
}
}
]
}
85 changes: 85 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
## Gerekli ENV bilgileri (Kullanıcıya özel/gizli)

# Twitter

Gerekli bilgileri sağla

```
TWITTER_USERNAME = "mselmany"
TWITTER_COMSUMER_KEY = "S4xh0E**********jBQdTP"
TWITTER_COMSUMER_SECRET = "L2WNig***************************A2QCV4"
```

ve [localhost:3001/api/twitter/token](localhost:3001/api/twitter/token) adresine istek at.

# Github

```
GITHUB_USERNAME = "mselmany"
```

# Dribbble

```
DRIBBBLE_CLIENT_ID = "467ddg*************************************************bbaf5199"
DRIBBBLE_CLIENT_SECRET = "e22b0b******************************************************0cb1"
```

ve [localhost:3001/api/dribbble/authorize](localhost:3001/api/dribbble/authorize) adresine istek at

# Instagram

```
INSTAGRAM_CLIENT_ID = "41c8********************f8c2"
INSTAGRAM_CLIENT_SECRET = "735ad********************a76a"
```

ve [http://localhost:3001/api/instagram/authorize?redirect_uri=http://localhost:3001/api/instagram/token](http://localhost:3001/api/instagram/authorize?redirect_uri=http://localhost:3001/api/instagram/token) adresine istek at

# Medium

```
MEDIUM_USERNAME = "mselmany"
```

# Pocket

```
POCKET_CONSUMER_KEY = "512********************04c"
```

ve [http://localhost:3001/api/pocket/authorize?redirect_uri=http://localhost:3001/api/pocket/token](http://localhost:3001/api/pocket/authorize?redirect_uri=http://localhost:3001/api/pocket/token) adresine istek at

# Raindrop

```
RAINDROP_COLLECTION_ID = "332791"
```

# Soundcloud

```
SOUNDCLOUD_USER_ID = "10812846"
SOUNDCLOUD_CLIENT_ID = "acc**********************5e6"
```

# Tumblr

```
TUMBLR_BLOGNAME = "mimo-mselmany.tumblr.com"
TUMBLR_CONSUMER_KEY = "gVCDF*******************************243ma"
```

# Unsplash

```
UNSPLASH_USERNAME = "tapir"
UNSPLASH_ACCESS_KEY = "03f06*********************************************285e"
```

# Youtube

```
YOUTUBE_CHANNEL_ID = "UCqszHejOz5-c05hnUbYskdA"
YOUTUBE_API_KEY = "D1t********************Wv9c-Er4"
```
45 changes: 27 additions & 18 deletions src/routes/Dribbble/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@ class Dribbble extends ApiBase {
super({ baseURL: API_URL });
this.client_id = client_id;
this.client_secret = client_secret;
this.authorization;
}

authorize({ redirect_url } = {}) {
authorize() {
try {
this.required({ redirect_url });
return `${AUTH_URL}/authorize?client_id=${
this.client_id
}&redirect_uri=${redirect_url}`;
return `${AUTH_URL}/authorize?client_id=${this.client_id}`;
} catch (err) {
this.error(err);
}
}

async token({ code, redirect_uri } = {}) {
// have to be redirect via authorize()
async token({ code } = {}) {
try {
this.required({ code });
const r = await this.client.post(
Expand All @@ -35,54 +34,64 @@ class Dribbble extends ApiBase {
params: {
client_id: this.client_id,
client_secret: this.client_secret,
code,
...(redirect_uri && { redirect_uri })
code
}
}
);
return r.data;
const { token_type, access_token } = r.data;
this.authorization = `${token_type} ${access_token}`;
return { class: "dribbble.token", data: r.data };
} catch (err) {
this.error(err);
}
}

async shots({ authorization, page, perpage = this.perpage } = {}) {
async shots({ page, perpage = this.perpage } = {}) {
try {
this.required({ authorization });
this.required({ authorization: this.authorization });
const r = await this.client.get("/user/shots", {
headers: {
authorization
authorization: this.authorization
},
params: {
...(page && { page }),
...(perpage && { perpage })
}
});
return r.data;
return { class: "dribbble.shots", data: r.data };
} catch (err) {
this.error(err);
}
}

/*
// ! Bu endpoint sadece Dribbble tarafından onaylanmış uygulamalarda destekleniyor.
async likes({ authorization, page, perpage = this.perpage } = {}) {
// ! This endpoint supported only approved apps by Dribbble. If you want to fetch your likes please submit your app to Dribbble support team.
async likes({ page, perpage = this.perpage } = {}) {
try {
this.required({ authorization });
this.required({ authorization: this.authorization });
const r = await this.client.get("/user/likes", {
headers: {
authorization
authorization: this.authorization
},
params: {
...(page && { page }),
...(perpage && { perpage })
}
});
return r.data;
return { class: "dribbble.likes", data: r.data };
} catch (err) {
this.error(err);
}
} */

async _bundle() {
try {
let r = { shots: this.shots() };
return { class: "dribbble.bundle", data: { shots: await r.shots } };
} catch (err) {
this.error(err);
}
}
}

export default new Dribbble(DRIBBBLE_CLIENT_ID, DRIBBBLE_CLIENT_SECRET);
5 changes: 2 additions & 3 deletions src/routes/Dribbble/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const router = Router();

router.get("/authorize", function(req, res, next) {
try {
res.redirect(Dribbble.authorize({ ...req.query }));
res.redirect(Dribbble.authorize());
} catch (error) {
next(error);
}
Expand All @@ -14,7 +14,6 @@ router.get("/authorize", function(req, res, next) {
router.get("/token", async function(req, res, next) {
try {
const r = await Dribbble.token({ ...req.query });
// ! TODO: save access_token to db.
res.status(200).json(r);
} catch (error) {
next(error);
Expand All @@ -23,7 +22,7 @@ router.get("/token", async function(req, res, next) {

router.get("/shots", async function(req, res, next) {
try {
const r = await Dribbble.shots({ ...req.headers, ...req.query });
const r = await Dribbble.shots({ ...req.query });
res.status(200).json(r);
} catch (error) {
next(error);
Expand Down
30 changes: 26 additions & 4 deletions src/routes/Github/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Github extends ApiBase {
...(per_page && { per_page })
}
});
return r.data;
return { class: "github.events", data: r.data };
} catch (err) {
this.error(err);
}
Expand All @@ -32,7 +32,7 @@ class Github extends ApiBase {
...(per_page && { per_page })
}
});
return r.data;
return { class: "github.watchers", data: r.data };
} catch (err) {
this.error(err);
}
Expand All @@ -46,7 +46,7 @@ class Github extends ApiBase {
...(per_page && { per_page })
}
});
return r.data;
return { class: "github.stars", data: r.data };
} catch (err) {
this.error(err);
}
Expand All @@ -60,7 +60,29 @@ class Github extends ApiBase {
...(per_page && { per_page })
}
});
return r.data;
return { class: "github.gists", data: r.data };
} catch (err) {
this.error(err);
}
}

async _bundle() {
try {
let r = {
events: this.events(),
watchers: this.watchers(),
stars: this.stars(),
gists: this.gists()
};
return {
class: "github.bundle",
data: {
events: await r.events,
watchers: await r.watchers,
stars: await r.stars,
gists: await r.gists
}
};
} catch (err) {
this.error(err);
}
Expand Down
34 changes: 24 additions & 10 deletions src/routes/Instagram/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class Instagram extends ApiBase {
super({ baseURL: API_URL });
this.client_id = client_id;
this.client_secret = client_secret;
this.redirect_uri = null;
this.redirect_uri;
this.access_token;
}

authorize({ redirect_uri } = {}) {
Expand Down Expand Up @@ -52,38 +53,51 @@ class Instagram extends ApiBase {
"Content-Type": "application/x-www-form-urlencoded"
}
});
return r.data;
this.access_token = r.data.access_token;
return { class: "instagram.token", data: r.data };
} catch (err) {
this.error(err);
}
}

async user({ access_token } = {}) {
async user() {
try {
this.required({ access_token });
this.required({ access_token: this.access_token });
const r = await this.client.get("/users/self", {
params: {
access_token
access_token: this.access_token
}
});
return r.data;
return { class: "instagram.user", data: r.data };
} catch (err) {
this.error(err);
}
}

async media({ access_token, min_id, max_id, count = this.perpage } = {}) {
async media({ min_id, max_id, count = this.perpage } = {}) {
try {
this.required({ access_token });
this.required({ access_token: this.access_token });
const r = await this.client.get("/users/self/media/recent", {
params: {
access_token,
access_token: this.access_token,
...(min_id && { min_id }),
...(max_id && { max_id }),
...(count && { count })
}
});
return r.data;
return { class: "instagram.media", data: r.data };
} catch (err) {
this.error(err);
}
}

async _bundle() {
try {
let r = { user: this.user(), media: this.media() };
return {
class: "instagram.bundle",
data: { user: await r.user, media: await r.media }
};
} catch (err) {
this.error(err);
}
Expand Down
1 change: 0 additions & 1 deletion src/routes/Instagram/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ router.get("/authorize", async function(req, res, next) {
router.get("/token", async function(req, res, next) {
try {
const r = await Instagram.token({ ...req.query });
// ! TODO: save access_token to db.
res.status(200).json(r);
} catch (error) {
next(error);
Expand Down
Loading

0 comments on commit 1ba0a82

Please sign in to comment.