From 212f500f634445409780219ac509d32db998a4f4 Mon Sep 17 00:00:00 2001 From: otopba Date: Wed, 15 Nov 2017 11:39:22 +0300 Subject: [PATCH 1/5] VimeoParser now is public --- library/build.gradle | 6 ++-- library/src/main/AndroidManifest.xml | 8 +++-- .../OnVimeoExtractionListener.java | 2 ++ .../vimeoextractor/VimeoAPIManager.java | 22 +++++++------- .../vimeoextractor/VimeoExtractor.java | 30 +++++++++++-------- .../vimeoextractor/VimeoParser.java | 14 +++++---- .../breedrapps/vimeoextractor/VimeoUser.java | 11 +++++-- .../breedrapps/vimeoextractor/VimeoVideo.java | 16 +++++++--- .../vimeoextractor/VimeoParserTest.java | 2 +- 9 files changed, 70 insertions(+), 41 deletions(-) diff --git a/library/build.gradle b/library/build.gradle index f9a2f04..91a49ad 100755 --- a/library/build.gradle +++ b/library/build.gradle @@ -22,11 +22,11 @@ dependencies { compile 'com.android.support:support-annotations:25.1.0' compile 'com.squareup.okhttp3:okhttp:3.5.0' testCompile 'junit:junit:4.12' - testCompile ('org.powermock:powermock-api-mockito:1.6.2') { + testCompile('org.powermock:powermock-api-mockito:1.6.2') { exclude module: 'hamcrest-core' exclude module: 'objenesis' } - testCompile ('org.powermock:powermock-module-junit4:1.6.2') { + testCompile('org.powermock:powermock-module-junit4:1.6.2') { exclude module: 'hamcrest-core' exclude module: 'objenesis' } @@ -39,7 +39,7 @@ task sourcesJar(type: Jar) { } task javadoc(type: Javadoc) { - failOnError false + failOnError false source = android.sourceSets.main.java.sourceFiles classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) } diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml index e350a1d..e7d71da 100644 --- a/library/src/main/AndroidManifest.xml +++ b/library/src/main/AndroidManifest.xml @@ -1,9 +1,11 @@ - + - diff --git a/library/src/main/java/uk/breedrapps/vimeoextractor/OnVimeoExtractionListener.java b/library/src/main/java/uk/breedrapps/vimeoextractor/OnVimeoExtractionListener.java index 8e84549..47ffa85 100644 --- a/library/src/main/java/uk/breedrapps/vimeoextractor/OnVimeoExtractionListener.java +++ b/library/src/main/java/uk/breedrapps/vimeoextractor/OnVimeoExtractionListener.java @@ -8,12 +8,14 @@ public interface OnVimeoExtractionListener { /** * Returns a {@link VimeoVideo} object relating to the extraction + * * @param video the Vimeo video */ void onSuccess(VimeoVideo video); /** * Returns when an error occurs during extractions + * * @param throwable the error object */ void onFailure(Throwable throwable); diff --git a/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoAPIManager.java b/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoAPIManager.java index 04fec23..572b9f1 100644 --- a/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoAPIManager.java +++ b/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoAPIManager.java @@ -22,8 +22,9 @@ class VimeoAPIManager { /** * Builds an HTTP call to Vimeo, from an identifier, to extract video information + * * @param identifier Vimeo video identifier - * @param referrer Video referrer, null if none present + * @param referrer Video referrer, null if none present * @return an OKHttp3 Call to use asynchronously or otherwise. * @throws IOException If a connection or other error occurs */ @@ -31,29 +32,30 @@ protected Call extractWithIdentifier(@NonNull String identifier, @Nullable Strin String url = String.format(VIMEO_CONFIG_URL, identifier); - if(referrer == null){ + if (referrer == null) { //If no referrer exists, generate from base URL referrer = String.format(VIMEO_URL, identifier); } - OkHttpClient client = new OkHttpClient(); - Request request = new Request.Builder() - .url(url) - .header("Content-Type", "application/json") - .header("Referer", referrer) - .build(); + OkHttpClient client = new OkHttpClient(); + Request request = new Request.Builder() + .url(url) + .header("Content-Type", "application/json") + .header("Referer", referrer) + .build(); - return client.newCall(request); + return client.newCall(request); } /** * Generates an appropriate error for a given response + * * @param response The response that was not successful * @return An Exception based on the HTTP Status code of the response */ protected Throwable getError(Response response) { - switch (response.code()){ + switch (response.code()) { case 404: return new IOException("Video could not be found"); case 403: diff --git a/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoExtractor.java b/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoExtractor.java index 2e76aea..0fa725f 100644 --- a/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoExtractor.java +++ b/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoExtractor.java @@ -12,9 +12,9 @@ /** * A class used to extract Vimeo video information * through an all-digit video identifier or a full video URL. - * + *

* Information includes stream urls, title and duration. - * + *

* See {@link VimeoVideo} for full information available */ public class VimeoExtractor { @@ -22,14 +22,16 @@ public class VimeoExtractor { //Singleton private static VimeoExtractor instance; - private VimeoExtractor(){} + private VimeoExtractor() { + } /** * Get singleton instance of the extractor + * * @return singleton instance */ public static VimeoExtractor getInstance() { - if(instance == null){ + if (instance == null) { instance = new VimeoExtractor(); } return instance; @@ -37,13 +39,14 @@ public static VimeoExtractor getInstance() { /** * Get Video stream information using its identifier + * * @param identifier Non-null numeric video identifier (e.g. 123456) - * @param referrer Video referrer URL. Leaving as null provides referrer as video url by default - * @param listener Callback from extraction + * @param referrer Video referrer URL. Leaving as null provides referrer as video url by default + * @param listener Callback from extraction */ - public void fetchVideoWithIdentifier(@NonNull String identifier, @Nullable String referrer, @NonNull final OnVimeoExtractionListener listener){ + public void fetchVideoWithIdentifier(@NonNull String identifier, @Nullable String referrer, @NonNull final OnVimeoExtractionListener listener) { //If an invalid identifier is entered, throw an error - if(identifier.length() == 0){ + if (identifier.length() == 0) { listener.onFailure(new IllegalArgumentException("Video identifier cannot be empty")); return; } @@ -59,11 +62,11 @@ public void onFailure(Call call, IOException e) { @Override public void onResponse(Call call, Response response) throws IOException { //Check if response is successful - if(response.isSuccessful()) { + if (response.isSuccessful()) { //Generate video object from JSON response VimeoVideo vimeoVideo = new VimeoVideo(response.body().string()); listener.onSuccess(vimeoVideo); - }else{ + } else { //Generate an appropriate error listener.onFailure(manager.getError(response)); } @@ -77,20 +80,21 @@ public void onResponse(Call call, Response response) throws IOException { /** * Get Video stream information from its full URL + * * @param videoURL Video URL * @param referrer Video referrer URL * @param listener Callback from extraction */ - public void fetchVideoWithURL(@NonNull String videoURL, @Nullable String referrer, @NonNull final OnVimeoExtractionListener listener){ + public void fetchVideoWithURL(@NonNull String videoURL, @Nullable String referrer, @NonNull final OnVimeoExtractionListener listener) { //Check for valid URL length - if(videoURL.length() == 0){ + if (videoURL.length() == 0) { listener.onFailure(new IllegalArgumentException("Video URL cannot be empty")); return; } VimeoParser parser = new VimeoParser(videoURL); //Determine if Vimeo URL is valid - if(!parser.isVimeoURLValid()) { + if (!parser.isVimeoURLValid()) { listener.onFailure(new IllegalArgumentException("Vimeo URL is not valid")); return; } diff --git a/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoParser.java b/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoParser.java index e7d61ca..570e54b 100644 --- a/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoParser.java +++ b/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoParser.java @@ -6,35 +6,38 @@ /** * Parser for a given Vimeo Link */ -class VimeoParser { +public class VimeoParser { //Full URL of Vimeo video private String url; /** * Initialise VideoParser with url + * * @param url Vimeo Video url */ - public VimeoParser(@NonNull String url){ + public VimeoParser(@NonNull String url) { this.url = url; } /** * Check if a Vimeo URL has a valid identifier + * * @return true if identifier is valid, false otherwise */ - public boolean isVimeoURLValid(){ + public boolean isVimeoURLValid() { String videoID = getExtractedIdentifier(); return videoID.length() > 0 && TextUtils.isDigitsOnly(videoID); } /** * Get a Vimeo identifier from the url + * * @return Vimeo identifier if found and an empty string otherwise */ - public String getExtractedIdentifier(){ + public String getExtractedIdentifier() { String[] urlParts = url.split("/"); - if(urlParts.length == 0){ + if (urlParts.length == 0) { return ""; } return urlParts[urlParts.length - 1]; @@ -42,6 +45,7 @@ public String getExtractedIdentifier(){ /** * Get the URL stored by parser + * * @return the url */ public String getUrl() { diff --git a/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoUser.java b/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoUser.java index ef87a45..48a367d 100644 --- a/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoUser.java +++ b/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoUser.java @@ -28,9 +28,10 @@ public class VimeoUser { // User Id private long id; - private VimeoUser(){} + private VimeoUser() { + } - VimeoUser(JSONObject userObject){ + VimeoUser(JSONObject userObject) { this.accountType = userObject.optString("account_type"); this.name = userObject.optString("name"); this.imageUrl = userObject.optString("img"); @@ -41,6 +42,7 @@ private VimeoUser(){} /** * Get account type of user - e.g. plus, basic + * * @return Account type of user */ public String getAccountType() { @@ -49,6 +51,7 @@ public String getAccountType() { /** * Get full name of user + * * @return Name of user */ public String getName() { @@ -57,6 +60,7 @@ public String getName() { /** * Profile image of user + * * @return Image url */ public String getImageUrl() { @@ -65,6 +69,7 @@ public String getImageUrl() { /** * Larger profile image of user + * * @return HQ image url */ public String getImage2xUrl() { @@ -73,6 +78,7 @@ public String getImage2xUrl() { /** * Profile URL of the user + * * @return url of profile */ public String getUrl() { @@ -81,6 +87,7 @@ public String getUrl() { /** * Get the Vimeo assigned ID for the user + * * @return id for user */ public long getId() { diff --git a/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoVideo.java b/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoVideo.java index 10579aa..7dfe357 100644 --- a/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoVideo.java +++ b/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoVideo.java @@ -28,7 +28,7 @@ public class VimeoVideo { private VimeoUser videoUser; //Initialise VimeoVideo from JSON - protected VimeoVideo(@NonNull String json){ + protected VimeoVideo(@NonNull String json) { streams = new HashMap<>(); thumbs = new HashMap<>(); parseJson(json); @@ -51,7 +51,7 @@ private void parseJson(String json) { //Get thumbnail information JSONObject thumbsInfo = videoInfo.getJSONObject("thumbs"); Iterator iterator; - for(iterator = thumbsInfo.keys(); iterator.hasNext();) { + for (iterator = thumbsInfo.keys(); iterator.hasNext(); ) { String key = iterator.next(); this.thumbs.put(key, thumbsInfo.getString(key)); } @@ -77,6 +77,7 @@ private void parseJson(String json) { /** * Video title + * * @return the video title */ public String getTitle() { @@ -85,6 +86,7 @@ public String getTitle() { /** * Video duration in seconds + * * @return the video duration */ public long getDuration() { @@ -93,17 +95,19 @@ public long getDuration() { /** * Check if given video has stream information + * * @return true if information is present, false otherwise */ - public boolean hasStreams(){ + public boolean hasStreams() { return streams.size() > 0; } /** * Check if video has HD stream available + * * @return true if 1080 or 4096p streams are available, false otherwise */ - public boolean isHD(){ + public boolean isHD() { return streams.containsKey("1080p") || streams.containsKey("4096p"); } @@ -111,6 +115,7 @@ public boolean isHD(){ * Get stream information in the form of a key-value map. * Keys are the quality information of the stream (e.g. 1080p) * Values are the corresponding stream URL + * * @return Map of streams for video */ public Map getStreams() { @@ -119,6 +124,7 @@ public Map getStreams() { /** * Check if video has associated thumbnails + * * @return true if thumbnails are present; false otherwise */ public boolean hasThumbs() { @@ -130,6 +136,7 @@ public boolean hasThumbs() { * Keys are the quality information of the thumbnail (e.g. base, 640, 1280) * The default key returned from Vimeo's API is "base" * Values are the corresponding thumbnail image URL + * * @return Map of available thumbnails for video */ public Map getThumbs() { @@ -138,6 +145,7 @@ public Map getThumbs() { /** * Get information on the user that created / uploaded the video + * * @return VimeoUser object containing information on the user */ public VimeoUser getVideoUser() { diff --git a/library/src/test/java/uk/breedrapps/vimeoextractor/VimeoParserTest.java b/library/src/test/java/uk/breedrapps/vimeoextractor/VimeoParserTest.java index e8eb2b2..d62dfd9 100644 --- a/library/src/test/java/uk/breedrapps/vimeoextractor/VimeoParserTest.java +++ b/library/src/test/java/uk/breedrapps/vimeoextractor/VimeoParserTest.java @@ -27,7 +27,7 @@ public class VimeoParserTest { private VimeoParser validParser, invalidParser; @Before - public void setUp() throws Exception{ + public void setUp() throws Exception { //Create parsers for a valid and an invalid Vimeo URL validParser = new VimeoParser("http://vimeo.com/12345"); invalidParser = new VimeoParser("http://vimeo.com/foo"); From 46277a8def4577741dd92b7f573efa6eec2fe9cd Mon Sep 17 00:00:00 2001 From: otopba Date: Thu, 30 Nov 2017 14:18:53 +0300 Subject: [PATCH 2/5] public VimeoParser --- .../src/main/java/uk/breedrapps/vimeoextractor/VimeoParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoParser.java b/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoParser.java index e7d61ca..1db9f87 100644 --- a/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoParser.java +++ b/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoParser.java @@ -6,7 +6,7 @@ /** * Parser for a given Vimeo Link */ -class VimeoParser { +public class VimeoParser { //Full URL of Vimeo video private String url; From 364584d444a01624e1cf5f043ad9650e8600002f Mon Sep 17 00:00:00 2001 From: otopba Date: Thu, 30 Nov 2017 14:21:41 +0300 Subject: [PATCH 3/5] Revert "public VimeoParser" This reverts commit 46277a8def4577741dd92b7f573efa6eec2fe9cd. --- .../src/main/java/uk/breedrapps/vimeoextractor/VimeoParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoParser.java b/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoParser.java index 570e54b..0d8f325 100644 --- a/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoParser.java +++ b/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoParser.java @@ -6,7 +6,7 @@ /** * Parser for a given Vimeo Link */ -public class VimeoParser { +class VimeoParser { //Full URL of Vimeo video private String url; From de7b3805dd27ecfbfb4b0eebaf209ab06d13c760 Mon Sep 17 00:00:00 2001 From: otopba Date: Thu, 30 Nov 2017 14:23:12 +0300 Subject: [PATCH 4/5] Revert "VimeoParser now is public" This reverts commit 212f500f634445409780219ac509d32db998a4f4. --- library/build.gradle | 6 ++-- library/src/main/AndroidManifest.xml | 8 ++--- .../OnVimeoExtractionListener.java | 2 -- .../vimeoextractor/VimeoAPIManager.java | 22 +++++++------- .../vimeoextractor/VimeoExtractor.java | 30 ++++++++----------- .../vimeoextractor/VimeoParser.java | 12 +++----- .../breedrapps/vimeoextractor/VimeoUser.java | 11 ++----- .../breedrapps/vimeoextractor/VimeoVideo.java | 16 +++------- .../vimeoextractor/VimeoParserTest.java | 2 +- 9 files changed, 40 insertions(+), 69 deletions(-) diff --git a/library/build.gradle b/library/build.gradle index 91a49ad..f9a2f04 100755 --- a/library/build.gradle +++ b/library/build.gradle @@ -22,11 +22,11 @@ dependencies { compile 'com.android.support:support-annotations:25.1.0' compile 'com.squareup.okhttp3:okhttp:3.5.0' testCompile 'junit:junit:4.12' - testCompile('org.powermock:powermock-api-mockito:1.6.2') { + testCompile ('org.powermock:powermock-api-mockito:1.6.2') { exclude module: 'hamcrest-core' exclude module: 'objenesis' } - testCompile('org.powermock:powermock-module-junit4:1.6.2') { + testCompile ('org.powermock:powermock-module-junit4:1.6.2') { exclude module: 'hamcrest-core' exclude module: 'objenesis' } @@ -39,7 +39,7 @@ task sourcesJar(type: Jar) { } task javadoc(type: Javadoc) { - failOnError false + failOnError false source = android.sourceSets.main.java.sourceFiles classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) } diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml index e7d71da..e350a1d 100644 --- a/library/src/main/AndroidManifest.xml +++ b/library/src/main/AndroidManifest.xml @@ -1,11 +1,9 @@ - + - diff --git a/library/src/main/java/uk/breedrapps/vimeoextractor/OnVimeoExtractionListener.java b/library/src/main/java/uk/breedrapps/vimeoextractor/OnVimeoExtractionListener.java index 47ffa85..8e84549 100644 --- a/library/src/main/java/uk/breedrapps/vimeoextractor/OnVimeoExtractionListener.java +++ b/library/src/main/java/uk/breedrapps/vimeoextractor/OnVimeoExtractionListener.java @@ -8,14 +8,12 @@ public interface OnVimeoExtractionListener { /** * Returns a {@link VimeoVideo} object relating to the extraction - * * @param video the Vimeo video */ void onSuccess(VimeoVideo video); /** * Returns when an error occurs during extractions - * * @param throwable the error object */ void onFailure(Throwable throwable); diff --git a/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoAPIManager.java b/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoAPIManager.java index 572b9f1..04fec23 100644 --- a/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoAPIManager.java +++ b/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoAPIManager.java @@ -22,9 +22,8 @@ class VimeoAPIManager { /** * Builds an HTTP call to Vimeo, from an identifier, to extract video information - * * @param identifier Vimeo video identifier - * @param referrer Video referrer, null if none present + * @param referrer Video referrer, null if none present * @return an OKHttp3 Call to use asynchronously or otherwise. * @throws IOException If a connection or other error occurs */ @@ -32,30 +31,29 @@ protected Call extractWithIdentifier(@NonNull String identifier, @Nullable Strin String url = String.format(VIMEO_CONFIG_URL, identifier); - if (referrer == null) { + if(referrer == null){ //If no referrer exists, generate from base URL referrer = String.format(VIMEO_URL, identifier); } - OkHttpClient client = new OkHttpClient(); - Request request = new Request.Builder() - .url(url) - .header("Content-Type", "application/json") - .header("Referer", referrer) - .build(); + OkHttpClient client = new OkHttpClient(); + Request request = new Request.Builder() + .url(url) + .header("Content-Type", "application/json") + .header("Referer", referrer) + .build(); - return client.newCall(request); + return client.newCall(request); } /** * Generates an appropriate error for a given response - * * @param response The response that was not successful * @return An Exception based on the HTTP Status code of the response */ protected Throwable getError(Response response) { - switch (response.code()) { + switch (response.code()){ case 404: return new IOException("Video could not be found"); case 403: diff --git a/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoExtractor.java b/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoExtractor.java index 0fa725f..2e76aea 100644 --- a/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoExtractor.java +++ b/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoExtractor.java @@ -12,9 +12,9 @@ /** * A class used to extract Vimeo video information * through an all-digit video identifier or a full video URL. - *

+ * * Information includes stream urls, title and duration. - *

+ * * See {@link VimeoVideo} for full information available */ public class VimeoExtractor { @@ -22,16 +22,14 @@ public class VimeoExtractor { //Singleton private static VimeoExtractor instance; - private VimeoExtractor() { - } + private VimeoExtractor(){} /** * Get singleton instance of the extractor - * * @return singleton instance */ public static VimeoExtractor getInstance() { - if (instance == null) { + if(instance == null){ instance = new VimeoExtractor(); } return instance; @@ -39,14 +37,13 @@ public static VimeoExtractor getInstance() { /** * Get Video stream information using its identifier - * * @param identifier Non-null numeric video identifier (e.g. 123456) - * @param referrer Video referrer URL. Leaving as null provides referrer as video url by default - * @param listener Callback from extraction + * @param referrer Video referrer URL. Leaving as null provides referrer as video url by default + * @param listener Callback from extraction */ - public void fetchVideoWithIdentifier(@NonNull String identifier, @Nullable String referrer, @NonNull final OnVimeoExtractionListener listener) { + public void fetchVideoWithIdentifier(@NonNull String identifier, @Nullable String referrer, @NonNull final OnVimeoExtractionListener listener){ //If an invalid identifier is entered, throw an error - if (identifier.length() == 0) { + if(identifier.length() == 0){ listener.onFailure(new IllegalArgumentException("Video identifier cannot be empty")); return; } @@ -62,11 +59,11 @@ public void onFailure(Call call, IOException e) { @Override public void onResponse(Call call, Response response) throws IOException { //Check if response is successful - if (response.isSuccessful()) { + if(response.isSuccessful()) { //Generate video object from JSON response VimeoVideo vimeoVideo = new VimeoVideo(response.body().string()); listener.onSuccess(vimeoVideo); - } else { + }else{ //Generate an appropriate error listener.onFailure(manager.getError(response)); } @@ -80,21 +77,20 @@ public void onResponse(Call call, Response response) throws IOException { /** * Get Video stream information from its full URL - * * @param videoURL Video URL * @param referrer Video referrer URL * @param listener Callback from extraction */ - public void fetchVideoWithURL(@NonNull String videoURL, @Nullable String referrer, @NonNull final OnVimeoExtractionListener listener) { + public void fetchVideoWithURL(@NonNull String videoURL, @Nullable String referrer, @NonNull final OnVimeoExtractionListener listener){ //Check for valid URL length - if (videoURL.length() == 0) { + if(videoURL.length() == 0){ listener.onFailure(new IllegalArgumentException("Video URL cannot be empty")); return; } VimeoParser parser = new VimeoParser(videoURL); //Determine if Vimeo URL is valid - if (!parser.isVimeoURLValid()) { + if(!parser.isVimeoURLValid()) { listener.onFailure(new IllegalArgumentException("Vimeo URL is not valid")); return; } diff --git a/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoParser.java b/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoParser.java index 0d8f325..e7d61ca 100644 --- a/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoParser.java +++ b/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoParser.java @@ -13,31 +13,28 @@ class VimeoParser { /** * Initialise VideoParser with url - * * @param url Vimeo Video url */ - public VimeoParser(@NonNull String url) { + public VimeoParser(@NonNull String url){ this.url = url; } /** * Check if a Vimeo URL has a valid identifier - * * @return true if identifier is valid, false otherwise */ - public boolean isVimeoURLValid() { + public boolean isVimeoURLValid(){ String videoID = getExtractedIdentifier(); return videoID.length() > 0 && TextUtils.isDigitsOnly(videoID); } /** * Get a Vimeo identifier from the url - * * @return Vimeo identifier if found and an empty string otherwise */ - public String getExtractedIdentifier() { + public String getExtractedIdentifier(){ String[] urlParts = url.split("/"); - if (urlParts.length == 0) { + if(urlParts.length == 0){ return ""; } return urlParts[urlParts.length - 1]; @@ -45,7 +42,6 @@ public String getExtractedIdentifier() { /** * Get the URL stored by parser - * * @return the url */ public String getUrl() { diff --git a/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoUser.java b/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoUser.java index 48a367d..ef87a45 100644 --- a/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoUser.java +++ b/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoUser.java @@ -28,10 +28,9 @@ public class VimeoUser { // User Id private long id; - private VimeoUser() { - } + private VimeoUser(){} - VimeoUser(JSONObject userObject) { + VimeoUser(JSONObject userObject){ this.accountType = userObject.optString("account_type"); this.name = userObject.optString("name"); this.imageUrl = userObject.optString("img"); @@ -42,7 +41,6 @@ private VimeoUser() { /** * Get account type of user - e.g. plus, basic - * * @return Account type of user */ public String getAccountType() { @@ -51,7 +49,6 @@ public String getAccountType() { /** * Get full name of user - * * @return Name of user */ public String getName() { @@ -60,7 +57,6 @@ public String getName() { /** * Profile image of user - * * @return Image url */ public String getImageUrl() { @@ -69,7 +65,6 @@ public String getImageUrl() { /** * Larger profile image of user - * * @return HQ image url */ public String getImage2xUrl() { @@ -78,7 +73,6 @@ public String getImage2xUrl() { /** * Profile URL of the user - * * @return url of profile */ public String getUrl() { @@ -87,7 +81,6 @@ public String getUrl() { /** * Get the Vimeo assigned ID for the user - * * @return id for user */ public long getId() { diff --git a/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoVideo.java b/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoVideo.java index 7dfe357..10579aa 100644 --- a/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoVideo.java +++ b/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoVideo.java @@ -28,7 +28,7 @@ public class VimeoVideo { private VimeoUser videoUser; //Initialise VimeoVideo from JSON - protected VimeoVideo(@NonNull String json) { + protected VimeoVideo(@NonNull String json){ streams = new HashMap<>(); thumbs = new HashMap<>(); parseJson(json); @@ -51,7 +51,7 @@ private void parseJson(String json) { //Get thumbnail information JSONObject thumbsInfo = videoInfo.getJSONObject("thumbs"); Iterator iterator; - for (iterator = thumbsInfo.keys(); iterator.hasNext(); ) { + for(iterator = thumbsInfo.keys(); iterator.hasNext();) { String key = iterator.next(); this.thumbs.put(key, thumbsInfo.getString(key)); } @@ -77,7 +77,6 @@ private void parseJson(String json) { /** * Video title - * * @return the video title */ public String getTitle() { @@ -86,7 +85,6 @@ public String getTitle() { /** * Video duration in seconds - * * @return the video duration */ public long getDuration() { @@ -95,19 +93,17 @@ public long getDuration() { /** * Check if given video has stream information - * * @return true if information is present, false otherwise */ - public boolean hasStreams() { + public boolean hasStreams(){ return streams.size() > 0; } /** * Check if video has HD stream available - * * @return true if 1080 or 4096p streams are available, false otherwise */ - public boolean isHD() { + public boolean isHD(){ return streams.containsKey("1080p") || streams.containsKey("4096p"); } @@ -115,7 +111,6 @@ public boolean isHD() { * Get stream information in the form of a key-value map. * Keys are the quality information of the stream (e.g. 1080p) * Values are the corresponding stream URL - * * @return Map of streams for video */ public Map getStreams() { @@ -124,7 +119,6 @@ public Map getStreams() { /** * Check if video has associated thumbnails - * * @return true if thumbnails are present; false otherwise */ public boolean hasThumbs() { @@ -136,7 +130,6 @@ public boolean hasThumbs() { * Keys are the quality information of the thumbnail (e.g. base, 640, 1280) * The default key returned from Vimeo's API is "base" * Values are the corresponding thumbnail image URL - * * @return Map of available thumbnails for video */ public Map getThumbs() { @@ -145,7 +138,6 @@ public Map getThumbs() { /** * Get information on the user that created / uploaded the video - * * @return VimeoUser object containing information on the user */ public VimeoUser getVideoUser() { diff --git a/library/src/test/java/uk/breedrapps/vimeoextractor/VimeoParserTest.java b/library/src/test/java/uk/breedrapps/vimeoextractor/VimeoParserTest.java index d62dfd9..e8eb2b2 100644 --- a/library/src/test/java/uk/breedrapps/vimeoextractor/VimeoParserTest.java +++ b/library/src/test/java/uk/breedrapps/vimeoextractor/VimeoParserTest.java @@ -27,7 +27,7 @@ public class VimeoParserTest { private VimeoParser validParser, invalidParser; @Before - public void setUp() throws Exception { + public void setUp() throws Exception{ //Create parsers for a valid and an invalid Vimeo URL validParser = new VimeoParser("http://vimeo.com/12345"); invalidParser = new VimeoParser("http://vimeo.com/foo"); From 34e416f8c25def6db67ffdce34f897adf0ffb6ed Mon Sep 17 00:00:00 2001 From: otopba Date: Thu, 30 Nov 2017 14:23:35 +0300 Subject: [PATCH 5/5] public VimeoParser --- .../src/main/java/uk/breedrapps/vimeoextractor/VimeoParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoParser.java b/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoParser.java index e7d61ca..1db9f87 100644 --- a/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoParser.java +++ b/library/src/main/java/uk/breedrapps/vimeoextractor/VimeoParser.java @@ -6,7 +6,7 @@ /** * Parser for a given Vimeo Link */ -class VimeoParser { +public class VimeoParser { //Full URL of Vimeo video private String url;