mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-19 14:05:23 +00:00
Gifs API (#223)
* gifs service * Commit from GitHub Actions (Publish APIs & Clients) Co-authored-by: domwong <domwong@users.noreply.github.com>
This commit is contained in:
135
clients/go/gifs/gifs.go
Executable file
135
clients/go/gifs/gifs.go
Executable file
@@ -0,0 +1,135 @@
|
||||
package gifs
|
||||
|
||||
import (
|
||||
"github.com/m3o/m3o-go/client"
|
||||
)
|
||||
|
||||
func NewGifsService(token string) *GifsService {
|
||||
return &GifsService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type GifsService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Search for a gif
|
||||
func (t *GifsService) Search(request *SearchRequest) (*SearchResponse, error) {
|
||||
rsp := &SearchResponse{}
|
||||
return rsp, t.client.Call("gifs", "Search", request, rsp)
|
||||
}
|
||||
|
||||
type Gif struct {
|
||||
// URL used for embedding the GIF
|
||||
EmbedUrl string `json:"embedUrl"`
|
||||
// The ID of the GIF
|
||||
Id string `json:"id"`
|
||||
// The different formats available for this GIF
|
||||
Images *ImageFormats `json:"images"`
|
||||
// The content rating for the GIF
|
||||
Rating string `json:"rating"`
|
||||
// A short URL for this GIF
|
||||
ShortUrl string `json:"shortUrl"`
|
||||
// The slug used in the GIF's URL
|
||||
Slug string `json:"slug"`
|
||||
// The page on which this GIF was found
|
||||
Source string `json:"source"`
|
||||
// The title for this GIF
|
||||
Title string `json:"title"`
|
||||
// The URL for this GIF
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
type ImageFormat struct {
|
||||
// height
|
||||
Height int32 `json:"height"`
|
||||
// size of the MP4 version
|
||||
Mp4size int32 `json:"mp4size"`
|
||||
// URL to an MP4 version of the gif
|
||||
Mp4url string `json:"mp4url"`
|
||||
// size in bytes
|
||||
Size int32 `json:"size"`
|
||||
// URL of the gif
|
||||
Url string `json:"url"`
|
||||
// size of the webp version
|
||||
WebpSize int32 `json:"webpSize"`
|
||||
// URL to a webp version of the gif
|
||||
WebpUrl string `json:"webpUrl"`
|
||||
// width
|
||||
Width int32 `json:"width"`
|
||||
}
|
||||
|
||||
type ImageFormats struct {
|
||||
// A downsized version of the GIF < 2MB
|
||||
Downsized *ImageFormat `json:"downsized"`
|
||||
// A downsized version of the GIF < 8MB
|
||||
DownsizedLarge *ImageFormat `json:"downsizedLarge"`
|
||||
// A downsized version of the GIF < 5MB
|
||||
DownsizedMedium *ImageFormat `json:"downsizedMedium"`
|
||||
// A downsized version of the GIF < 200kb
|
||||
DownsizedSmall *ImageFormat `json:"downsizedSmall"`
|
||||
// Static image of the downsized version of the GIF
|
||||
DownsizedStill *ImageFormat `json:"downsizedStill"`
|
||||
// Version of the GIF with fixed height of 200 pixels. Good for mobile use
|
||||
FixedHeight *ImageFormat `json:"fixedHeight"`
|
||||
// Version of the GIF with fixed height of 200 pixels and number of frames reduced to 6
|
||||
FixedHeightDownsampled *ImageFormat `json:"fixedHeightDownsampled"`
|
||||
// Version of the GIF with fixed height of 100 pixels. Good for mobile keyboards
|
||||
FixedHeightSmall *ImageFormat `json:"fixedHeightSmall"`
|
||||
// Static image of the GIF with fixed height of 100 pixels
|
||||
FixedHeightSmallStill *ImageFormat `json:"fixedHeightSmallStill"`
|
||||
// Static image of the GIF with fixed height of 200 pixels
|
||||
FixedHeightStill *ImageFormat `json:"fixedHeightStill"`
|
||||
// Version of the GIF with fixed width of 200 pixels. Good for mobile use
|
||||
FixedWidth *ImageFormat `json:"fixedWidth"`
|
||||
// Version of the GIF with fixed width of 200 pixels and number of frames reduced to 6
|
||||
FixedWidthDownsampled *ImageFormat `json:"fixedWidthDownsampled"`
|
||||
// Version of the GIF with fixed width of 100 pixels. Good for mobile keyboards
|
||||
FixedWidthSmall *ImageFormat `json:"fixedWidthSmall"`
|
||||
// Static image of the GIF with fixed width of 100 pixels
|
||||
FixedWidthSmallStill *ImageFormat `json:"fixedWidthSmallStill"`
|
||||
// Static image of the GIF with fixed width of 200 pixels
|
||||
FixedWidthStill *ImageFormat `json:"fixedWidthStill"`
|
||||
// 15 second version of the GIF looping
|
||||
Looping *ImageFormat `json:"looping"`
|
||||
// The original GIF. Good for desktop use
|
||||
Original *ImageFormat `json:"original"`
|
||||
// Static image of the original version of the GIF
|
||||
OriginalStill *ImageFormat `json:"originalStill"`
|
||||
// mp4 version of the GIF <50kb displaying first 1-2 secs
|
||||
Preview *ImageFormat `json:"preview"`
|
||||
// Version of the GIF <50kb displaying first 1-2 secs
|
||||
PreviewGif *ImageFormat `json:"previewGif"`
|
||||
}
|
||||
|
||||
type Pagination struct {
|
||||
// total number returned in this response
|
||||
Count int32 `json:"count"`
|
||||
// position in pagination
|
||||
Offset int32 `json:"offset"`
|
||||
// total number of results available
|
||||
TotalCount int32 `json:"totalCount"`
|
||||
}
|
||||
|
||||
type SearchRequest struct {
|
||||
// ISO 2 letter language code for regional content
|
||||
Lang string `json:"lang"`
|
||||
// Max number of gifs to return. Defaults to 25
|
||||
Limit int32 `json:"limit"`
|
||||
// The start position of results (used with pagination)
|
||||
Offset int32 `json:"offset"`
|
||||
// The search term
|
||||
Query string `json:"query"`
|
||||
// Apply age related content filter. "g", "pg", "pg-13", or "r". Defaults to "g"
|
||||
Rating string `json:"rating"`
|
||||
}
|
||||
|
||||
type SearchResponse struct {
|
||||
// list of results
|
||||
Data []Gif `json:"data"`
|
||||
// information on pagination
|
||||
Pagination *Pagination `json:"pagination"`
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/micro/services/clients/go/file"
|
||||
"github.com/micro/services/clients/go/forex"
|
||||
"github.com/micro/services/clients/go/geocoding"
|
||||
"github.com/micro/services/clients/go/gifs"
|
||||
"github.com/micro/services/clients/go/helloworld"
|
||||
"github.com/micro/services/clients/go/holidays"
|
||||
"github.com/micro/services/clients/go/id"
|
||||
@@ -57,6 +58,7 @@ func NewClient(token string) *Client {
|
||||
FileService: file.NewFileService(token),
|
||||
ForexService: forex.NewForexService(token),
|
||||
GeocodingService: geocoding.NewGeocodingService(token),
|
||||
GifsService: gifs.NewGifsService(token),
|
||||
HelloworldService: helloworld.NewHelloworldService(token),
|
||||
HolidaysService: holidays.NewHolidaysService(token),
|
||||
IdService: id.NewIdService(token),
|
||||
@@ -101,6 +103,7 @@ type Client struct {
|
||||
FileService *file.FileService
|
||||
ForexService *forex.ForexService
|
||||
GeocodingService *geocoding.GeocodingService
|
||||
GifsService *gifs.GifsService
|
||||
HelloworldService *helloworld.HelloworldService
|
||||
HolidaysService *holidays.HolidaysService
|
||||
IdService *id.IdService
|
||||
|
||||
129
clients/ts/gifs/index.ts
Executable file
129
clients/ts/gifs/index.ts
Executable file
@@ -0,0 +1,129 @@
|
||||
import * as m3o from "@m3o/m3o-node";
|
||||
|
||||
export class GifsService {
|
||||
private client: m3o.Client;
|
||||
|
||||
constructor(token: string) {
|
||||
this.client = new m3o.Client({ token: token });
|
||||
}
|
||||
// Search for a gif
|
||||
search(request: SearchRequest): Promise<SearchResponse> {
|
||||
return this.client.call(
|
||||
"gifs",
|
||||
"Search",
|
||||
request
|
||||
) as Promise<SearchResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
export interface Gif {
|
||||
// URL used for embedding the GIF
|
||||
embedUrl?: string;
|
||||
// The ID of the GIF
|
||||
id?: string;
|
||||
// The different formats available for this GIF
|
||||
images?: ImageFormats;
|
||||
// The content rating for the GIF
|
||||
rating?: string;
|
||||
// A short URL for this GIF
|
||||
shortUrl?: string;
|
||||
// The slug used in the GIF's URL
|
||||
slug?: string;
|
||||
// The page on which this GIF was found
|
||||
source?: string;
|
||||
// The title for this GIF
|
||||
title?: string;
|
||||
// The URL for this GIF
|
||||
url?: string;
|
||||
}
|
||||
|
||||
export interface ImageFormat {
|
||||
// height
|
||||
height?: number;
|
||||
// size of the MP4 version
|
||||
mp4Size?: number;
|
||||
// URL to an MP4 version of the gif
|
||||
mp4Url?: string;
|
||||
// size in bytes
|
||||
size?: number;
|
||||
// URL of the gif
|
||||
url?: string;
|
||||
// size of the webp version
|
||||
webpSize?: number;
|
||||
// URL to a webp version of the gif
|
||||
webpUrl?: string;
|
||||
// width
|
||||
width?: number;
|
||||
}
|
||||
|
||||
export interface ImageFormats {
|
||||
// A downsized version of the GIF < 2MB
|
||||
downsized?: ImageFormat;
|
||||
// A downsized version of the GIF < 8MB
|
||||
downsizedLarge?: ImageFormat;
|
||||
// A downsized version of the GIF < 5MB
|
||||
downsizedMedium?: ImageFormat;
|
||||
// A downsized version of the GIF < 200kb
|
||||
downsizedSmall?: ImageFormat;
|
||||
// Static image of the downsized version of the GIF
|
||||
downsizedStill?: ImageFormat;
|
||||
// Version of the GIF with fixed height of 200 pixels. Good for mobile use
|
||||
fixedHeight?: ImageFormat;
|
||||
// Version of the GIF with fixed height of 200 pixels and number of frames reduced to 6
|
||||
fixedHeightDownsampled?: ImageFormat;
|
||||
// Version of the GIF with fixed height of 100 pixels. Good for mobile keyboards
|
||||
fixedHeightSmall?: ImageFormat;
|
||||
// Static image of the GIF with fixed height of 100 pixels
|
||||
fixedHeightSmallStill?: ImageFormat;
|
||||
// Static image of the GIF with fixed height of 200 pixels
|
||||
fixedHeightStill?: ImageFormat;
|
||||
// Version of the GIF with fixed width of 200 pixels. Good for mobile use
|
||||
fixedWidth?: ImageFormat;
|
||||
// Version of the GIF with fixed width of 200 pixels and number of frames reduced to 6
|
||||
fixedWidthDownsampled?: ImageFormat;
|
||||
// Version of the GIF with fixed width of 100 pixels. Good for mobile keyboards
|
||||
fixedWidthSmall?: ImageFormat;
|
||||
// Static image of the GIF with fixed width of 100 pixels
|
||||
fixedWidthSmallStill?: ImageFormat;
|
||||
// Static image of the GIF with fixed width of 200 pixels
|
||||
fixedWidthStill?: ImageFormat;
|
||||
// 15 second version of the GIF looping
|
||||
looping?: ImageFormat;
|
||||
// The original GIF. Good for desktop use
|
||||
original?: ImageFormat;
|
||||
// Static image of the original version of the GIF
|
||||
originalStill?: ImageFormat;
|
||||
// mp4 version of the GIF <50kb displaying first 1-2 secs
|
||||
preview?: ImageFormat;
|
||||
// Version of the GIF <50kb displaying first 1-2 secs
|
||||
previewGif?: ImageFormat;
|
||||
}
|
||||
|
||||
export interface Pagination {
|
||||
// total number returned in this response
|
||||
count?: number;
|
||||
// position in pagination
|
||||
offset?: number;
|
||||
// total number of results available
|
||||
totalCount?: number;
|
||||
}
|
||||
|
||||
export interface SearchRequest {
|
||||
// ISO 2 letter language code for regional content
|
||||
lang?: string;
|
||||
// Max number of gifs to return. Defaults to 25
|
||||
limit?: number;
|
||||
// The start position of results (used with pagination)
|
||||
offset?: number;
|
||||
// The search term
|
||||
query?: string;
|
||||
// Apply age related content filter. "g", "pg", "pg-13", or "r". Defaults to "g"
|
||||
rating?: string;
|
||||
}
|
||||
|
||||
export interface SearchResponse {
|
||||
// list of results
|
||||
data?: Gif[];
|
||||
// information on pagination
|
||||
pagination?: { [key: string]: any };
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import * as evchargers from "./evchargers";
|
||||
import * as file from "./file";
|
||||
import * as forex from "./forex";
|
||||
import * as geocoding from "./geocoding";
|
||||
import * as gifs from "./gifs";
|
||||
import * as helloworld from "./helloworld";
|
||||
import * as holidays from "./holidays";
|
||||
import * as id from "./id";
|
||||
@@ -51,6 +52,7 @@ export class Client {
|
||||
this.fileService = new file.FileService(token);
|
||||
this.forexService = new forex.ForexService(token);
|
||||
this.geocodingService = new geocoding.GeocodingService(token);
|
||||
this.gifsService = new gifs.GifsService(token);
|
||||
this.helloworldService = new helloworld.HelloworldService(token);
|
||||
this.holidaysService = new holidays.HolidaysService(token);
|
||||
this.idService = new id.IdService(token);
|
||||
@@ -91,6 +93,7 @@ export class Client {
|
||||
fileService: file.FileService;
|
||||
forexService: forex.ForexService;
|
||||
geocodingService: geocoding.GeocodingService;
|
||||
gifsService: gifs.GifsService;
|
||||
helloworldService: helloworld.HelloworldService;
|
||||
holidaysService: holidays.HolidaysService;
|
||||
idService: id.IdService;
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
"./file": "./dist/file/index.js",
|
||||
"./forex": "./dist/forex/index.js",
|
||||
"./geocoding": "./dist/geocoding/index.js",
|
||||
"./gifs": "./dist/gifs/index.js",
|
||||
"./helloworld": "./dist/helloworld/index.js",
|
||||
"./holidays": "./dist/holidays/index.js",
|
||||
"./id": "./dist/id/index.js",
|
||||
@@ -64,5 +65,5 @@
|
||||
},
|
||||
"type": "module",
|
||||
"types": "dist/index.d.ts",
|
||||
"version": "1.0.539"
|
||||
"version": "1.0.540"
|
||||
}
|
||||
Reference in New Issue
Block a user