Class: Ayadn::API
Class Method Summary collapse
Instance Method Summary collapse
- #block(username) ⇒ Object
- #check_response_meta_code(res) ⇒ Object
- #delete_message(channel_id, message_id) ⇒ Object
- #delete_post(post_id) ⇒ Object
- #follow(username) ⇒ Object
- #get_blocked ⇒ Object
- #get_channel(channel_id, options = {}) ⇒ Object
- #get_channels ⇒ Object
- #get_checkins(options) ⇒ Object
- #get_config ⇒ Object
- #get_conversations(options) ⇒ Object
- #get_convo(post_id, options = {}) ⇒ Object
- #get_details(post_id, options = {}) ⇒ Object
- #get_explore(explore, options) ⇒ Object
- #get_file(file_id) ⇒ Object
- #get_files_list(options) ⇒ Object
- #get_followers(username) ⇒ Object
- #get_followings(username) ⇒ Object
- #get_global(options) ⇒ Object
- #get_hashtag(hashtag) ⇒ Object
- #get_interactions ⇒ Object
- #get_mentions(username, options) ⇒ Object
- #get_messages(channel_id, options) ⇒ Object
-
#get_muted ⇒ Object
“nil” as a first argument? the other method should be refactored.
- #get_photos(options) ⇒ Object
- #get_posts(username, options) ⇒ Object
- #get_raw_list(username, target) ⇒ Object
- #get_search(words, options) ⇒ Object
- #get_token_info ⇒ Object
- #get_trending(options) ⇒ Object
- #get_unified(options) ⇒ Object
- #get_user(username) ⇒ Object
- #get_users(usernames) ⇒ Object
- #get_whatstarred(username, options) ⇒ Object
- #get_whoreposted(post_id) ⇒ Object
- #get_whostarred(post_id) ⇒ Object
- #mute(username) ⇒ Object
- #repost(post_id) ⇒ Object
- #search_annotations(words, options) ⇒ Object
- #search_channels(words, options) ⇒ Object
- #search_messages(channel_id, words, options) ⇒ Object
- #search_users(words, options) ⇒ Object
- #star(post_id) ⇒ Object
- #unblock(username) ⇒ Object
- #unfollow(username) ⇒ Object
- #unmute(username) ⇒ Object
- #unrepost(post_id) ⇒ Object
- #unstar(post_id) ⇒ Object
- #update_marker(name, last_read_id) ⇒ Object
Class Method Details
.build_query(arg) ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/ayadn/api.rb', line 259 def self.build_query(arg) # Number of posts/messages to fetch. # Either from CLI and integer # or from the settings if arg[:count].to_s.is_integer? count = arg[:count] else count = Settings..counts.default end # Do we want the "directed posts"? # Either from CLI (optional) # or from the settings directed = arg[:directed] || Settings..timeline.directed # because I was not always consistent in the legacy code base, let's be cautious if directed == true || directed == 1 directed = 1 else directed = 0 end # We *never* want the HTML in the response, we are a CLI client html = 0 # If the user asks to see posts starting with a specific post ID if arg[:since_id] "&count=#{count}&include_html=#{html}&include_directed_posts=#{directed}&include_deleted=0&include_annotations=1&since_id=#{arg[:since_id]}" # Or asks to see their recent messages elsif arg[:recent_message] "&count=#{count}&include_html=#{html}&include_directed_posts=#{directed}&include_deleted=0&include_annotations=1&include_recent_message=#{arg[:recent_message]}" # Else we create a normal request URL else "&count=#{count}&include_html=#{html}&include_directed_posts=#{directed}&include_deleted=0&include_annotations=1" end end |
Instance Method Details
#block(username) ⇒ Object
182 183 184 |
# File 'lib/ayadn/api.rb', line 182 def block(username) JSON.parse(CNX.post(Endpoints.new.block(username))) end |
#check_response_meta_code(res) ⇒ Object
242 243 244 245 246 247 248 |
# File 'lib/ayadn/api.rb', line 242 def (res) if res['meta']['code'] == 200 res else Errors.global_error({error: nil, caller: caller, data: [res['meta']]}) end end |
#delete_message(channel_id, message_id) ⇒ Object
194 195 196 |
# File 'lib/ayadn/api.rb', line 194 def (channel_id, ) JSON.parse(CNX.delete(Endpoints.new.(channel_id, ))) end |
#delete_post(post_id) ⇒ Object
190 191 192 |
# File 'lib/ayadn/api.rb', line 190 def delete_post(post_id) JSON.parse(CNX.delete(Endpoints.new.delete_post(post_id))) end |
#follow(username) ⇒ Object
174 175 176 |
# File 'lib/ayadn/api.rb', line 174 def follow(username) JSON.parse(CNX.post(Endpoints.new.follow(username))) end |
#get_blocked ⇒ Object
118 119 120 |
# File 'lib/ayadn/api.rb', line 118 def get_blocked build_list(nil, :blocked) end |
#get_channel(channel_id, options = {}) ⇒ Object
228 229 230 231 |
# File 'lib/ayadn/api.rb', line 228 def get_channel channel_id, = {} = {:recent_message => 1, :annotations => 1, :before_id => nil} get_parsed_response(Endpoints.new.channel(channel_id, )) end |
#get_channels ⇒ Object
223 224 225 226 |
# File 'lib/ayadn/api.rb', line 223 def get_channels = {:count => 200, :recent_message => 1, :annotations => 1, :before_id => nil} get_parsed_response(Endpoints.new.channels()) end |
#get_checkins(options) ⇒ Object
14 15 16 17 |
# File 'lib/ayadn/api.rb', line 14 def get_checkins() = paginate , 'explore:checkins' get_parsed_response(Endpoints.new.checkins()) end |
#get_config ⇒ Object
238 239 240 |
# File 'lib/ayadn/api.rb', line 238 def get_config get_parsed_response(Endpoints.new.config_api_url) end |
#get_conversations(options) ⇒ Object
32 33 34 35 |
# File 'lib/ayadn/api.rb', line 32 def get_conversations() = paginate , 'explore:replies' get_explore(:conversations, ) end |
#get_convo(post_id, options = {}) ⇒ Object
77 78 79 |
# File 'lib/ayadn/api.rb', line 77 def get_convo(post_id, = {}) get_parsed_response(Endpoints.new.convo(post_id, )) end |
#get_details(post_id, options = {}) ⇒ Object
144 145 146 |
# File 'lib/ayadn/api.rb', line 144 def get_details(post_id, = {}) get_parsed_response(Endpoints.new.single_post(post_id, )) end |
#get_explore(explore, options) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ayadn/api.rb', line 37 def get_explore(explore, ) url = case explore when :trending Endpoints.new.trending() when :photos Endpoints.new.photos() when :conversations Endpoints.new.conversations() end get_parsed_response(url) end |
#get_file(file_id) ⇒ Object
166 167 168 |
# File 'lib/ayadn/api.rb', line 166 def get_file(file_id) get_parsed_response(Endpoints.new.file(file_id)) end |
#get_files_list(options) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/ayadn/api.rb', line 148 def get_files_list() array_of_hashes = [] unless [:all] resp = get_parsed_response(Endpoints.new.files_list()) resp['data'].each { |p| array_of_hashes << p } else = {:count => 200, :before_id => nil} endpoints = Endpoints.new loop do resp = get_parsed_response(endpoints.files_list()) resp['data'].each { |p| array_of_hashes << p } break unless resp['meta']['more'] = {:count => 200, :before_id => resp['meta']['min_id']} end end array_of_hashes end |
#get_followers(username) ⇒ Object
109 110 111 |
# File 'lib/ayadn/api.rb', line 109 def get_followers(username) build_list(username, :followers) end |
#get_followings(username) ⇒ Object
105 106 107 |
# File 'lib/ayadn/api.rb', line 105 def get_followings(username) build_list(username, :followings) end |
#get_global(options) ⇒ Object
19 20 21 22 |
# File 'lib/ayadn/api.rb', line 19 def get_global() = paginate , 'global' get_parsed_response(Endpoints.new.global()) end |
#get_hashtag(hashtag) ⇒ Object
81 82 83 |
# File 'lib/ayadn/api.rb', line 81 def get_hashtag(hashtag) get_parsed_response(Endpoints.new.hashtag(hashtag)) end |
#get_interactions ⇒ Object
61 62 63 |
# File 'lib/ayadn/api.rb', line 61 def get_interactions get_parsed_response(Endpoints.new.interactions) end |
#get_mentions(username, options) ⇒ Object
49 50 51 |
# File 'lib/ayadn/api.rb', line 49 def get_mentions(username, ) get_parsed_response(Endpoints.new.mentions(username, )) end |
#get_messages(channel_id, options) ⇒ Object
233 234 235 236 |
# File 'lib/ayadn/api.rb', line 233 def (channel_id, ) = paginate , "channel:#{channel_id}" get_parsed_response(Endpoints.new.(channel_id, )) end |
#get_muted ⇒ Object
“nil” as a first argument? the other method should be refactored
114 115 116 |
# File 'lib/ayadn/api.rb', line 114 def get_muted build_list(nil, :muted) end |
#get_photos(options) ⇒ Object
28 29 30 31 |
# File 'lib/ayadn/api.rb', line 28 def get_photos() = paginate , 'explore:photos' get_explore(:photos, ) end |
#get_posts(username, options) ⇒ Object
53 54 55 |
# File 'lib/ayadn/api.rb', line 53 def get_posts(username, ) get_parsed_response(Endpoints.new.posts(username, )) end |
#get_raw_list(username, target) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/ayadn/api.rb', line 122 def get_raw_list(username, target) = {:count => 200, :before_id => nil} bucket = [] # Fetch new items until the API says no more # This is chronologically reversed: start with current id, get 200 posts, get the post id we're at, then 200 again, etc loop do resp = get_parsed_response(get_list_url(username, target, )) bucket << resp break if resp['meta']['min_id'] == nil || resp['meta']['more'] == false = {:count => 200, :before_id => resp['meta']['min_id']} end bucket end |
#get_search(words, options) ⇒ Object
85 86 87 |
# File 'lib/ayadn/api.rb', line 85 def get_search(words, ) get_parsed_response(Endpoints.new.search(words, )) end |
#get_token_info ⇒ Object
65 66 67 |
# File 'lib/ayadn/api.rb', line 65 def get_token_info get_parsed_response(Endpoints.new.token_info) end |
#get_trending(options) ⇒ Object
24 25 26 27 |
# File 'lib/ayadn/api.rb', line 24 def get_trending() = paginate , 'explore:trending' get_explore(:trending, ) end |
#get_unified(options) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/ayadn/api.rb', line 5 def get_unified() # "paginate" fetches last post ID we've seen if the user asks for scrolling or asks to see new posts only = paginate , 'unified' # Create the API endpoint URL endpoint = Endpoints.new.unified() # Fetch the response from the ADN servers get_parsed_response(endpoint) end |
#get_user(username) ⇒ Object
136 137 138 |
# File 'lib/ayadn/api.rb', line 136 def get_user(username) get_parsed_response(Endpoints.new.user(username)) end |
#get_users(usernames) ⇒ Object
140 141 142 |
# File 'lib/ayadn/api.rb', line 140 def get_users(usernames) get_parsed_response(Endpoints.new.users(usernames)) end |
#get_whatstarred(username, options) ⇒ Object
57 58 59 |
# File 'lib/ayadn/api.rb', line 57 def get_whatstarred(username, ) get_parsed_response(Endpoints.new.whatstarred(username, )) end |
#get_whoreposted(post_id) ⇒ Object
69 70 71 |
# File 'lib/ayadn/api.rb', line 69 def get_whoreposted(post_id) get_parsed_response(Endpoints.new.whoreposted(post_id)) end |
#get_whostarred(post_id) ⇒ Object
73 74 75 |
# File 'lib/ayadn/api.rb', line 73 def get_whostarred(post_id) get_parsed_response(Endpoints.new.whostarred(post_id)) end |
#mute(username) ⇒ Object
178 179 180 |
# File 'lib/ayadn/api.rb', line 178 def mute(username) JSON.parse(CNX.post(Endpoints.new.mute(username))) end |
#repost(post_id) ⇒ Object
186 187 188 |
# File 'lib/ayadn/api.rb', line 186 def repost(post_id) JSON.parse(CNX.post(Endpoints.new.repost(post_id))) end |
#search_annotations(words, options) ⇒ Object
93 94 95 |
# File 'lib/ayadn/api.rb', line 93 def search_annotations words, get_parsed_response(Endpoints.new.search_annotations(words, )) end |
#search_channels(words, options) ⇒ Object
97 98 99 |
# File 'lib/ayadn/api.rb', line 97 def search_channels words, get_parsed_response(Endpoints.new.search_channels(words, )) end |
#search_messages(channel_id, words, options) ⇒ Object
101 102 103 |
# File 'lib/ayadn/api.rb', line 101 def channel_id, words, get_parsed_response(Endpoints.new.(channel_id, words, )) end |
#search_users(words, options) ⇒ Object
89 90 91 |
# File 'lib/ayadn/api.rb', line 89 def search_users words, get_parsed_response(Endpoints.new.search_users(words, )) end |
#star(post_id) ⇒ Object
170 171 172 |
# File 'lib/ayadn/api.rb', line 170 def star(post_id) JSON.parse(CNX.post(Endpoints.new.star(post_id))) end |
#unblock(username) ⇒ Object
210 211 212 |
# File 'lib/ayadn/api.rb', line 210 def unblock(username) JSON.parse(CNX.delete(Endpoints.new.block(username))) end |
#unfollow(username) ⇒ Object
202 203 204 |
# File 'lib/ayadn/api.rb', line 202 def unfollow(username) JSON.parse(CNX.delete(Endpoints.new.follow(username))) end |
#unmute(username) ⇒ Object
206 207 208 |
# File 'lib/ayadn/api.rb', line 206 def unmute(username) JSON.parse(CNX.delete(Endpoints.new.mute(username))) end |
#unrepost(post_id) ⇒ Object
214 215 216 217 218 219 220 221 |
# File 'lib/ayadn/api.rb', line 214 def unrepost(post_id) resp = JSON.parse(CNX.delete(Endpoints.new.repost(post_id))) if resp['data']['repost_of'] JSON.parse(CNX.delete(Endpoints.new.repost(resp['data']['repost_of']['id']))) else resp end end |