lib/ayadn/endpoints.rb in ayadn-0.6.4 vs lib/ayadn/endpoints.rb in ayadn-1.0.0

- old
+ new

@@ -1,154 +1,221 @@ -#!/usr/bin/env ruby # encoding: utf-8 -class AyaDN +module Ayadn + class Endpoints - AYADN_CLIENT_ID = "hFsCGArAjgJkYBHTHbZnUvzTmL4vaLHL" - AYADN_CALLBACK_URL = "http://aya.io/ayadn/auth.html" + attr_accessor :ayadn_callback_url, :base_url, :config_api_url, :posts_url, :users_url, :files_url, :token_url, :channels_url, :pm_url - BASE_URL = "https://alpha-api.app.net/" + def initialize + @ayadn_callback_url = "http://aya.io/ayadn/auth.html" + @base_url = "https://alpha-api.app.net/" + @config_api_url = @base_url + "stream/0/config" + @posts_url = @base_url + "stream/0/posts/" + @users_url = @base_url + "stream/0/users/" + @files_url = @base_url + "stream/0/files/" + @token_url = @base_url + "stream/0/token/" + @channels_url = @base_url + "stream/0/channels/" + @pm_url = @channels_url + "pm/messages" + end - CONFIG_API_URL = BASE_URL + "stream/0/config" - - POSTS_URL = BASE_URL + "stream/0/posts/" - USERS_URL = BASE_URL + "stream/0/users/" - FILES_URL = BASE_URL + "stream/0/files/" - CHANNELS_URL = BASE_URL + "stream/0/channels/" - PM_URL = CHANNELS_URL + "pm/messages" + def authorize_url + "https://account.app.net/oauth/authenticate?client_id=#{Settings::AYADN_CLIENT_ID}&response_type=token&redirect_uri=#{@ayadn_callback_url}&scope=basic,stream,write_post,follow,public_messages,messages,files,update_profile&include_marker=1" + end - class Endpoints - def initialize(token) - @token = token - end - def authorize_url - "https://account.app.net/oauth/authenticate?client_id=#{AYADN_CLIENT_ID}&response_type=token&redirect_uri=#{AYADN_CALLBACK_URL}&scope=basic stream write_post follow public_messages messages files&include_marker=1" - end - def global - POSTS_URL + "stream/global?access_token=#{@token}&count=#{$tools.config['counts']['global']}" - end - def unified - POSTS_URL + "stream/unified?access_token=#{@token}&count=#{$tools.config['counts']['unified']}" - end - def unified_streamback - POSTS_URL + "stream/unified?access_token=#{@token}&count=#{$tools.config['timeline']['streamback']}" - end - def single_post(post_id) - POSTS_URL + "#{post_id}?access_token=#{@token}" - end - def explore(stream) - case stream - when "checkins" - POSTS_URL + "stream/explore/checkins?access_token=#{@token}&count=#{$tools.config['counts']['checkins']}" - when "trending", "conversations", "photos" - POSTS_URL + "stream/explore/#{stream}?access_token=#{@token}&count=#{$tools.config['counts']['explore']}" - end - end - def hashtags(tags) - POSTS_URL + "tag/#{tags}" - end - def who_reposted(post_id) - POSTS_URL + "#{post_id}/reposters/?access_token=#{@token}" - end - def who_starred(post_id) - POSTS_URL + "#{post_id}/stars/?access_token=#{@token}" - end - def replies(post_id) - POSTS_URL + "#{post_id}/replies/?access_token=#{@token}" - end - def star(post_id) - POSTS_URL + "#{post_id}/star/?access_token=#{@token}" - end - def repost(post_id) - POSTS_URL + "#{post_id}/repost/?access_token=#{@token}" - end - def search(words) - POSTS_URL + "search?text=#{words}&access_token=#{@token}&count=#{$tools.config['counts']['search']}" - end - def mentions(username) - USERS_URL + "#{username}/mentions/?access_token=#{@token}&count=#{$tools.config['counts']['mentions']}" - end - def posts(username) - USERS_URL + "#{username}/posts/?access_token=#{@token}&count=#{$tools.config['counts']['posts']}" - end - def user_info(username) - USERS_URL + "#{username}/?access_token=#{@token}" - end - def starred_posts(username) - USERS_URL + "#{username}/stars/?access_token=#{@token}&count=#{$tools.config['counts']['starred']}" - end - def follow(username) - USERS_URL + "#{username}/follow/?access_token=#{@token}" - end - def following(username) - USERS_URL + "#{username}/following/?access_token=#{@token}" - end - def followers(username) - USERS_URL + "#{username}/followers/?access_token=#{@token}" - end - def mute(username) - USERS_URL + "#{username}/mute/?access_token=#{@token}" - end - def muted(username) - USERS_URL + "#{username}/muted/?access_token=#{@token}" - end - def block(username) - USERS_URL + "#{username}/block/?access_token=#{@token}" - end - def blocked(username) - USERS_URL + "#{username}/blocked/?access_token=#{@token}" - end - def interactions - USERS_URL + "me/interactions?access_token=#{@token}" - end - def channels - CHANNELS_URL + "?access_token=#{@token}&count=200" - end - def messages(channel_id) - CHANNELS_URL + "#{channel_id}/messages?access_token=#{@token}&count=200" - end - def get_message(channel_id, message_id) - CHANNELS_URL + "#{channel_id}/messages/#{message_id}?access_token=#{@token}" - end - def files_list - USERS_URL + "me/files?access_token=#{@token}" - end - def get_file(file_id) - FILES_URL + "#{file_id}?access_token=#{@token}" - end - def get_multiple_files(file_ids) - FILES_URL + "?ids=#{file_ids}&access_token=#{@token}" - end - def access_token - "access_token=#{@token}" - end - def include_deleted - "&include_deleted=1" - end - def exclude_deleted - "&include_deleted=0" - end - def include_html - "&include_html=1" - end - def exclude_html - "&include_html=0" - end - def include_directed - "&include_directed_posts=1" - end - def exclude_directed - "&include_directed_posts=0" - end - def include_annotations - "&include_annotations=1" - end - def exclude_annotations - "&include_annotations=0" - end - def base_params - "&include_html=0&include_annotations=1&include_deleted=1" - end - def light_params - "&include_html=0&include_annotations=0&include_deleted=0" - end - end -end \ No newline at end of file + def token_info + "#{@token_url}?access_token=#{Settings.user_token}" + end + + def file(file_id) + "#{@files_url}#{file_id}?access_token=#{Settings.user_token}" + end + + def files + "#{@files_url}?access_token=#{Settings.user_token}" + end + + def unified(options) + if options[:count] || options[:since_id] + @options_list = API.build_query(options) + else + @options_list = API.build_query({count: Settings.options[:counts][:unified]}) + end + "#{@posts_url}stream/unified?access_token=#{Settings.user_token}#{@options_list}" + end + + def checkins(options) + if options[:count] || options[:since_id] + @options_list = API.build_query(options) + else + @options_list = API.build_query({count: Settings.options[:counts][:checkins]}) + end + "#{@posts_url}stream/explore/checkins?access_token=#{Settings.user_token}#{@options_list}" + end + + def global(options) + if options[:count] || options[:since_id] + @options_list = API.build_query(options) + else + @options_list = API.build_query({count: Settings.options[:counts][:global]}) + end + "#{@posts_url}stream/global?access_token=#{Settings.user_token}#{@options_list}" + end + + def trending(options) + if options[:count] || options[:since_id] + @options_list = API.build_query(options) + else + @options_list = API.build_query({count: Settings.options[:counts][:trending]}) + end + "#{@posts_url}stream/explore/trending?access_token=#{Settings.user_token}#{@options_list}" + end + + def photos(options) + if options[:count] || options[:since_id] + @options_list = API.build_query(options) + else + @options_list = API.build_query({count: Settings.options[:counts][:photos]}) + end + "#{@posts_url}stream/explore/photos?access_token=#{Settings.user_token}#{@options_list}" + end + + def conversations(options) + if options[:count] || options[:since_id] + @options_list = API.build_query(options) + else + @options_list = API.build_query({count: Settings.options[:counts][:conversations]}) + end + "#{@posts_url}stream/explore/conversations?access_token=#{Settings.user_token}#{@options_list}" + end + + def mentions(username, options) + if options[:count] + @options_list = API.build_query(options) + else + @options_list = API.build_query({count: Settings.options[:counts][:mentions]}) + end + "#{@users_url}#{username}/mentions/?access_token=#{Settings.user_token}#{@options_list}" + end + + def posts(username, options) + if options[:count] + @options_list = API.build_query(options) + else + @options_list = API.build_query({count: Settings.options[:counts][:posts]}) + end + "#{@users_url}#{username}/posts/?access_token=#{Settings.user_token}#{@options_list}" + end + + def whatstarred(username, options) + if options[:count] + @options_list = API.build_query(options) + else + @options_list = API.build_query({count: Settings.options[:counts][:default]}) + end + "#{@users_url}#{username}/stars/?access_token=#{Settings.user_token}#{@options_list}" + end + + def interactions + "#{@users_url}me/interactions?access_token=#{Settings.user_token}" + end + + def whoreposted(post_id) + "#{@posts_url}#{post_id}/reposters/?access_token=#{Settings.user_token}" + end + + def whostarred(post_id) + "#{@posts_url}#{post_id}/stars/?access_token=#{Settings.user_token}" + end + + def convo(post_id, options) + if options[:count] + @options_list = API.build_query(options) + else + @options_list = API.build_query({count: Settings.options[:counts][:convo]}) + end + "#{@posts_url}#{post_id}/replies/?access_token=#{Settings.user_token}#{@options_list}" + end + + def followings(username, options) + "#{@users_url}#{username}/following/?access_token=#{Settings.user_token}&count=#{options[:count]}&before_id=#{options[:before_id]}" + end + + def followers(username, options) + "#{@users_url}#{username}/followers/?access_token=#{Settings.user_token}&count=#{options[:count]}&before_id=#{options[:before_id]}" + end + + def muted(options) + "#{@users_url}me/muted/?access_token=#{Settings.user_token}&count=#{options[:count]}&before_id=#{options[:before_id]}" + end + + def blocked(options) + "#{@users_url}me/blocked/?access_token=#{Settings.user_token}&count=#{options[:count]}&before_id=#{options[:before_id]}" + end + + def hashtag(hashtag) + "#{@posts_url}tag/#{hashtag}" + end + + def search(words, options) + if options[:count] + @options_list = API.build_query(options) + else + @options_list = API.build_query({count: Settings.options[:counts][:search]}) + end + "#{@posts_url}search?text=#{words}&access_token=#{Settings.user_token}#{@options_list}" + end + + def user(username) + "#{@users_url}#{username}?access_token=#{Settings.user_token}&include_user_annotations=1" + end + + def single_post(post_id, options) + @options_list = API.build_query(options) + "#{@posts_url}#{post_id}?access_token=#{Settings.user_token}#{@options_list}" + end + + def files_list(options) + if options[:count] + @options_list = API.build_query(options) + else + @options_list = API.build_query({count: Settings.options[:counts][:files]}) + end + "#{@users_url}me/files?access_token=#{Settings.user_token}#{@options_list}" + end + + def delete_post(post_id) + "#{@posts_url}#{post_id}?access_token=#{Settings.user_token}" + end + + def follow(username) + "#{@users_url}#{username}/follow?access_token=#{Settings.user_token}" + end + + def mute(username) + "#{@users_url}#{username}/mute?access_token=#{Settings.user_token}" + end + + def block(username) + "#{@users_url}#{username}/block?access_token=#{Settings.user_token}" + end + + def repost(post_id) + "#{@posts_url}#{post_id}/repost?access_token=#{Settings.user_token}" + end + + def star(post_id) + "#{@posts_url}#{post_id}/star?access_token=#{Settings.user_token}" + end + + def channels(options) + "#{@channels_url}?access_token=#{Settings.user_token}#{API.build_query(options)}" + end + + def messages(channel_id, options) + "#{@channels_url}#{channel_id}/messages?access_token=#{Settings.user_token}#{API.build_query(options)}" + end + + def ayadnlog + "#{@channels_url}47348/messages?access_token=#{Settings.user_token}" + end + + end +end