Skip to content

Commit e14f33f

Browse files
committed
Added API docs to fix #14
1 parent 5cbfbe5 commit e14f33f

9 files changed

+340
-59
lines changed

.travis.yml

+34-31
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,38 @@
1-
language: go
1+
matrix:
2+
include:
3+
- language: go
4+
go: 1.13.x
5+
install: true
6+
script:
7+
- ./test.sh
8+
deploy:
9+
# deploy binaries
10+
- provider: script
11+
skip_cleanup: true
12+
script: curl -sL https://git.io/goreleaser | bash
13+
on:
14+
tags: true
15+
condition: $TRAVIS_OS_NAME = linux
216

3-
# You don't need to test on very old versions of the Go compiler. It's the user's
4-
# responsibility to keep their compiler up to date.
5-
go:
6-
- 1.13.x
17+
# deploy API
18+
- provider: heroku
19+
api_key: $HEROKU_PRODUCTION_API_KEY
20+
app: $HEROKU_APP_NAME
21+
on:
22+
tags: true
23+
24+
- language: node_js
25+
node_js: 7
26+
script:
27+
npm i -g @stoplight/cli
28+
deploy:
29+
# deploy docs
30+
- provider: script
31+
skip_cleanup: true
32+
script: stoplight publish --token $SPOTLIGHT_TOKEN --url https://stoplight.io/api
33+
on:
34+
tags: true
35+
736

8-
# Skip the install step. Don't `go get` dependencies. Only build with the code
9-
# in vendor/
10-
install: true
11-
12-
# Don't email me the results of the test runs.
1337
notifications:
1438
email: false
15-
16-
17-
# script always runs to completion (set +e). If we have linter issues AND a
18-
# failing test, we want to see both. Configure golangci-lint with a
19-
# .golangci.yml file at the top level of your repo.
20-
script:
21-
- ./test.sh
22-
23-
deploy:
24-
- provider: script
25-
skip_cleanup: true
26-
script: curl -sL https://git.io/goreleaser | bash
27-
on:
28-
tags: true
29-
condition: $TRAVIS_OS_NAME = linux
30-
31-
- provider: heroku
32-
api_key: $HEROKU_PRODUCTION_API_KEY
33-
app: $HEROKU_APP_NAME
34-
on:
35-
tags: true

Gophie.v1.yaml

