Skip to content

Commit

Permalink
Fix code style issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirimas committed Oct 28, 2018
1 parent 9f92173 commit 71bd468
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 55 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
Async Twitch New API Wrapper is a asynchronous java wrapper for interaction with API of the [Twitch New API](https://dev.twitch.tv/docs/api/).

Currently support:
* users
* users follows
* streams
* games
* users
* users follows
* streams
* games

Please feel free to report any issues or contribute code.

Expand All @@ -21,7 +21,7 @@ For example, a `GET /streams/featured` request would map to the `twitch.streams(

Responses are handled via callbacks passed via a handler with each function call. This process is outlined in the following examples.

#### Basic Example
### Basic Example

```java
Twitch twitch = new Twitch();
Expand Down Expand Up @@ -56,12 +56,12 @@ twitch.auth().setAccessToken("my-access-token");
```

## Documentation
* The [Twitch API](https://dev.twitch.tv/docs/api/) documentation will best explain the functionality of each endpoint.
* The [Twitch API](https://dev.twitch.tv/docs/api/) documentation will best explain the functionality of each endpoint.

## Dependencies

* [Java Async HTTP Client](https://github.com/urgrue/java-async-http/releases/tag/2.1.2) ver. 2.1.2 // Jar include to the project until it not in the maven repository
* [Jackson JSON Processor - Databind](https://github.com/FasterXML/jackson-databind/wiki) ver. 2.9.7
* [Java Async HTTP Client](https://github.com/urgrue/java-async-http/releases/tag/2.1.2) ver. 2.1.2 // Jar include to the project until it not in the maven repository
* [Jackson JSON Processor - Databind](https://github.com/FasterXML/jackson-databind/wiki) ver. 2.9.7

## Install

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,15 @@ public void run() {
*/
private void processRequest() throws IOException {
// Get a reference to the socket's input and output streams.
InputStream is = socket.getInputStream();
DataOutputStream os = new DataOutputStream(socket.getOutputStream());

// Set up input stream filters.
BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));

// Get the request line of the HTTP request message.
String requestLine = br.readLine();

// Store the request line for debugging.
//String rawRequest = "\n" + requestLine;

// Read the header lines.
String headerLine = null;
while ((headerLine = br.readLine()).length() != 0) {
//rawRequest += headerLine + "\n";
String requestLine;
try (BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()))) {
// Get the request line of the HTTP request message.
requestLine = br.readLine();
}

// DEBUG: Print request
//System.out.println(rawRequest);

// Parse the request line.
StringTokenizer tokens = new StringTokenizer(requestLine);
String requestMethod = tokens.nextToken(); // Request method, which should be "GET"
Expand Down Expand Up @@ -192,7 +180,6 @@ private void processRequest() throws IOException {

// Close streams and socket.
os.close();
br.close();
socket.close();

// Send callbacks
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ru/mirrobot/twitch/api/models/Stream.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public enum Type {
LIVE("live"),
VODCAST("vodcast");

private final String key;

Type(String key) {
this.key = key;
}

private final String key;

@Override
public String toString() {
return key;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/ru/mirrobot/twitch/api/models/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public enum Type {
GLOBAL_MOD("global_mod"),
EMPTY("");

private final String key;

Type(String key) {
this.key = key;
}

private final String key;

@Override
public String toString() {
return key;
Expand All @@ -50,12 +50,12 @@ public enum BroadcasterType {
AFFILIATE("affiliate"),
EMPTY("");

BroadcasterType(String key) {
private final String key;

BroadcasterType(String key) {
this.key = key;
}

private final String key;

@Override
public String toString() {
return key;
Expand Down
46 changes: 23 additions & 23 deletions src/main/resources/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,44 @@ var thisPage = location.origin + location.pathname; // Path to this file
var failurePage = location.origin + "/authorization-failure.html";

var hashValues = {
access_token: null,
accessToken: null,
scope: ""
};

function process() {
if (document.location.search.length > 0) {
// GET param exists
} else {
// Attempt to extract access token from hash
getAccessTokenFromHash();
/**
* Twitch Auth API sends the access token and scope through the Hash of the URL. This
* method will extract them and put them into the hashValues object.
*/
function extractAccessToken() {
var hash = document.location.hash;
var params = hash.slice(1).split("&");
for (var i = 0; i < params.length; i++) {
var param = params[i].split("=");
if (param[0] === "access_token") {
hashValues.accessToken = param[1]; // access token found
} else if (param[0] === "scope") {
hashValues.scope = param[1];
}
}
}

function getAccessTokenFromHash() {
extractAccessToken();
if (hashValues.access_token != null && hashValues.access_token.length > 0) {
if (hashValues.accessToken != null && hashValues.accessToken.length > 0) {
// Send request to server for extraction of access token
document.location.replace(thisPage + "?access_token=" + hashValues.access_token + "&scope=" + hashValues.scope);
document.location.replace(thisPage + "?access_token=" + hashValues.accessToken + "&scope=" + hashValues.scope);
} else {
// No access token found
document.location.replace(failurePage + "?error=access_denied&error_description=no_access_token_found");
}
}

/**
* Twitch Auth API sends the access token and scope through the Hash of the URL. This
* method will extract them and put them into the hashValues object.
*/
function extractAccessToken() {
var hash = document.location.hash;
var params = hash.slice(1).split('&');
for (var i = 0; i < params.length; i++) {
var param = params[i].split('=');
if (param[0] === "access_token") {
hashValues.access_token = param[1]; // access token found
} else if (param[0] === "scope") {
hashValues.scope = param[1];
}
function process() {
if (document.location.search.length > 0) {
// GET param exists
} else {
// Attempt to extract access token from hash
getAccessTokenFromHash();
}
}

Expand Down

0 comments on commit 71bd468

Please sign in to comment.