-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from gkiko/api-1.1.0
Api 1.1.0
- Loading branch information
Showing
11 changed files
with
135 additions
and
72 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
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
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
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,18 @@ | ||
package ge.kuku.movie.parse.data; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.mashape.unirest.http.Unirest; | ||
|
||
public class OmdbClient { | ||
|
||
private static final String OMDB_API = "http://www.omdbapi.com/"; | ||
|
||
public String getMovieNameById(String imdbId) throws Exception { | ||
String jsonBody = Unirest.get(OMDB_API).queryString("i", imdbId).asString().getBody(); | ||
ObjectMapper mapper = new ObjectMapper(); | ||
JsonNode actualObj = mapper.readTree(jsonBody); | ||
return actualObj.get("Title").asText(); | ||
} | ||
|
||
} |
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
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
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 @@ | ||
import ge.kuku.movie.parse.data.OmdbClient; | ||
|
||
import java.util.Map; | ||
|
||
class FakeOmdbClient extends OmdbClient { | ||
|
||
private static FakeOmdbClient client; | ||
private String nameToReuturn; | ||
|
||
static FakeOmdbClient instance() { | ||
if (client == null) { | ||
client = new FakeOmdbClient(); | ||
} | ||
return client; | ||
} | ||
|
||
@Override | ||
public String getMovieNameById(String id) { | ||
return nameToReuturn; | ||
} | ||
|
||
public void setNameToReturn(String nameToReturn) { | ||
this.nameToReuturn = nameToReturn; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,25 +1,40 @@ | ||
import ge.kuku.movie.parse.core.MovieDo; | ||
import ge.kuku.movie.parse.data.ImoviesEntity; | ||
import ge.kuku.movie.parse.data.Parser; | ||
|
||
import java.util.*; | ||
|
||
public class FakeParser implements Parser { | ||
class FakeParser implements Parser { | ||
|
||
Map inMemory = new HashMap<>(); | ||
private static FakeParser parser; | ||
private Map<String, ImoviesEntity> inMemory; | ||
|
||
static FakeParser instance() { | ||
if (parser == null) { | ||
parser = new FakeParser(); | ||
} | ||
return parser; | ||
} | ||
|
||
private FakeParser() { | ||
inMemory = new HashMap<>(); | ||
} | ||
|
||
@Override | ||
public List parse(String movieName, String imdbId) { | ||
ImoviesEntity val = (ImoviesEntity) inMemory.get(movieName); | ||
if (val == null){ | ||
return Collections.emptyList(); | ||
public List<ImoviesEntity> parse(String movieName, String imdbId) { | ||
List<ImoviesEntity> l = new ArrayList<>(); | ||
|
||
ImoviesEntity val = inMemory.get(movieName); | ||
if (val != null){ | ||
l.add(val); | ||
} | ||
List l = new ArrayList(); | ||
l.add(val); | ||
return l; | ||
} | ||
|
||
public void addItem(String movieName, ImoviesEntity movieDo) { | ||
void addItem(String movieName, ImoviesEntity movieDo) { | ||
inMemory.put(movieName, movieDo); | ||
} | ||
} | ||
|
||
void clear() { | ||
inMemory.clear(); | ||
} | ||
} |
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,19 @@ | ||
import ge.kuku.movie.parse.core.ParserService; | ||
import ge.kuku.movie.parse.data.CompositeParser; | ||
import ge.kuku.movie.parse.data.OmdbClient; | ||
import ge.kuku.movie.parse.data.Parser; | ||
|
||
class FakeParserService extends ParserService { | ||
|
||
@Override | ||
public Parser getParser() { | ||
CompositeParser p = CompositeParser.instance(); | ||
p.add(FakeParser.instance()); | ||
return p; | ||
} | ||
|
||
@Override | ||
public OmdbClient getOmdbClient() { | ||
return FakeOmdbClient.instance(); | ||
} | ||
} |
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