-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding helper classes to consume Twistage import API and ingesting si…
…gnature
- Loading branch information
1 parent
388e4d8
commit cc83eab
Showing
4 changed files
with
114 additions
and
3 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
61 changes: 61 additions & 0 deletions
61
src/main/java/com/hyland/webhook/helper/AuthenticationHelper.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,61 @@ | ||
package com.hyland.webhook.helper; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
|
||
public class AuthenticationHelper { | ||
|
||
private AuthenticationHelper(){ | ||
} | ||
|
||
protected static String getViewSignature(String licenseKey) { | ||
return fetch ("https://indiaservice.twistage.com/api/view_key?licenseKey=" + | ||
licenseKey).trim(); | ||
} | ||
|
||
protected static String getIngestSignature(String licenseKey, String contributor, String library) { | ||
return fetch ("https://indiaservice.twistage.com/api/ingest_key?licenseKey=" + | ||
licenseKey + "&contributor=" + contributor + "&library_id=" + library).trim(); | ||
} | ||
|
||
protected static String fetch(String url) { | ||
try { | ||
Object content = createUrl(url).getContent(); | ||
if (content instanceof String) { | ||
return (String) content; | ||
} else if (content instanceof InputStream) { | ||
return getInputStreamContents((InputStream) content); | ||
} else { | ||
throw new RuntimeException ("Unexpected content returned from URL: " + | ||
content.toString()); | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException (e); | ||
} | ||
} | ||
|
||
protected static URL createUrl(String url) { | ||
try { | ||
return new URL(url); | ||
} catch (MalformedURLException e) { | ||
throw new RuntimeException (e); | ||
} | ||
} | ||
|
||
protected static String getInputStreamContents(InputStream inputStream) throws IOException { | ||
StringBuilder contents = new StringBuilder(); | ||
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream))) { | ||
String line = null; | ||
while ((line = bufferedReader.readLine()) != null) { | ||
contents.append(line); | ||
contents.append(System.getProperty("line.separator")); | ||
} | ||
} | ||
return contents.toString(); | ||
} | ||
|
||
} |
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,46 @@ | ||
package com.hyland.webhook.helper; | ||
|
||
import java.io.*; | ||
import java.net.HttpURLConnection; | ||
|
||
import static com.hyland.webhook.helper.AuthenticationHelper.*; | ||
|
||
public class ImportHelper { | ||
|
||
protected String upload (String licenseKey, String contributor, String library, | ||
String pathOfXmlFile) | ||
throws IOException { | ||
|
||
String xml = getInputStreamContents (new FileInputStream(new File (pathOfXmlFile))); | ||
|
||
String auth = getIngestSignature(licenseKey, contributor, library); | ||
|
||
String url = "https://indiaservice.twistage.com/videos/create_many?signature=" + auth; | ||
|
||
InputStream inputStream = new ByteArrayInputStream(xml.getBytes()); | ||
|
||
HttpURLConnection conn = (HttpURLConnection) createUrl(url).openConnection(); | ||
|
||
conn.setDoInput (true); | ||
conn.setDoOutput (true); | ||
conn.setUseCaches (false); | ||
|
||
conn.setRequestMethod("POST"); | ||
conn.setRequestProperty("Content-Type", "text/xml"); | ||
|
||
BufferedInputStream bufferedInput = new BufferedInputStream(inputStream); | ||
BufferedOutputStream bufferedOutput = new BufferedOutputStream(conn.getOutputStream()); | ||
|
||
int nextByte; | ||
while ((nextByte = bufferedInput.read ()) != -1) { | ||
bufferedOutput.write (nextByte); | ||
} | ||
|
||
bufferedOutput.flush (); | ||
bufferedOutput.close (); | ||
|
||
// read the server's response | ||
return getInputStreamContents (conn.getInputStream()); | ||
} | ||
|
||
} |
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,3 +1,4 @@ | ||
zoom.verification.token=pZwChq6bS5KstopcfycnDA | ||
logging.level.org.springframework.security: DEBUG | ||
logging.level.org.springframework.security= DEBUG | ||
twistage.api.licenseKey=2f5752b1a0d1a | ||
|