+213
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
openapi: 3.0.0
2+
info:
3+
title: Gophie
4+
version: '1.0'
5+
contact:
6+
name: Bisoncorps
7+
8+
url: 'https://github.com/bisoncorps'
9+
license:
10+
url: 'https://github.com/bisoncorps/gophie/blob/master/LICENSE'
11+
name: License(GNU AGPL v3.0)
12+
description: |-
13+
I was visiting my favourite low data movie download site, but that day was particularly annoying. I moved to click and kept getting redirected to nude pictures. I just want free movies, I cried. Bisoncorps then proceeded to create Gophie. It is a CLI tool which enables you to be the cheapskate you are without getting guilt tripped. It was eventually turned into a functional API to enable searching and listing of movies.
14+
15+
## Applications
16+
17+
Gophie is available as a CLI and has also been used to build several other products
18+
19+
- [Gophie Web](https://github.com/deven96/gophie-web)
20+
- [Beetube bot](https://github.com/kodjunkie/beetube-bot)
21+
servers:
22+
- url: 'https://gophie.herokuapp.com'
23+
description: Heroku Server
24+
paths:
25+
/list:
26+
get:
27+
summary: List
28+
tags: []
29+
responses:
30+
'200':
31+
description: OK
32+
content:
33+
application/json:
34+
schema:
35+
type: array
36+
items:
37+
$ref: '#/components/schemas/Movie'
38+
examples: {}
39+
application/xml:
40+
schema:
41+
type: array
42+
items:
43+
$ref: ''
44+
multipart/form-data:
45+
schema:
46+
type: object
47+
properties: {}
48+
operationId: get-list
49+
description: Get recent movies from an engine by page where 1 is the most recent page
50+
parameters:
51+
- schema:
52+
type: integer
53+
in: query
54+
name: page
55+
description: page number to retrieve
56+
required: true
57+
- schema:
58+
type: string
59+
default: netnaija
60+
in: query
61+
name: engine
62+
description: engine to use
63+
/engine:
64+
get:
65+
summary: Engine
66+
tags: []
67+
responses:
68+
'200':
69+
description: OK
70+
content:
71+
application/json:
72+
schema:
73+
type: object
74+
properties:
75+
name:
76+
$ref: '#/components/schemas/Engine'
77+
examples:
78+
example-1:
79+
value:
80+
fzmovies:
81+
Name: FzMovies
82+
Description: ''
83+
BaseURL: 'https://www.fzmovies.net/'
84+
SearchURL: 'https://www.fzmovies.net/csearch.php'
85+
ListURL: 'https://www.fzmovies.net/movieslist.php'
86+
netnaija:
87+
Name: NetNaija
88+
Description: ''
89+
BaseURL: 'https://www.thenetnaija.com/'
90+
SearchURL: 'https://www.thenetnaija.com/search'
91+
ListURL: 'https://www.thenetnaija.com/videos/movies/'
92+
operationId: get-engine
93+
description: Returns the engine descriptions on gophie
94+
parameters:
95+
- schema:
96+
type: string
97+
in: query
98+
name: engine
99+
description: engine to check
100+
requestBody: {}
101+
/search:
102+
get:
103+
summary: Search
104+
tags: []
105+
responses:
106+
'200':
107+
description: OK
108+
content:
109+
application/json:
110+
schema:
111+
type: array
112+
items:
113+
$ref: '#/components/schemas/Movie'
114+
examples:
115+
example-1: {}
116+
operationId: get-search
117+
description: Search for a movie
118+
parameters:
119+
- schema:
120+
type: string
121+
default: netnaija
122+
in: query
123+
description: engine
124+
name: engine
125+
- schema:
126+
type: string
127+
in: query
128+
name: query
129+
description: query to search for
130+
required: true
131+
components:
132+
schemas:
133+
Movie:
134+
title: Movie model
135+
type: object
136+
description: model representation of a movie
137+
properties:
138+
Index:
139+
type: integer
140+
description: non-unique id
141+
Title:
142+
type: string
143+
description: Title of the movie
144+
CoverPhotoLink:
145+
type: string
146+
description: Link to the cover photo
147+
Description:
148+
type: string
149+
description: Description of the movie
150+
Size:
151+
type: string
152+
description: Size of the movie
153+
DownloadLInk:
154+
type: string
155+
description: Link to download the movie
156+
Year:
157+
description: Year the movie
158+
type: number
159+
SDownloadLink:
160+
type:
161+
- 'null'
162+
- array
163+
description: If the movie is a series then this might contain links to the individual parts
164+
items:
165+
type: string
166+
UploadDate:
167+
type: string
168+
description: Date the movie was uploaded
169+
Source:
170+
type: string
171+
description: The engine the movie was retrieved from
172+
x-examples:
173+
example-1:
174+
Index: 0
175+
Title: All the Bright Places (2020)
176+
CoverPhotoLink: 'https://img.netnaija.com/NGMHHK.jpg'
177+
Description: ''
178+
Size: (242.26MB)
179+
DownloadLink: 'https://www.downloadbetter.com/RVMqXLxQs70/all-the-bright-places-2020-netnaija-com-mp4.html?d=1'
180+
Year: 2020
181+
IsSeries: false
182+
SDownloadLink: null
183+
UploadDate: ''
184+
Source: NetNaija
185+
description: Contains information concerning a movie
186+
Engine:
187+
title: Engine model
188+
type: object
189+
description: model representation of the sites that have been scraped
190+
properties:
191+
Name:
192+
type: string
193+
description: Name of the engine(site)
194+
Description:
195+
type: string
196+
description: Brief description of the engine
197+
BaseURL:
198+
type: string
199+
description: Main URL of the engine
200+
SearchURL:
201+
type: string
202+
description: Search URL of the engine
203+
ListURL:
204+
type: string
205+
description: List URL of the engine
206+
x-examples:
207+
example-1:
208+
Name: NetNaija
209+
Description: ''
210+
BaseURL: 'https://www.thenetnaija.com/'
211+
SearchURL: 'https://www.thenetnaija.com/search'
212+
ListURL: 'https://www.thenetnaija.com/videos/movies/'
213+
securitySchemes: {}

README.md

+5-21
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,7 @@ For Development use `go run main.go [command]`
6666

6767
### API
6868

69-
The available api endpoints with the possible params are
70-
- Search `GET /search?query=query`
71-
- List `GET /list?page=pageNumber`
72-
- Engine `GET /engines`
73-
74-
All endpoints have the following extra params that can be passed
75-
- `engine=engine`: defaults to `netnaija`
76-
77-
### Supported Engines
78-
79-
- NetNaija
80-
- FzMovies
81-
82-
## Deployed
83-
84-
Deployed version is hosted [here](https://gophie.herokuapp.com)
85-
86-
## Todo
69+
The complete API documentation is available on [Stoplight](https://stoplight.io/p/docs/gh/bisoncorps/gophie/Gophie.v1.yaml?srn=gh/bisoncorps/gophie/)
8770

8871
- [x] Create cli and api
8972
- [x] Fix NetNaija link issue
@@ -100,15 +83,16 @@ Deployed version is hosted [here](https://gophie.herokuapp.com)
10083
- [x] Implement resume downloads
10184
- [ ] Increment tests
10285

103-
## License (MIT)
86+
## License
10487

105-
This project is opened under the [MIT 2.0 License](https://github.com/bisoncorps/gophie/blob/master/LICENSE) which allows very broad use for both academic and commercial purposes.
88+
This project is opened under the [GNU AGPLv3](https://github.com/bisoncorps/gophie/blob/master/LICENSE) which allows very broad use for both academic and commercial purposes.
10689

10790

10891
## Credits
109-
Library | Use
92+
Library/Resource | Use
11093
------- | -----
11194
[github.com/gocolly/colly](https://github.com/gocolly/colly) | scraping the net for links
11295
[github.com/manifoldco/promptui](https://github.com/manifoldco/promptui/) | interactive CLI
11396
[github.com/spf13/cobra](https://github.com/spf13/cobra) | CLI interface
11497
[github.com/iawia002/annie](https://github.com/iawia002/annie) | Downloader (resume capabilities)
98+
[Stoplight](https://stoplight.io) | Generating API docs

cmd/api.go

+19
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package cmd
1717

1818
import (
1919
"encoding/json"
20+
"html/template"
2021
"net/http"
2122
"strconv"
2223

@@ -47,6 +48,21 @@ func getDefaultsMiddleware(handler http.HandlerFunc) http.HandlerFunc {
4748
}
4849
}
4950

51+
// DocHandler : renders iframe pointing to hosted docs
52+
func DocHandler(w http.ResponseWriter, r *http.Request) {
53+
enableCors(&w)
54+
w.Header().Add("Content-Type", "text/html")
55+
tmpl, err := template.ParseFiles("index.html")
56+
if err != nil {
57+
http.Error(w, err.Error(), http.StatusInternalServerError)
58+
return
59+
}
60+
61+
if err := tmpl.Execute(w, "None"); err != nil {
62+
http.Error(w, err.Error(), http.StatusInternalServerError)
63+
}
64+
}
65+
5066
// ListHandler : handles List Requests
5167
func ListHandler(w http.ResponseWriter, r *http.Request) {
5268
eng := r.URL.Query().Get("engine")
@@ -104,6 +120,8 @@ func SearchHandler(w http.ResponseWriter, r *http.Request) {
104120
// EngineHandler : handles Engine Listing
105121
func EngineHandler(w http.ResponseWriter, r *http.Request) {
106122
eng := r.URL.Query().Get("engine")
123+
enableCors(&w)
124+
w.Header().Add("Content-Type", "application/json")
107125
var (
108126
response []byte
109127
err error
@@ -137,6 +155,7 @@ var apiCmd = &cobra.Command{
137155
http.HandleFunc("/search", getDefaultsMiddleware(SearchHandler))
138156
http.HandleFunc("/list", getDefaultsMiddleware(ListHandler))
139157
http.HandleFunc("/engine", EngineHandler)
158+
http.HandleFunc("/", DocHandler)
140159

141160
log.Info("listening on ", port)
142161
_, err := strconv.Atoi(port)

0 commit comments

Comments
 (0)