|
|
|
|
|
|
|
|
|
|
|
|
|
this_program `()(string client_id, string client_secret, |
void|string redirect_uri, |
void|string|array(string)|multiset(string) scope) |
{ |
return V1(client_id, client_secret, redirect_uri, scope); |
} |
|
|
class V1 |
{ |
inherit WebApi.Api : parent; |
|
protected constant AuthClass = Auth.Instagram; |
|
|
|
|
|
|
Users `users() |
{ |
return _users || (_users = Users()); |
} |
|
|
|
|
|
|
Tags `tags() |
{ |
return _tags || (_tags = Tags()); |
} |
|
|
|
|
|
|
Media `media() |
{ |
return _media || (_media = Media()); |
} |
|
|
|
|
|
|
Comments `comments() |
{ |
return _comments || (_comments = Comments()); |
} |
|
|
|
|
|
|
Likes `likes() |
{ |
return _likes || (_likes = Likes()); |
} |
|
|
|
|
|
|
Locations `locations() |
{ |
return _locations || (_locations = Locations()); |
} |
|
|
|
|
Any `any() |
{ |
return _any || (_any = Any()); |
} |
|
|
|
|
|
|
|
|
|
|
|
mapping get(string path, void|ParamsArg params, void|Callback cb) |
{ |
return `any()->get(path, params, cb); |
} |
|
|
|
|
|
|
|
|
|
|
|
mapping put(string path, void|ParamsArg params, void|Callback cb) |
{ |
return `any()->put(path, params, cb); |
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
mapping post(string path, void|ParamsArg params, string data, |
void|Callback cb) |
{ |
return `any()->post(path, params, 0, cb); |
} |
|
|
|
|
|
|
|
|
|
|
|
mapping delete(string path, void|ParamsArg params, void|Callback cb) |
{ |
return `any()->delete(path, params, cb); |
} |
|
|
|
#define ASSERT_SCOPE(S,FUN) do { \ |
if (!auth->has_scope(S)) { \ |
error("The method %O requires the scope \"%s\" which is not set! ", \ |
FUN, S); \ |
} \ |
} while (0) |
|
|
protected class Method |
{ |
inherit WebApi.Api.Method; |
|
|
protected mixed _get(string s, void|ParamsArg p, void|Callback cb) |
{ |
return parent::get(get_uri(METHOD_PATH + s), p, cb); |
} |
|
|
protected mixed _post(string s, void|ParamsArg p, string data, |
void|Callback cb) |
{ |
return parent::post(get_uri(METHOD_PATH + s), p, data, cb); |
} |
|
|
protected mixed _delete(string s, void|ParamsArg p, void|Callback cb) |
{ |
return parent::delete(get_uri(METHOD_PATH + s), p, cb); |
} |
|
|
protected mixed _put(string s, void|ParamsArg p, void|Callback cb) |
{ |
return parent::put(get_uri(METHOD_PATH + s), p, cb); |
} |
} |
|
|
|
|
|
protected class Users |
{ |
inherit Method; |
|
protected constant METHOD_PATH = "/users/"; |
|
|
|
|
|
|
|
|
|
mapping user(void|string uid, void|Callback cb) |
{ |
return _get(uid||"self", 0, cb); |
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapping feed(void|ParamsArg params, void|Callback cb) |
{ |
return _get("self/feed", params, cb); |
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapping recent(void|string uid, void|ParamsArg params, void|Callback cb) |
{ |
return _get((uid||"self") + "/media/recent", params, cb); |
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapping liked(void|ParamsArg params, void|Callback cb) |
{ |
return _get("self/media/liked", params, cb); |
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
mapping search(string query, void|int count, void|Callback cb) |
{ |
mapping p = ([ "q" : query ]); |
if (count) p->count = count; |
return _get("search", p, cb); |
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapping follows(void|string user_id, void|Callback cb) |
{ |
ASSERT_SCOPE("relationships", "Instagram()->users->follows()"); |
return _get((user_id||"self") + "/follows", 0, cb); |
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapping followed_by(string|void user_id, void|Callback cb) |
{ |
ASSERT_SCOPE("relationships", "Instagram()->users->followed_by()"); |
return _get((user_id||"self") + "/followed-by", 0, cb); |
} |
|
|
|
|
|
|
|
|
|
|
|
|
mapping requested_by(void|Callback cb) |
{ |
ASSERT_SCOPE("relationships", "Instagram()->users->requested_by()"); |
return _get("self/requested-by", 0, cb); |
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapping relationship(string user_id, void|Callback cb) |
{ |
ASSERT_SCOPE("relationships", "Instagram()->users->relationship()"); |
return _get(user_id + "/relationship", 0, cb); |
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapping relationship_change(string user_id, string action, void|Callback cb) |
{ |
ASSERT_SCOPE("relationships", |
"Instagram()->users->relationship_change()"); |
|
if (!(<"follow","unfollow","block","unblock","approve","deny">)[action]) |
error("Unknown action %O! ", action); |
|
mapping p = ([ "action" : action ]); |
return _post(user_id + "/relationship", p, 0, cb); |
} |
} |
|
|
|
|
|
protected class Tags |
{ |
inherit Method; |
|
protected constant METHOD_PATH = "/tags/"; |
|
|
|
|
|
|
|
|
|
|
mapping tag(string tag_name, void|Callback cb) |
{ |
return _get(normalize_tag(tag_name), 0, cb); |
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapping recent(string tag_name, void|ParamsArg params, void|Callback cb) |
{ |
return _get(normalize_tag(tag_name) + "/media/recent", params, cb); |
} |
|
|
|
|
|
|
|
|
|
|
|
mapping search(string tag_name, Callback cb) |
{ |
return _get("search", ([ "q" : normalize_tag(tag_name) ]), cb); |
} |
|
|
private string normalize_tag(string t) |
{ |
if (t && sizeof(t) && t[0] == '#') |
t = t[1..]; |
|
return t; |
} |
} |
|
|
|
|
|
protected class Media |
{ |
inherit Method; |
|
protected constant METHOD_PATH = "/media/"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapping item(string media_id, void|Callback cb) |
{ |
return _get(media_id, 0, cb); |
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapping search(void|ParamsArg params, void|Callback cb) |
{ |
return _get("search", params, cb); |
} |
|
|
|
|
|
|
mapping popular(void|Callback cb) |
{ |
return _get("popular", 0, cb); |
} |
} |
|
|
|
|
|
protected class Comments |
{ |
inherit Method; |
|
protected constant METHOD_PATH = "/media/"; |
|
|
|
|
|
|
|
|
|
|
|
mapping list(string media_id, void|Callback cb) |
{ |
ASSERT_SCOPE("comments", "Instagram()->comments->get()"); |
return _get(media_id + "/comments", 0, cb); |
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapping add(string media_id, string comment, void|Callback cb) |
{ |
ASSERT_SCOPE("comments", "Instagram()->comments->add()"); |
return _post(media_id + "/comments", ([ "text" : comment ]), 0, cb); |
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapping remove(string media_id, string comment_id, void|Callback cb) |
{ |
ASSERT_SCOPE("comments", "Instagram()->comments->delete()"); |
return _delete(media_id + "/comments/" + comment_id, 0, cb); |
} |
} |
|
|
|
|
|
protected class Likes |
{ |
inherit Method; |
|
protected constant METHOD_PATH = "/media/"; |
|
|
|
|
|
|
|
|
|
|
|
|
mapping list(string media_id, void|Callback cb) |
{ |
ASSERT_SCOPE("likes", "Instagram()->likes->list()"); |
return _get(media_id + "/likes", 0, cb); |
} |
|
|
|
|
|
|
|
|
|
|
|
|
mapping add(string media_id, void|Callback cb) |
{ |
ASSERT_SCOPE("likes", "Instagram()->likes->add()"); |
return _post(media_id + "/likes", 0, 0, cb); |
} |
|
|
|
|
|
|
|
|
|
|
|
|
mapping remove(string media_id, void|Callback cb) |
{ |
ASSERT_SCOPE("likes", "Instagram()->likes->remove()"); |
return _delete(media_id + "/likes", 0, cb); |
} |
} |
|
|
|
|
|
protected class Locations |
{ |
inherit Method; |
|
protected constant METHOD_PATH = "/locations/"; |
|
|
|
|
|
|
|
|
|
|
mapping location(string location_id, void|Callback cb) |
{ |
return _get(location_id, 0, cb); |
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapping recent_media(string location_id, void|ParamsArg params, |
void|Callback cb) |
{ |
return _get(location_id + "/media/recent", params, cb); |
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapping search(ParamsArg params, void|Callback cb) |
{ |
return _get("search", params, cb); |
} |
} |
|
|
|
protected class Any |
{ |
inherit Method; |
|
protected constant METHOD_PATH = "/"; |
|
|
|
|
|
|
|
|
|
|
|
mixed get(string s, void|ParamsArg p, void|Callback cb) |
{ |
return _get(s, p, cb); |
} |
|
|
|
|
|
|
|
|
|
|
|
mixed post(string s, void|ParamsArg p, string data, void|Callback cb) |
{ |
return _post(s, p, data, cb); |
} |
|
|
|
|
|
|
|
|
|
|
|
mixed delete(string s, void|ParamsArg p, void|Callback cb) |
{ |
return _delete(s, p, cb); |
} |
|
|
|
|
|
|
|
|
|
mixed put(string s, void|ParamsArg p, void|Callback cb) |
{ |
return _put(s, p, cb); |
} |
} |
|
|
|
|
protected constant API_URI = "https://api.instagram.com/v1"; |
|
|
private Users _users; |
|
|
private Tags _tags; |
|
|
private Media _media; |
|
|
private Comments _comments; |
|
|
private Likes _likes; |
|
|
private Locations _locations; |
|
|
private Any _any; |
} |
|
|