-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#12 - prepare RxJava Retrofit call for sending absences to Mysql server
- Loading branch information
Showing
5 changed files
with
217 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
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
108 changes: 108 additions & 0 deletions
108
app/src/main/java/com/eusecom/attendance/retrofit/RfEtestApi.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,108 @@ | ||
package com.eusecom.attendance.retrofit; | ||
|
||
import java.util.List; | ||
|
||
import io.reactivex.Observable; | ||
import retrofit2.http.Field; | ||
import retrofit2.http.FormUrlEncoded; | ||
import retrofit2.http.GET; | ||
import retrofit2.http.Path; | ||
import retrofit2.http.Query; | ||
|
||
/* | ||
<?php | ||
//read headers | ||
$headerStringValue=""; | ||
$headers = apache_request_headers(); | ||
foreach ($headers as $header => $value) { | ||
$headerStringValue = " ".$headerStringValue.$value." "; | ||
} | ||
$user = $_GET['user']; | ||
$sqlt = <<<ico | ||
{ | ||
"login": "JakeWharton", | ||
"id": 66577, | ||
"avatar_url": "https://avatars3.githubusercontent.com/u/66577?v=3", | ||
"gravatar_id": "", | ||
"url": "https://api.github.com/users/JakeWharton", | ||
"html_url": "https://github.com/JakeWharton", | ||
"followers_url": "https://api.github.com/users/JakeWharton/followers", | ||
"following_url": "https://api.github.com/users/JakeWharton/following{/other_user}", | ||
"gists_url": "https://api.github.com/users/JakeWharton/gists{/gist_id}", | ||
"starred_url": "https://api.github.com/users/JakeWharton/starred{/owner}{/repo}", | ||
"subscriptions_url": "https://api.github.com/users/JakeWharton/subscriptions", | ||
"organizations_url": "https://api.github.com/users/JakeWharton/orgs", | ||
"repos_url": "https://api.github.com/users/JakeWharton/repos", | ||
"events_url": "https://api.github.com/users/JakeWharton/events{/privacy}", | ||
"received_events_url": "https://api.github.com/users/JakeWharton/received_events", | ||
"type": "User", | ||
"site_admin": false, | ||
"name": "Jake Wharton", | ||
"company": "Square, Inc.", | ||
"blog": "http://jakewharton.com", | ||
"location": "Pittsburgh, PA, USA", | ||
"email": "jakewharton@gmail.com | ||
ico; | ||
$prem=" from php prem"; | ||
$sqlt1 = <<<ico1 | ||
", | ||
"hireable": null, | ||
"bio": null, | ||
"public_repos": 92, | ||
"public_gists": 54, | ||
"followers": 33187, | ||
"following": 12, | ||
"created_at": "2009-03-24T16:09:53Z", | ||
"updated_at": "2017-03-26T15:19:18Z" | ||
} | ||
ico1; | ||
echo $sqlt.$prem.$headerStringValue.$user.$sqlt1; | ||
?> | ||
*/ | ||
|
||
public interface RfEtestApi { | ||
|
||
/** | ||
* See https://developer.github.com/v3/repos/#list-contributors | ||
*/ | ||
@GET("/attendance/contributor.php") | ||
Observable<List<RfContributor>> contributors(@Query("owner") String owner, | ||
@Query("repo") String repo); | ||
|
||
@GET("/attendance/contributor.json") | ||
Observable<List<RfContributor>> contributors_json(@Query("owner") String owner, | ||
@Query("repo") String repo); | ||
|
||
@GET("/attendance/{owner}/{repo}/contributor.json") | ||
Observable<List<RfContributor>> contributors_withPath(@Path("owner") String owner, | ||
@Path("repo") String repo); | ||
|
||
@GET("/repos/{owner}/{repo}/contributors") | ||
Observable<List<RfContributor>> contributors_orig(@Path("owner") String owner, | ||
@Path("repo") String repo); | ||
|
||
@GET("/repos/{owner}/{repo}/contributors") | ||
List<RfContributor> getContributors(@Path("owner") String owner, @Path("repo") String repo); | ||
|
||
/** | ||
* See https://developer.github.com/v3/users/ | ||
*/ | ||
@GET("/attendance/user.php") | ||
Observable<RfUser> user(@Query("user") String user); | ||
|
||
@GET("/users/{user}") | ||
Observable<RfUser> user_orig(@Path("user") String user); | ||
|
||
/** | ||
* See https://developer.github.com/v3/users/ | ||
*/ | ||
@GET("/users/{user}") | ||
RfUser getUser(@Path("user") String user); | ||
} |
40 changes: 40 additions & 0 deletions
40
app/src/main/java/com/eusecom/attendance/retrofit/RfEtestService.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,40 @@ | ||
package com.eusecom.attendance.retrofit; | ||
|
||
import android.text.TextUtils; | ||
|
||
import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; | ||
|
||
import okhttp3.OkHttpClient; | ||
import okhttp3.Request; | ||
import retrofit2.Retrofit; | ||
import retrofit2.converter.gson.GsonConverterFactory; | ||
|
||
import static java.lang.String.format; | ||
|
||
public class RfEtestService { | ||
|
||
private RfEtestService() { | ||
} | ||
|
||
public static RfEtestApi createGithubService(final String githubToken) { | ||
Retrofit.Builder builder = new Retrofit.Builder().addCallAdapterFactory(RxJava2CallAdapterFactory.create()) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.baseUrl("http://www.eshoptest.sk"); | ||
//.baseUrl("https://api.github.com"); | ||
|
||
if (!TextUtils.isEmpty(githubToken)) { | ||
|
||
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(chain -> { | ||
Request request = chain.request(); | ||
Request newReq = request.newBuilder() | ||
.addHeader("Authorization", format("token %s", githubToken)) | ||
.build(); | ||
return chain.proceed(newReq); | ||
}).build(); | ||
|
||
builder.client(client); | ||
} | ||
|
||
return builder.build().create(RfEtestApi.class); | ||
} | ||
} |
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