-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Fatih Totrakanlı
committed
Jun 5, 2017
0 parents
commit d35af0d
Showing
64 changed files
with
12,932 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
nbproject/private/ | ||
build/ | ||
nbbuild/ | ||
dist/ | ||
nbdist/ | ||
.nb-gradle/ | ||
.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# SpringBoot - Spotify API - ReactJS | ||
###### This is a web application developed using Spotify API with React. | ||
###### There are two modules in the project. | ||
###### spotify-api-server is a Spring Boot application with using Spotify Search API. | ||
###### spotify-api-ui is a ReactJS application. | ||
|
||
 | ||
|
||
## spotify-api-server | ||
|
||
For use Spotify API you need to take authorization token from Spotify. | ||
You can take authorization token from [Here](https://developer.spotify.com/web-api/console/get-search-item/) | ||
|
||
In the ``` | ||
application.yml | ||
```, you can set token here. | ||
|
||
This token looks like this; | ||
``` | ||
token: "BQDYNZJKRPp271pXIiMRrRbx77TSo5BuQKMZeBXFlD9FwwRP4VjbkKxTfwKOvZSS_kZCQYSGK9QA7dKFl63tXo4taPItG6ya0AL-7L2zvOlI8IDrRwoF4yEws8AJjXtf2-PKJqj3hmaz765w_A" | ||
``` | ||
|
||
The project is a Spring Boot project. For this reason, you can run the Application class by running it. | ||
|
||
## spotify-api-ui | ||
|
||
###### This module uses React and React-Bootstrap. Includes paging and limiting features about Spotify response. | ||
|
||
In the project folder ``` | ||
$ cd spotify-api-ui | ||
``` use the following command. | ||
``` | ||
$ npm install | ||
``` | ||
|
||
then | ||
|
||
``` | ||
$ npm start | ||
``` | ||
|
||
and project will start at ``` | ||
http://127.0.0.1:3000 | ||
``` | ||
|
||
## License | ||
|
||
The MIT License (MIT) Copyright (c) 2017 Fatih Totrakanlı |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.spotify.api</groupId> | ||
<artifactId>com.spotify.api</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<modules> | ||
<module>spotify-api-server</module> | ||
</modules> | ||
<packaging>pom</packaging> | ||
|
||
<name>com.spotify.api</name> | ||
<url>http://maven.apache.org</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>com.spotify.api</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>com.spotify.api</name> | ||
<url>http://maven.apache.org</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>1.5.2.RELEASE</version> | ||
<relativePath/> | ||
</parent> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient</artifactId> | ||
<version>4.5.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>3.8.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
20 changes: 20 additions & 0 deletions
20
spotify-api-server/src/main/java/com/spotify/api/controller/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.spotify.api.controller; | ||
|
||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
import java.io.IOException; | ||
|
||
@SpringBootApplication | ||
public class Application implements CommandLineRunner { | ||
|
||
public static void main(String[] args) throws IOException { | ||
SpringApplication.run(Application.class, args); | ||
} | ||
|
||
@Override | ||
public void run(String... strings) throws Exception { | ||
|
||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
spotify-api-server/src/main/java/com/spotify/api/controller/controller/SearchController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.spotify.api.controller.controller; | ||
|
||
import com.spotify.api.controller.helper.SearchModel; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.impl.client.HttpClientBuilder; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
import static org.apache.http.HttpHeaders.USER_AGENT; | ||
|
||
/** | ||
* Created by Fatih Totrakanli on 31/05/2017. | ||
*/ | ||
|
||
@RestController | ||
@RequestMapping(value = "search") | ||
public class SearchController { | ||
|
||
private static Logger logger = LoggerFactory.getLogger(SearchController.class.getName()); | ||
|
||
@Value("${token}") | ||
private String token; | ||
|
||
@PostMapping(value = "/api") | ||
public StringBuffer searchQ(@RequestBody SearchModel search) throws IOException { | ||
|
||
String query = search.getQuery().equals("") ? "%2B" : search.getQuery().replaceAll("\\s+", "%2B"); | ||
logger.info(query + " search started..."); | ||
|
||
String url = "https://api.spotify.com/v1/search?q=" + query + "&type=track&limit=" + search.getLimit() + "&offset=" + search.getOffset(); | ||
|
||
HttpClient client = HttpClientBuilder.create().build(); | ||
HttpGet request = new HttpGet(url); | ||
|
||
request.addHeader("User-Agent", USER_AGENT); | ||
request.addHeader("Authorization", "Bearer " + token); | ||
request.addHeader("Accept", "application/json"); | ||
HttpResponse response = client.execute(request); | ||
|
||
logger.info("Response Code : " + response.getStatusLine().getStatusCode()); | ||
|
||
if (response.getStatusLine().getStatusCode() == 401) { | ||
String error = "The server did not respond properly. Please check spotify authorization token from application.yml or get new token from (https://developer.spotify.com/web-api/console/get-search-item/)."; | ||
logger.error(error); | ||
throw new RuntimeException(error); | ||
} else { | ||
if (response.getStatusLine().getStatusCode() != 200) | ||
throw new RuntimeException("Something went wrong."); | ||
} | ||
|
||
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); | ||
|
||
StringBuffer result = new StringBuffer(); | ||
String line = ""; | ||
logger.info("Reading response..."); | ||
while ((line = rd.readLine()) != null) { | ||
result.append(line); | ||
} | ||
|
||
logger.info("Reading response completed successfully."); | ||
|
||
return result; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
spotify-api-server/src/main/java/com/spotify/api/controller/helper/CorsFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.spotify.api.controller.helper; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import javax.servlet.*; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Created by Fatih Totrakanli on 31/05/2017. | ||
*/ | ||
|
||
@Component | ||
public class CorsFilter implements Filter { | ||
|
||
|
||
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { | ||
HttpServletResponse response = (HttpServletResponse) res; | ||
response.setHeader("Access-Control-Allow-Origin", "*"); | ||
response.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE"); | ||
response.setHeader("Access-Control-Max-Age", "3600"); | ||
response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type"); | ||
chain.doFilter(req, res); | ||
} | ||
|
||
public void init(FilterConfig filterConfig) { | ||
} | ||
|
||
public void destroy() { | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
spotify-api-server/src/main/java/com/spotify/api/controller/helper/SearchModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.spotify.api.controller.helper; | ||
|
||
/** | ||
* Created by Fatih Totrakanli on 31/05/2017. | ||
*/ | ||
public class SearchModel { | ||
|
||
private String query; | ||
|
||
private int limit = 20; | ||
|
||
private int offset = 0; | ||
|
||
public String getQuery() { | ||
return query; | ||
} | ||
|
||
public void setQuery(String query) { | ||
this.query = query; | ||
} | ||
|
||
public int getOffset() { | ||
return offset; | ||
} | ||
|
||
public void setOffset(int offset) { | ||
this.offset = offset; | ||
} | ||
|
||
public int getLimit() { | ||
return limit; | ||
} | ||
|
||
public void setLimit(int limit) { | ||
this.limit = limit; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
server: | ||
servlet-path: /rest/ | ||
port: 8081 | ||
|
||
token: "BQC_DprHnxDYM3SwDFmL3rb63RuWdwmqmq3sEAXnpNYgf0OcWZcusYIC9eqaGk1t1iJJcyzx1j6LQx5usMrm0cK4NDjiF5_tvajqsbTxHDL6z03GPncnksjGMtp7tAaJbw3SBB1wr0vYurAFnQ" |
38 changes: 38 additions & 0 deletions
38
spotify-api-server/src/test/java/com/spotify/api/AppTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.spotify.api; | ||
|
||
import junit.framework.Test; | ||
import junit.framework.TestCase; | ||
import junit.framework.TestSuite; | ||
|
||
/** | ||
* Unit test for simple App. | ||
*/ | ||
public class AppTest | ||
extends TestCase | ||
{ | ||
/** | ||
* Create the test case | ||
* | ||
* @param testName name of the test case | ||
*/ | ||
public AppTest( String testName ) | ||
{ | ||
super( testName ); | ||
} | ||
|
||
/** | ||
* @return the suite of tests being tested | ||
*/ | ||
public static Test suite() | ||
{ | ||
return new TestSuite( AppTest.class ); | ||
} | ||
|
||
/** | ||
* Rigourous Test :-) | ||
*/ | ||
public void testApp() | ||
{ | ||
assertTrue( true ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# See https://help.github.com/ignore-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
Oops, something went wrong.