Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 1 addition & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,4 @@

---

## Usage

### Install

`npm i @matfire/the_movie_wrapper --save`

### Initialization

there is a single available export in this library.
This export contains the client you'll need to use in order to talk with TMDB's api.

#### Using the client in a projet
```js
import Client from "@matfire/the_movie_wrapper"

const client = new Client("<insert_your_api_key>");
```

### Available Services

Each section of the API has been divided into sections. Taking the code example above, calling the authentication service is done like so: `client.auth.createAuthUrl()`.

#### Authentication
- getAuthenticationToken() -> retrieve an authentication token for user authentication
- createAuthUrl(callbackUrl) -> generates the authentication url where the user should be redirected. Expects a callbackUrl
- createSession(requestToken) -> generates a session_id from a request token
### Documentation
Empty file added docs/.nojekyll
Empty file.
20 changes: 20 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# The Movie Wrapper

## A fully-typed TMDB Api wrapper

---

### Installation and Usage

Check [Quickstart](quickstart.md)

### Available Services

Check [Available Services](services.md)

### Saying thanks

If you liked this library and want to help me repay the coffee debt I created while working on it, you can always
<!-- ko-fi :id=matteogassend :color=red -->
Buy me a coffee
<!-- ko-fi -->
1 change: 1 addition & 0 deletions docs/_404.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Nothing to see here
3 changes: 3 additions & 0 deletions docs/_coverpage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# The Movie Getter

## A fully-typed TMDB wrapper
4 changes: 4 additions & 0 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* [Home](/)
* [Getting Started](quickstart.md)
* [Services](services.md)
* [Authentication](services/authentication.md)
34 changes: 34 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="description" content="Description">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@4/lib/themes/vue.css">
</head>
<body>
<div id="app"></div>
<script>
window.$docsify = {
name: 'TheMovieGetter',
repo: 'matfire/TheMovieWrapper',
autoHeader: true,
notFoundPage: true,
coverpage: true,
loadSidebar:true
}
</script>
<!-- Docsify v4 -->
<script src="//cdn.jsdelivr.net/npm/docsify@4"></script>
<script src="https://unpkg.com/docsify-copy-code@2"></script>
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-bash.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/docsify-ko-fi"></script>
<script>
if (typeof navigator.serviceWorker !== 'undefined') {
navigator.serviceWorker.register('sw.js')
}
</script>
</body>
</html>
23 changes: 23 additions & 0 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Getting Started

## Installation

in order to install TheMovieGetter, simply run:

```bash
npm install --save @matfire/the-movie-getter
```
from your project directory

## Using the library

- Import the library in your project
```javascript
import Client from "@matfire/the_movie_wrapper"
```
- Initialize the client with your TMDB api key
```javascript
const client = new Client("<insert_your_api_key>");
```

See [Available service](services.md) to learn what is currently available
3 changes: 3 additions & 0 deletions docs/services.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Available Services

- [Authentication](services/authentication.md)
16 changes: 16 additions & 0 deletions docs/services/authentication.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Authentication Service

## Description
this service is responsible for handling authentication. It generates authentication urls against TMDB's website and handles register a `session_id` to the client instance.

## Available Methods

- getAuthenticationToken() : get temporary authentication token
- createAuthUrl(redirectUrl) : generate url for user authentication. If specified, appends redirectUrl to request
- createSession(requestToken) : gets session_id from request token

## Example

```javascript
client.authentication.createAuthUrl('example.com')
```
83 changes: 83 additions & 0 deletions docs/sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/* ===========================================================
* docsify sw.js
* ===========================================================
* Copyright 2016 @huxpro
* Licensed under Apache 2.0
* Register service worker.
* ========================================================== */

const RUNTIME = 'docsify'
const HOSTNAME_WHITELIST = [
self.location.hostname,
'fonts.gstatic.com',
'fonts.googleapis.com',
'cdn.jsdelivr.net'
]

// The Util Function to hack URLs of intercepted requests
const getFixedUrl = (req) => {
var now = Date.now()
var url = new URL(req.url)

// 1. fixed http URL
// Just keep syncing with location.protocol
// fetch(httpURL) belongs to active mixed content.
// And fetch(httpRequest) is not supported yet.
url.protocol = self.location.protocol

// 2. add query for caching-busting.
// Github Pages served with Cache-Control: max-age=600
// max-age on mutable content is error-prone, with SW life of bugs can even extend.
// Until cache mode of Fetch API landed, we have to workaround cache-busting with query string.
// Cache-Control-Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=453190
if (url.hostname === self.location.hostname) {
url.search += (url.search ? '&' : '?') + 'cache-bust=' + now
}
return url.href
}

/**
* @Lifecycle Activate
* New one activated when old isnt being used.
*
* waitUntil(): activating ====> activated
*/
self.addEventListener('activate', event => {
event.waitUntil(self.clients.claim())
})

/**
* @Functional Fetch
* All network requests are being intercepted here.
*
* void respondWith(Promise<Response> r)
*/
self.addEventListener('fetch', event => {
// Skip some of cross-origin requests, like those for Google Analytics.
if (HOSTNAME_WHITELIST.indexOf(new URL(event.request.url).hostname) > -1) {
// Stale-while-revalidate
// similar to HTTP's stale-while-revalidate: https://www.mnot.net/blog/2007/12/12/stale
// Upgrade from Jake's to Surma's: https://gist.github.com/surma/eb441223daaedf880801ad80006389f1
const cached = caches.match(event.request)
const fixedUrl = getFixedUrl(event.request)
const fetched = fetch(fixedUrl, { cache: 'no-store' })
const fetchedCopy = fetched.then(resp => resp.clone())

// Call respondWith() with whatever we get first.
// If the fetch fails (e.g disconnected), wait for the cache.
// If there’s nothing in cache, wait for the fetch.
// If neither yields a response, return offline pages.
event.respondWith(
Promise.race([fetched.catch(_ => cached), cached])
.then(resp => resp || fetched)
.catch(_ => { /* eat any errors */ })
)

// Update the cache with the version we fetched (only for ok status)
event.waitUntil(
Promise.all([fetchedCopy, caches.open(RUNTIME)])
.then(([response, cache]) => response.ok && cache.put(event.request, response))
.catch(_ => { /* eat any errors */ })
)
}
})