Skip to content

Prepare Android Header #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Feb 3, 2022
Merged

Prepare Android Header #81

merged 19 commits into from
Feb 3, 2022

Conversation

cdr-chakotay
Copy link
Contributor

Prepare sending of additional SDK information with the Transloadit Client Header.
e.G. if you are using the Android SDK.
See issue in the Android SDK

@cdr-chakotay cdr-chakotay added enhancement sdks Integrations for Transloadit's API labels Jan 12, 2022
@cdr-chakotay cdr-chakotay requested a review from Acconut January 12, 2022 00:58
Copy link
Member

@Acconut Acconut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the quick PR! This is a bit more complex than I anticipated, in particular the validation part. I am wondering if we actually need that. Wouldn't it be sufficient to allow setting a string, which then gets appended to the Transloadit-Client header?

The implementation I had in mind when we talked about it, looks a bit like this:

  • The Transloadit constructor parses the version.properties file obtain the current version (we can simply move this code from the Request class into Transloadit for that:
    InputStream in = getClass().getClassLoader().getResourceAsStream("version.properties");
    try {
    prop.load(in);
    version = "java-sdk:" + prop.getProperty("versionNumber").replace("'", "");
    in.close();
    } catch (IOException e) {
    throw new RuntimeException(e);
    } catch (NullPointerException npe) {
    version = "java-sdk:unknown";
    }
    In general, I don´t think the Request class is the correct spot for this)
  • The Transloadit class also has an appendVersionInformation(String) (or something similar) were the Android SDK can append its version.
  • The Transloadit class also has a String getVersionInformation() method, which is used by the Request class to get the full value for Transloadit-Client.
  • We can also think about making the last two methods protected, so not everyone but rather the AndroidTransloadit subclass can change that information. It's not fully protected against modifications that way, but this is not important.

@cdr-chakotay
Copy link
Contributor Author

Thank you for the quick PR! This is a bit more complex than I anticipated, in particular the validation part. I am wondering if we actually need that. Wouldn't it be sufficient to allow setting a string, which then gets appended to the Transloadit-Client header?

The implementation I had in mind when we talked about it, looks a bit like this:

  • The Transloadit constructor parses the version.properties file obtain the current version (we can simply move this code from the Request class into Transloadit for that:
    InputStream in = getClass().getClassLoader().getResourceAsStream("version.properties");
    try {
    prop.load(in);
    version = "java-sdk:" + prop.getProperty("versionNumber").replace("'", "");
    in.close();
    } catch (IOException e) {
    throw new RuntimeException(e);
    } catch (NullPointerException npe) {
    version = "java-sdk:unknown";
    }

    In general, I don´t think the Request class is the correct spot for this)
  • The Transloadit class also has an appendVersionInformation(String) (or something similar) were the Android SDK can append its version.
  • The Transloadit class also has a String getVersionInformation() method, which is used by the Request class to get the full value for Transloadit-Client.
  • We can also think about making the last two methods protected, so not everyone but rather the AndroidTransloadit subclass can change that information. It's not fully protected against modifications that way, but this is not important.

Sounds good, I am not done anyway. So I will try to follow your suggestions :)
Regarding the validation part: Yes it is a little more complicated, but it preserves some uniformity :)

@cdr-chakotay cdr-chakotay marked this pull request as ready for review January 12, 2022 16:51
@cdr-chakotay
Copy link
Contributor Author

We may need to release this in order to use it in the Android-SDK

@cdr-chakotay cdr-chakotay requested a review from Acconut January 13, 2022 13:38
@Acconut
Copy link
Member

Acconut commented Jan 28, 2022

Apologies for my delayed response! I just had another idea how we could simplify this version handling even further: What if, instead of having a getter/setter for additionalTransloaditClientHeaderContent, we only have the protected loadVersionInfo method. The Android SDK then overwrites this method to include its version information. Something like this:

// Java SDK
class Transloadit {
  private String versionInfo;
  
  constructor() {
    this.versionInfo = loadVersionInfo();
  }
  
  prototected String loadVersionInfo() {
    // Load from version.properties file...
    return ...;
  }
  
  // This method is package-private so only the Request class can access it.
  String getVersionInfo() {
    return this.versionInfo;
  }
}

class Request {
  constructor() {
    transloadit.getVersionInfo();
    ...
  }
}

// Android SDK
class AndroidTransloadit extends Transloadit {
  @Overwrite
  protected String loadVersionInfo() {
    // Load from version.properties for Android SDK...
    // Combine version from parent class and from Android SDK
    return super.loadVersionInfo() + androidVersionInfo;
  }
}

Hopefully that approach is understandable for you. The benefit is that we have no getter/setters (no code is the best code) and the version.properties files are only accessed once when the client is initialized and not for every request being sent.

In addition, I would remove the version number validation as it could pose a problem in the future. Imagine we want to make a pre-release version v1.2.3-pre1 for the Android SDK. The validation will not accept this and throw an error, causing the entire SDK to not work.

What do you think?

@cdr-chakotay
Copy link
Contributor Author

Can do this :) sounds good !

I'll try that by chance

@cdr-chakotay
Copy link
Contributor Author

@Acconut have implemented it according to the proposal.
You can find the corresponding Android SDK counterpart here:
https://github.com/transloadit/android-sdk/pull/11

Copy link
Member

@Acconut Acconut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work! Thanks for the quick turnaround! The test is failing. Could you briefly look into that? If we determine it unrelated or you fixed it, we can merge this baby :)

…fix jUnit test, which obtained the version.properties file from the tus library
@cdr-chakotay
Copy link
Contributor Author

I am willing to merge this and release it as 0.4.2 :) Than we can add this dependency to the android SDK as well and are done with the headers 👍🏻 @Acconut

@cdr-chakotay cdr-chakotay requested a review from Acconut January 29, 2022 22:41
@Acconut
Copy link
Member

Acconut commented Feb 3, 2022

Awesome work! Thank you very much!

@Acconut Acconut merged commit 17823ed into master Feb 3, 2022
@Acconut Acconut deleted the PrepareAndroidHeader branch February 3, 2022 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement sdks Integrations for Transloadit's API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants