Skip to content

Commit

Permalink
Add Endpoint class, replace unnecessary links, add InstagramNotFoundE…
Browse files Browse the repository at this point in the history
…xception
  • Loading branch information
raiym committed Jul 5, 2016
1 parent 8143fa4 commit cfc2e23
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 5 deletions.
17 changes: 17 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,25 @@ repositories {
mavenCentral()
}

configurations {
google
compile.extendsFrom google

okhttp
compile.extendsFrom okhttp
}

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.google.code.gson:gson:2.6.2'
google 'com.google.code.gson:gson:2.6.2'
okhttp 'com.squareup.okhttp3:okhttp:3.2.0'
}

jar {
dependsOn configurations.runtime
from {
(configurations.runtime - configurations.okhttp).collect { it.isDirectory() ? it : zipTree(it) }
}
}
8 changes: 4 additions & 4 deletions src/main/java/App.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import me.postaddict.instagram.Instagram;
import me.postaddict.instagram.InstagramException;
import me.postaddict.instagram.exception.InstagramException;
import me.postaddict.instagram.model.Media;

import java.io.IOException;
Expand All @@ -11,11 +11,11 @@ public class App {
public static void main(String[] args) {
Instagram instagram = new Instagram();
try {
// me.postaddict.instagram.model.Account account = instagram.getAccount("durov");
// System.out.println(account.profilePicUrl);
me.postaddict.instagram.model.Account account = instagram.getAccount("durov");
System.out.println(account.mediaCount);
// List<Media> medias = instagram.getMedias("durov", 12);
// System.out.println(medias.get(0).imageHighResolutionUrl);
Media media = instagram.getMediaByUrl("https://www.instagram.com/p/BEz_ahOsmS_/");
Media media = instagram.getMediaByUrl("https://www.instagram.com/p/BGY0zB4r7X2/");
System.out.println(media.owner.username);
} catch (IOException e) {
e.printStackTrace();
Expand Down
72 changes: 72 additions & 0 deletions src/main/java/me/postaddict/instagram/Endpoint.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package me.postaddict.instagram;

public class Endpoint {
public static final String BASE_URL = "https://www.instagram.com";
public static final String ACCOUNT_PAGE = "https://www.instagram.com/{{username}}";
public static final String MEDIA_LINK = "https://www.instagram.com/p/{{code}}";
public static final String ACCOUNT_MEDIAS = "https://www.instagram.com/{{username}}/media?max_id={{maxId}}";
public static final String ACCOUNT_JSON_INFO = "https://www.instagram.com/{{username}}/?__a=1";
public static final String MEDIA_JSON_INFO = "https://www.instagram.com/p/{{code}}/?__a=1";
public static final String MEDIA_JSON_BY_LOCATION_ID = "https://www.instagram.com/explore/locations/{{facebookLocationId}}/?__a=1";
public static final String MEDIA_JSON_BY_TAG = "https://www.instagram.com/explore/tags/{{tag}}/?__a=1&max_id={{maxId}}";
public static final String GENERAL_SEARCH = "https://www.instagram.com/web/search/topsearch/?query={{query}}";
public static final String ACCOUNT_JSON_INFO_BY_ID = "https://www.instagram.com/query/?q=ig_user({{userId}}){id,username,external_url,full_name,profile_pic_url,biography,followed_by{count},follows{count},media{count},is_private,is_verified}";
public static final String LAST_COMMENTS_BY_CODE = "https://www.instagram.com/query/?q=ig_shortcode({{code}}){comments.last({{count}}){count,nodes{id,created_at,text,user{id,profile_pic_url,username,follows{count},followed_by{count},biography,full_name,media{count},is_private,external_url,is_verified}},page_info}}";
public static final String COMMENTS_BEFORE_COMMENT_ID_BY_CODE = "https://www.instagram.com/query/?q=ig_shortcode({{code}}){comments.before({{commentId}},{{count}}){count,nodes{id,created_at,text,user{id,profile_pic_url,username,follows{count},followed_by{count},biography,full_name,media{count},is_private,external_url,is_verified}},page_info}}";

public static String getAccountPageLink(String username) {
return ACCOUNT_PAGE.replace("{{username}}", username);
}

public static String getAccountJsonInfoLinkByUsername(String username) {
return ACCOUNT_JSON_INFO.replace("{{username}}", username);
}

public static String getAccountJsonInfoLinkByAccountId(String userId) {
return ACCOUNT_JSON_INFO_BY_ID.replace("{{userId}}", userId);
}

public static String getAccountMediasJsonLink(String username, String maxId) {
if (maxId == null) {
maxId = "";
}
return ACCOUNT_MEDIAS.replace("{{username}}", username).replace("{{maxId}}", maxId);
}

public static String getMediaPageLinkByCode(String code) {
return MEDIA_LINK.replace("{{code}}", code);
}

public static String getMediaJsonLinkByShortcode(String shortcode) {
return MEDIA_JSON_INFO.replace("{{code}}", shortcode);
}

public static String getMediasJsonByLocationIdLink(String facebookLocationId) {
return MEDIA_JSON_BY_LOCATION_ID.replace("{{facebookLocationId}}", facebookLocationId);
}

public static String getMediasJsonByTagLink(String tag, String maxId) {
if (maxId == null) {
maxId = "";
}
return MEDIA_JSON_BY_TAG.replace("{{tag}}", tag).replace("{{maxId}}", maxId);
}

public static String getGeneralSearchJsonLink(String query) {
return GENERAL_SEARCH.replace("{{query}}", query);
}

public static String getLastCommentsByCodeLink(String code, int count) {
return LAST_COMMENTS_BY_CODE
.replace("{{code}}", code)
.replace("{{count}}", "" + count);
}

public static String getCommentsBeforeCommentIdByCode(String code, int count, String commentId) {
return COMMENTS_BEFORE_COMMENT_ID_BY_CODE
.replace("{{code}}", code)
.replace("{{count}}", "" + count)
.replace("{{commentId}}", commentId);
}

}
1 change: 1 addition & 0 deletions src/main/java/me/postaddict/instagram/Instagram.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.postaddict.instagram;

import com.google.gson.Gson;
import me.postaddict.instagram.exception.InstagramException;
import me.postaddict.instagram.model.Account;
import me.postaddict.instagram.model.Media;
import okhttp3.OkHttpClient;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.postaddict.instagram;
package me.postaddict.instagram.exception;

public class InstagramException extends Exception {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package me.postaddict.instagram.exception;

public class InstagramNotFoundException extends InstagramException {

public InstagramNotFoundException() {
}

public InstagramNotFoundException(String message) {
super(message);
}
}

0 comments on commit cfc2e23

Please sign in to comment.