Skip to content

Commit

Permalink
feat: get inststagram feed
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse0Michael committed Jul 28, 2020
1 parent 441358e commit 5040b1a
Show file tree
Hide file tree
Showing 22 changed files with 259 additions and 44 deletions.
1 change: 1 addition & 0 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ pkg/fetcher/api.go
pkg/fetcher/api_default.go
pkg/fetcher/logger.go
pkg/fetcher/model_feed_item.go
pkg/fetcher/model_feed_item_media.go
pkg/fetcher/model_feed_items.go
pkg/fetcher/routers.go
48 changes: 39 additions & 9 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ openapi: 3.0.2
info:
description: Fetch social media feeds
title: Fetcher
version: v1
version: 1.1.0
servers:
- description: Jesse's internal api
url: http://localhost:8080/
Expand All @@ -20,6 +20,14 @@ paths:
schema:
type: string
style: simple
- description: instagramID
explode: false
in: query
name: instagramID
required: false
schema:
type: string
style: simple
responses:
"200":
content:
Expand All @@ -35,11 +43,11 @@ components:
feedItems:
example:
items:
- id: 1
date: 2000-01-23
source: twitter
- id: 2
date: 2000-01-23
- id: CAfj92js93gjai
ts: 1560834652
source: instagram
- id: hnoy78d34qdty3
ts: 1560802637
source: twitter
properties:
items:
Expand All @@ -60,23 +68,45 @@ components:
type: string
ts:
description: Unix timestamp (seconds) for when the item was published
format: int64
type: integer
source:
description: The source platform the item is from
enum:
- twitter
- instagram
type: string
url:
description: Permalink to the feed item on the platform
type: string
media:
description: URL to media (image, video, etc..)
type: string
description: Array of media items (images, videos, etc...)
items:
$ref: '#/components/schemas/feedItem_media'
type: array
content:
description: Text content for the item
description: Text content for the item (may contain HTML)
type: string
required:
- id
- source
- ts
type: object
feedItem_media:
properties:
url:
description: The URL to the media content
type: string
poster:
description: The URL to a poster image
type: string
kind:
description: The kind of media
enum:
- image
- video
- audio
type: string
required:
- kind
- url
1 change: 1 addition & 0 deletions client/ts/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ api/apis.ts
api/defaultApi.ts
git_push.sh
model/./feedItem.ts
model/./feedItemMedia.ts
model/./feedItems.ts
model/models.ts
package.json
Expand Down
9 changes: 7 additions & 2 deletions client/ts/api/defaultApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Fetcher
* Fetch social media feeds
*
* The version of the OpenAPI document: v1
* The version of the OpenAPI document: 1.1.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down Expand Up @@ -89,8 +89,9 @@ export class DefaultApi {
* Get feed.
* @summary Get feed
* @param twitterID twitterID
* @param instagramID instagramID
*/
public async getFeed (twitterID?: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body: Array<FeedItems>; }> {
public async getFeed (twitterID?: string, instagramID?: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body: Array<FeedItems>; }> {
const localVarPath = this.basePath + '/feed';
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
Expand All @@ -107,6 +108,10 @@ export class DefaultApi {
localVarQueryParameters['twitterID'] = ObjectSerializer.serialize(twitterID, "string");
}

if (instagramID !== undefined) {
localVarQueryParameters['instagramID'] = ObjectSerializer.serialize(instagramID, "string");
}

(<any>Object).assign(localVarHeaderParams, options.headers);

let localVarUseFormData = false;
Expand Down
14 changes: 8 additions & 6 deletions client/ts/model/feedItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Fetcher
* Fetch social media feeds
*
* The version of the OpenAPI document: v1
* The version of the OpenAPI document: 1.1.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand All @@ -11,6 +11,7 @@
*/

import { RequestFile } from '../api';
import { FeedItemMedia } from './feedItemMedia';

export class FeedItem {
/**
Expand All @@ -30,11 +31,11 @@ export class FeedItem {
*/
'url'?: string;
/**
* URL to media (image, video, etc..)
* Array of media items (images, videos, etc...)
*/
'media'?: string;
'media'?: Array<FeedItemMedia>;
/**
* Text content for the item
* Text content for the item (may contain HTML)
*/
'content'?: string;

Expand Down Expand Up @@ -64,7 +65,7 @@ export class FeedItem {
{
"name": "media",
"baseName": "media",
"type": "string"
"type": "Array<FeedItemMedia>"
},
{
"name": "content",
Expand All @@ -79,6 +80,7 @@ export class FeedItem {

export namespace FeedItem {
export enum SourceEnum {
Twitter = <any> 'twitter'
Twitter = <any> 'twitter',
Instagram = <any> 'instagram'
}
}
59 changes: 59 additions & 0 deletions client/ts/model/feedItemMedia.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Fetcher
* Fetch social media feeds
*
* The version of the OpenAPI document: 1.1.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

import { RequestFile } from '../api';

export class FeedItemMedia {
/**
* The URL to the media content
*/
'url': string;
/**
* The URL to a poster image
*/
'poster'?: string;
/**
* The kind of media
*/
'kind': FeedItemMedia.KindEnum;

static discriminator: string | undefined = undefined;

static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
{
"name": "url",
"baseName": "url",
"type": "string"
},
{
"name": "poster",
"baseName": "poster",
"type": "string"
},
{
"name": "kind",
"baseName": "kind",
"type": "FeedItemMedia.KindEnum"
} ];

static getAttributeTypeMap() {
return FeedItemMedia.attributeTypeMap;
}
}

export namespace FeedItemMedia {
export enum KindEnum {
Image = <any> 'image',
Video = <any> 'video',
Audio = <any> 'audio'
}
}
2 changes: 1 addition & 1 deletion client/ts/model/feedItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Fetcher
* Fetch social media feeds
*
* The version of the OpenAPI document: v1
* The version of the OpenAPI document: 1.1.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
4 changes: 4 additions & 0 deletions client/ts/model/models.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export * from './feedItem';
export * from './feedItemMedia';
export * from './feedItems';

import localVarRequest = require('request');

import { FeedItem } from './feedItem';
import { FeedItemMedia } from './feedItemMedia';
import { FeedItems } from './feedItems';

/* tslint:disable:no-unused-variable */
Expand All @@ -20,10 +22,12 @@ let primitives = [

let enumsMap: {[index: string]: any} = {
"FeedItem.SourceEnum": FeedItem.SourceEnum,
"FeedItemMedia.KindEnum": FeedItemMedia.KindEnum,
}

let typeMap: {[index: string]: any} = {
"FeedItem": FeedItem,
"FeedItemMedia": FeedItemMedia,
"FeedItems": FeedItems,
}

Expand Down
8 changes: 7 additions & 1 deletion cmd/fetcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"log"
"net/http"

"github.com/ahmdrz/goinsta/v2"
"github.com/dghubble/go-twitter/twitter"
fetcher "github.com/jesse0michael/fetcher/pkg/fetcher"
"github.com/joho/godotenv"
Expand Down Expand Up @@ -41,7 +42,12 @@ func main() {
// Twitter client
twitterClient := twitter.NewClient(httpClient)

DefaultAPIService := fetcher.NewDefaultApiService(twitterClient)
insta := goinsta.New(cfg.Instagram.Username, cfg.Instagram.Password)
if err := insta.Login(); err != nil {
log.Fatalf("failed to log into instagram: %s", cfg.Instagram.Password)
}

DefaultAPIService := fetcher.NewDefaultApiService(twitterClient, insta)
DefaultAPIController := fetcher.NewDefaultApiController(DefaultAPIService)

router := fetcher.NewRouter(DefaultAPIController)
Expand Down
4 changes: 2 additions & 2 deletions cmd/lambda/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func HandleRequest(ctx context.Context, req events.APIGatewayProxyRequest) (inte
// Twitter client
twitterClient := twitter.NewClient(httpClient)

fetcherService := fetcher.NewDefaultApiService(twitterClient)
fetcherService := fetcher.NewDefaultApiService(twitterClient, nil)

return fetcherService.GetFeed(feeds.Twitter)
return fetcherService.GetFeed(feeds.Twitter, "")
}

func main() {
Expand Down
Loading

0 comments on commit 5040b1a

Please sign in to comment.