This repository has been archived by the owner on Jan 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
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
Showing
21 changed files
with
307 additions
and
271 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
35 changes: 35 additions & 0 deletions
35
app/src/main/java/subreddit/android/appstore/backend/HttpModule.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,35 @@ | ||
package subreddit.android.appstore.backend; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
|
||
import dagger.Module; | ||
import dagger.Provides; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.logging.HttpLoggingInterceptor; | ||
import subreddit.android.appstore.BuildConfig; | ||
import subreddit.android.appstore.util.dagger.ApplicationScope; | ||
|
||
@Module | ||
public class HttpModule { | ||
|
||
@Provides | ||
@ApplicationScope | ||
Gson provideGson() { | ||
return new GsonBuilder().create(); | ||
} | ||
|
||
@Provides | ||
@ApplicationScope | ||
OkHttpClient provideOkHttpClient(UserAgentInterceptor userAgent) { | ||
OkHttpClient.Builder builder = new OkHttpClient.Builder(); | ||
if (BuildConfig.DEBUG) { | ||
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); | ||
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); | ||
builder.addInterceptor(interceptor); | ||
} | ||
builder.addInterceptor(userAgent); | ||
return builder.build(); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
app/src/main/java/subreddit/android/appstore/backend/github/GithubApi.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 subreddit.android.appstore.backend.github; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import io.reactivex.Observable; | ||
import retrofit2.http.GET; | ||
|
||
public interface GithubApi { | ||
String BASEURL = "https://api.github.com/"; | ||
|
||
@GET("repos/d4rken/reddit-android-appstore/releases/latest") | ||
Observable<Release> getLatestRelease(); | ||
|
||
@GET("repos/d4rken/reddit-android-appstore/contributors") | ||
Observable<List<Contributor>> getContributors(); | ||
|
||
class Release { | ||
@SerializedName("url") public String releaseUrl; | ||
@SerializedName("tag_name") public String tagName; | ||
@SerializedName("name") public String releaseName; | ||
@SerializedName("body") public String releaseDescription; | ||
public boolean prerelease; | ||
@SerializedName("published_at") public Date publishDate; | ||
public List<Assets> assets; | ||
|
||
public static class Assets { | ||
@SerializedName("browser_download_url") public String downloadUrl; | ||
public long size; | ||
} | ||
} | ||
|
||
class Contributor { | ||
@SerializedName("login") public String username; | ||
} | ||
} |
26 changes: 2 additions & 24 deletions
26
app/src/main/java/subreddit/android/appstore/backend/github/GithubRepository.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 |
---|---|---|
@@ -1,34 +1,12 @@ | ||
package subreddit.android.appstore.backend.github; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import io.reactivex.Observable; | ||
|
||
public interface GithubRepository { | ||
|
||
Observable<Release> getLatestRelease(); | ||
Observable<List<Contributor>> getContributors(); | ||
|
||
class Release { | ||
@SerializedName("url") public String releaseUrl; | ||
@SerializedName("tag_name") public String tagName; | ||
@SerializedName("name") public String releaseName; | ||
@SerializedName("body") public String releaseDescription; | ||
public boolean prerelease; | ||
@SerializedName("published_at") public Date publishDate; | ||
public List<Assets> assets; | ||
|
||
public static class Assets { | ||
@SerializedName("browser_download_url") public String downloadUrl; | ||
public long size; | ||
} | ||
} | ||
|
||
class Contributor { | ||
@SerializedName("login") public String username; | ||
} | ||
Observable<GithubApi.Release> getLatestRelease(); | ||
Observable<List<GithubApi.Contributor>> getContributors(); | ||
|
||
} |
44 changes: 6 additions & 38 deletions
44
app/src/main/java/subreddit/android/appstore/backend/github/LiveGithubRepository.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
19 changes: 0 additions & 19 deletions
19
app/src/main/java/subreddit/android/appstore/backend/reddit/Token.java
This file was deleted.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
app/src/main/java/subreddit/android/appstore/backend/reddit/TokenApi.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,35 @@ | ||
package subreddit.android.appstore.backend.reddit; | ||
|
||
|
||
import io.reactivex.Observable; | ||
import retrofit2.http.Field; | ||
import retrofit2.http.FormUrlEncoded; | ||
import retrofit2.http.Header; | ||
import retrofit2.http.POST; | ||
|
||
public interface TokenApi { | ||
String BASEURL = "https://www.reddit.com/"; | ||
|
||
@FormUrlEncoded | ||
@POST("api/v1/access_token") | ||
Observable<TokenApi.Token> getUserlessAuthToken(@Header("Authorization") String authentication, | ||
@Field("device_id") String deviceId, | ||
@Field("grant_type") String grant_type, | ||
@Field("scope") String scope); | ||
|
||
class Token { | ||
String access_token; | ||
String token_type; | ||
long expires_in; | ||
String scope; | ||
final long issuedTime = System.currentTimeMillis(); | ||
|
||
public boolean isExpired() { | ||
return System.currentTimeMillis() > issuedTime + expires_in * 1000; | ||
} | ||
|
||
public String getAuthorizationString() { | ||
return token_type + " " + access_token; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.