Browse Source
rewrite stories backend, close #319, close #372, close #405
renovate/org.robolectric-robolectric-4.x
rewrite stories backend, close #319, close #372, close #405
renovate/org.robolectric-robolectric-4.x
Austin Huang
4 years ago
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
12 changed files with 408 additions and 292 deletions
-
89app/src/main/java/awais/instagrabber/asyncs/QuizAction.java
-
88app/src/main/java/awais/instagrabber/asyncs/RespondAction.java
-
69app/src/main/java/awais/instagrabber/asyncs/VoteAction.java
-
185app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java
-
5app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java
-
10app/src/main/java/awais/instagrabber/models/StoryModel.java
-
53app/src/main/java/awais/instagrabber/models/stickers/SliderModel.java
-
20app/src/main/java/awais/instagrabber/repositories/StoriesRepository.java
-
20app/src/main/java/awais/instagrabber/repositories/responses/StoryStickerResponse.java
-
129app/src/main/java/awais/instagrabber/webservices/StoriesService.java
-
10app/src/main/res/layout/fragment_story_viewer.xml
-
6app/src/main/res/values/strings.xml
@ -1,89 +0,0 @@ |
|||||
package awais.instagrabber.asyncs; |
|
||||
|
|
||||
import android.os.AsyncTask; |
|
||||
import android.util.Log; |
|
||||
|
|
||||
import org.json.JSONObject; |
|
||||
|
|
||||
import java.io.DataOutputStream; |
|
||||
import java.net.HttpURLConnection; |
|
||||
import java.net.URL; |
|
||||
import java.util.UUID; |
|
||||
|
|
||||
import awais.instagrabber.models.StoryModel; |
|
||||
import awais.instagrabber.models.stickers.QuizModel; |
|
||||
import awais.instagrabber.utils.Constants; |
|
||||
import awais.instagrabber.utils.CookieUtils; |
|
||||
import awais.instagrabber.utils.Utils; |
|
||||
|
|
||||
import static awais.instagrabber.utils.Utils.settingsHelper; |
|
||||
|
|
||||
public class QuizAction extends AsyncTask<Integer, Void, Integer> { |
|
||||
private static final String TAG = "QuizAction"; |
|
||||
|
|
||||
private final StoryModel storyModel; |
|
||||
private final QuizModel quizModel; |
|
||||
private final String cookie; |
|
||||
private final OnTaskCompleteListener onTaskCompleteListener; |
|
||||
|
|
||||
public QuizAction(final StoryModel storyModel, |
|
||||
final QuizModel quizModel, |
|
||||
final String cookie, |
|
||||
final OnTaskCompleteListener onTaskCompleteListener) { |
|
||||
this.storyModel = storyModel; |
|
||||
this.quizModel = quizModel; |
|
||||
this.cookie = cookie; |
|
||||
this.onTaskCompleteListener = onTaskCompleteListener; |
|
||||
} |
|
||||
|
|
||||
protected Integer doInBackground(Integer... rawChoice) { |
|
||||
int choice = rawChoice[0]; |
|
||||
final String url = "https://i.instagram.com/api/v1/media/" + storyModel.getStoryMediaId().split("_")[0] + "/" + quizModel.getId() + "/story_quiz_answer/"; |
|
||||
HttpURLConnection urlConnection = null; |
|
||||
try { |
|
||||
JSONObject ogBody = new JSONObject("{\"client_context\":\"" + UUID.randomUUID().toString() |
|
||||
+ "\",\"mutation_token\":\"" + UUID.randomUUID().toString() |
|
||||
+ "\",\"_csrftoken\":\"" + cookie.split("csrftoken=")[1].split(";")[0] |
|
||||
+ "\",\"_uid\":\"" + CookieUtils.getUserIdFromCookie(cookie) |
|
||||
+ "\",\"__uuid\":\"" + settingsHelper.getString(Constants.DEVICE_UUID) |
|
||||
+ "\"}"); |
|
||||
ogBody.put("answer", String.valueOf(choice)); |
|
||||
String urlParameters = Utils.sign(ogBody.toString()); |
|
||||
urlConnection = (HttpURLConnection) new URL(url).openConnection(); |
|
||||
urlConnection.setRequestMethod("POST"); |
|
||||
urlConnection.setUseCaches(false); |
|
||||
urlConnection.setRequestProperty("User-Agent", Constants.I_USER_AGENT); |
|
||||
urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); |
|
||||
if (urlParameters != null) { |
|
||||
urlConnection.setRequestProperty("Content-Length", Integer.toString(urlParameters.getBytes().length)); |
|
||||
} |
|
||||
urlConnection.setDoOutput(true); |
|
||||
DataOutputStream wr = new DataOutputStream(urlConnection.getOutputStream()); |
|
||||
wr.writeBytes(urlParameters); |
|
||||
wr.flush(); |
|
||||
wr.close(); |
|
||||
Log.d(TAG, "quiz: " + url + " " + cookie + " " + urlParameters); |
|
||||
urlConnection.connect(); |
|
||||
if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { |
|
||||
return choice; |
|
||||
} |
|
||||
} catch (Throwable ex) { |
|
||||
Log.e(TAG, "quiz: " + ex); |
|
||||
} finally { |
|
||||
if (urlConnection != null) { |
|
||||
urlConnection.disconnect(); |
|
||||
} |
|
||||
} |
|
||||
return -1; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
protected void onPostExecute(final Integer choice) { |
|
||||
if (onTaskCompleteListener == null || choice == null) return; |
|
||||
onTaskCompleteListener.onTaskComplete(choice); |
|
||||
} |
|
||||
|
|
||||
public interface OnTaskCompleteListener { |
|
||||
void onTaskComplete(final int choice); |
|
||||
} |
|
||||
} |
|
@ -1,88 +0,0 @@ |
|||||
package awais.instagrabber.asyncs; |
|
||||
|
|
||||
import android.os.AsyncTask; |
|
||||
import android.util.Log; |
|
||||
|
|
||||
import org.json.JSONObject; |
|
||||
|
|
||||
import java.io.DataOutputStream; |
|
||||
import java.net.HttpURLConnection; |
|
||||
import java.net.URL; |
|
||||
import java.util.UUID; |
|
||||
|
|
||||
import awais.instagrabber.models.StoryModel; |
|
||||
import awais.instagrabber.models.stickers.QuestionModel; |
|
||||
import awais.instagrabber.utils.Constants; |
|
||||
import awais.instagrabber.utils.CookieUtils; |
|
||||
import awais.instagrabber.utils.Utils; |
|
||||
|
|
||||
import static awais.instagrabber.utils.Utils.settingsHelper; |
|
||||
|
|
||||
public class RespondAction extends AsyncTask<String, Void, Boolean> { |
|
||||
|
|
||||
private final StoryModel storyModel; |
|
||||
private final QuestionModel questionModel; |
|
||||
private final String cookie; |
|
||||
private final OnTaskCompleteListener onTaskCompleteListener; |
|
||||
|
|
||||
public RespondAction(final StoryModel storyModel, |
|
||||
final QuestionModel questionModel, |
|
||||
final String cookie, |
|
||||
final OnTaskCompleteListener onTaskCompleteListener) { |
|
||||
this.storyModel = storyModel; |
|
||||
this.questionModel = questionModel; |
|
||||
this.cookie = cookie; |
|
||||
this.onTaskCompleteListener = onTaskCompleteListener; |
|
||||
} |
|
||||
|
|
||||
protected Boolean doInBackground(String... rawChoice) { |
|
||||
final String url = "https://i.instagram.com/api/v1/media/" |
|
||||
+ storyModel.getStoryMediaId().split("_")[0] + "/" + questionModel.getId() + "/story_question_response/"; |
|
||||
HttpURLConnection urlConnection = null; |
|
||||
try { |
|
||||
final JSONObject ogbody = new JSONObject("{\"client_context\":\"" + UUID.randomUUID().toString() |
|
||||
+ "\",\"mutation_token\":\"" + UUID.randomUUID().toString() |
|
||||
+ "\",\"_csrftoken\":\"" + cookie.split("csrftoken=")[1].split(";")[0] |
|
||||
+ "\",\"_uid\":\"" + CookieUtils.getUserIdFromCookie(cookie) |
|
||||
+ "\",\"__uuid\":\"" + settingsHelper.getString(Constants.DEVICE_UUID) |
|
||||
+ "\"}"); |
|
||||
String choice = rawChoice[0].replaceAll("\"", ("\\\"")); |
|
||||
ogbody.put("response", choice); |
|
||||
String urlParameters = Utils.sign(ogbody.toString()); |
|
||||
urlConnection = (HttpURLConnection) new URL(url).openConnection(); |
|
||||
urlConnection.setRequestMethod("POST"); |
|
||||
urlConnection.setUseCaches(false); |
|
||||
urlConnection.setRequestProperty("User-Agent", Constants.I_USER_AGENT); |
|
||||
urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); |
|
||||
urlConnection.setRequestProperty("Content-Length", Integer.toString(urlParameters.getBytes().length)); |
|
||||
urlConnection.setDoOutput(true); |
|
||||
DataOutputStream wr = new DataOutputStream(urlConnection.getOutputStream()); |
|
||||
wr.writeBytes(urlParameters); |
|
||||
wr.flush(); |
|
||||
wr.close(); |
|
||||
urlConnection.connect(); |
|
||||
if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { |
|
||||
return true; |
|
||||
} |
|
||||
|
|
||||
} catch (Throwable ex) { |
|
||||
Log.e("austin_debug", "respond: " + ex); |
|
||||
} finally { |
|
||||
if (urlConnection != null) { |
|
||||
urlConnection.disconnect(); |
|
||||
} |
|
||||
} |
|
||||
return null; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
protected void onPostExecute(final Boolean ok) { |
|
||||
if (onTaskCompleteListener == null) return; |
|
||||
onTaskCompleteListener.onTaskComplete(ok); |
|
||||
|
|
||||
} |
|
||||
|
|
||||
public interface OnTaskCompleteListener { |
|
||||
void onTaskComplete(final boolean result); |
|
||||
} |
|
||||
} |
|
@ -1,69 +0,0 @@ |
|||||
package awais.instagrabber.asyncs; |
|
||||
|
|
||||
import android.os.AsyncTask; |
|
||||
import android.util.Log; |
|
||||
|
|
||||
import java.io.DataOutputStream; |
|
||||
import java.net.HttpURLConnection; |
|
||||
import java.net.URL; |
|
||||
|
|
||||
import awais.instagrabber.models.StoryModel; |
|
||||
import awais.instagrabber.models.stickers.PollModel; |
|
||||
import awais.instagrabber.utils.Constants; |
|
||||
|
|
||||
public class VoteAction extends AsyncTask<Integer, Void, Integer> { |
|
||||
|
|
||||
private static final String TAG = "VoteAction"; |
|
||||
|
|
||||
private final StoryModel storyModel; |
|
||||
private final PollModel pollModel; |
|
||||
private final String cookie; |
|
||||
private final OnTaskCompleteListener onTaskCompleteListener; |
|
||||
|
|
||||
public VoteAction(final StoryModel storyModel, |
|
||||
final PollModel pollModel, |
|
||||
final String cookie, |
|
||||
final OnTaskCompleteListener onTaskCompleteListener) { |
|
||||
this.storyModel = storyModel; |
|
||||
this.pollModel = pollModel; |
|
||||
this.cookie = cookie; |
|
||||
this.onTaskCompleteListener = onTaskCompleteListener; |
|
||||
} |
|
||||
|
|
||||
protected Integer doInBackground(Integer... rawChoice) { |
|
||||
int choice = rawChoice[0]; |
|
||||
final String url = "https://www.instagram.com/media/" + storyModel.getStoryMediaId().split("_")[0] + "/" + pollModel.getId() + "/story_poll_vote/"; |
|
||||
try { |
|
||||
final HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection(); |
|
||||
urlConnection.setRequestMethod("POST"); |
|
||||
urlConnection.setUseCaches(false); |
|
||||
urlConnection.setRequestProperty("User-Agent", Constants.USER_AGENT); |
|
||||
urlConnection.setRequestProperty("x-csrftoken", cookie.split("csrftoken=")[1].split(";")[0]); |
|
||||
urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); |
|
||||
urlConnection.setRequestProperty("Content-Length", "6"); |
|
||||
urlConnection.setDoOutput(true); |
|
||||
DataOutputStream wr = new DataOutputStream(urlConnection.getOutputStream()); |
|
||||
wr.writeBytes("vote=" + choice); |
|
||||
wr.flush(); |
|
||||
wr.close(); |
|
||||
urlConnection.connect(); |
|
||||
if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { |
|
||||
return choice; |
|
||||
} |
|
||||
urlConnection.disconnect(); |
|
||||
} catch (Exception ex) { |
|
||||
Log.e(TAG, "Error", ex); |
|
||||
} |
|
||||
return -1; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
protected void onPostExecute(final Integer result) { |
|
||||
if (result == null || onTaskCompleteListener == null) return; |
|
||||
onTaskCompleteListener.onTaskComplete(result); |
|
||||
} |
|
||||
|
|
||||
public interface OnTaskCompleteListener { |
|
||||
void onTaskComplete(final int choice); |
|
||||
} |
|
||||
} |
|
@ -0,0 +1,53 @@ |
|||||
|
package awais.instagrabber.models.stickers; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
public final class SliderModel implements Serializable { |
||||
|
private final int voteCount; |
||||
|
private final Double average; |
||||
|
private Double myChoice; |
||||
|
private final boolean canVote; |
||||
|
private final String id, question, emoji; |
||||
|
|
||||
|
public SliderModel(final String id, final String question, final String emoji, final boolean canVote, |
||||
|
final Double average, final int voteCount, final Double myChoice) { |
||||
|
this.id = id; |
||||
|
this.question = question; |
||||
|
this.emoji = emoji; |
||||
|
this.canVote = canVote; |
||||
|
this.average = average; |
||||
|
this.voteCount = voteCount; |
||||
|
this.myChoice = myChoice; |
||||
|
} |
||||
|
|
||||
|
public String getId() { |
||||
|
return id; |
||||
|
} |
||||
|
|
||||
|
public String getQuestion() { |
||||
|
return question; |
||||
|
} |
||||
|
|
||||
|
public String getEmoji() { |
||||
|
return emoji; |
||||
|
} |
||||
|
|
||||
|
public boolean canVote() { |
||||
|
return canVote; |
||||
|
} |
||||
|
|
||||
|
public int getVoteCount() { |
||||
|
return voteCount; |
||||
|
} |
||||
|
|
||||
|
public Double getAverage() { |
||||
|
return average; |
||||
|
} |
||||
|
|
||||
|
public Double getMyChoice() { return myChoice; } |
||||
|
|
||||
|
public Double setMyChoice(final Double choice) { |
||||
|
this.myChoice = choice; |
||||
|
return choice; |
||||
|
} |
||||
|
} |
@ -0,0 +1,20 @@ |
|||||
|
package awais.instagrabber.repositories.responses; |
||||
|
|
||||
|
public class StoryStickerResponse { |
||||
|
private final String status; |
||||
|
|
||||
|
public StoryStickerResponse(final String status) { |
||||
|
this.status = status; |
||||
|
} |
||||
|
|
||||
|
public String getStatus() { |
||||
|
return status; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String toString() { |
||||
|
return "StoryStickerResponse{" + |
||||
|
"status='" + status + '\'' + |
||||
|
'}'; |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue