Class: Ayadn::API

Inherits:
Object
  • Object
show all
Defined in:
lib/ayadn/api.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build_query(arg) ⇒ Object



237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/ayadn/api.rb', line 237

def self.build_query(arg)
  count = Settings.options[:counts][:default]
  if arg[:count]
    if arg[:count].to_s.is_integer?
      count = arg[:count]
    end
  end
  directed = Settings.options[:timeline][:directed]
  if arg[:directed]
    if arg[:directed] == 0 || arg[:directed] == 1
      directed = arg[:directed]
    end
  end
  deleted = Settings.options[:timeline][:deleted]
  if arg[:deleted]
    if arg[:deleted] == 0 || arg[:deleted] == 1
      deleted = arg[:deleted]
    end
  end
  html = Settings.options[:timeline][:html]
  if arg[:html]
    if arg[:html] == 0 || arg[:html] == 1
      html = arg[:html]
    end
  end
  annotations = Settings.options[:timeline][:annotations]
  if arg[:annotations]
    if arg[:annotations] == 0 || arg[:annotations] == 1
      annotations = arg[:annotations]
    end
  end
  if arg[:since_id]
    "&count=#{count}&include_html=#{html}&include_directed=#{directed}&include_deleted=#{deleted}&include_annotations=#{annotations}&since_id=#{arg[:since_id]}"
  elsif arg[:recent_message]
    "&count=#{count}&include_html=#{html}&include_directed=#{directed}&include_deleted=#{deleted}&include_annotations=#{annotations}&include_recent_message=#{arg[:recent_message]}"
  else
    "&count=#{count}&include_html=#{html}&include_directed=#{directed}&include_deleted=#{deleted}&include_annotations=#{annotations}"
  end
end

Instance Method Details

#block(username) ⇒ Object



165
166
167
# File 'lib/ayadn/api.rb', line 165

def block(username)
  JSON.parse(CNX.post(Endpoints.new.block(username)))
end

#check_response_meta_code(res) ⇒ Object



229
230
231
232
233
234
235
# File 'lib/ayadn/api.rb', line 229

def check_response_meta_code(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



177
178
179
# File 'lib/ayadn/api.rb', line 177

def delete_message(channel_id, message_id)
  JSON.parse(CNX.delete(Endpoints.new.delete_message(channel_id, message_id)))
end

#delete_post(post_id) ⇒ Object



173
174
175
# File 'lib/ayadn/api.rb', line 173

def delete_post(post_id)
  JSON.parse(CNX.delete(Endpoints.new.delete_post(post_id)))
end

#follow(post_id) ⇒ Object



157
158
159
# File 'lib/ayadn/api.rb', line 157

def follow(post_id)
  JSON.parse(CNX.post(Endpoints.new.follow(post_id)))
end

#get_blockedObject



108
109
110
# File 'lib/ayadn/api.rb', line 108

def get_blocked
  build_list(nil, :blocked)
end

#get_channelsObject



206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/ayadn/api.rb', line 206

def get_channels
  options = {:count => 200, :recent_message => 1, :annotations => 1, :before_id => nil}
  get_parsed_response(Endpoints.new.channels(options))
  # big = []
  # loop do
  #   resp = get_parsed_response(Endpoints.new.channels(options))
  #   #check_response_meta_code(resp)
  #   big << resp
  #   break if resp['meta']['more'] == false
  #   options = {:count => 200, :before_id => resp['meta']['min_id']}
  # end
  # big
end

#get_checkins(options) ⇒ Object



10
11
12
13
# File 'lib/ayadn/api.rb', line 10

def get_checkins(options)
  options = paginate options, 'explore:checkins'
  get_parsed_response(Endpoints.new.checkins(options))
end

#get_configObject



225
226
227
# File 'lib/ayadn/api.rb', line 225

def get_config
  get_parsed_response(Endpoints.new.config_api_url)
end

#get_conversations(options) ⇒ Object



28
29
30
31
# File 'lib/ayadn/api.rb', line 28

def get_conversations(options)
  options = paginate options, 'explore:replies'
  get_explore(:conversations, options)
end

#get_convo(post_id, options = {}) ⇒ Object



68
69
70
# File 'lib/ayadn/api.rb', line 68

def get_convo(post_id, options = {})
  get_parsed_response(Endpoints.new.convo(post_id, options))
end

#get_details(post_id, options = {}) ⇒ Object



128
129
130
# File 'lib/ayadn/api.rb', line 128

def get_details(post_id, options = {})
  get_parsed_response(Endpoints.new.single_post(post_id, options))
end

#get_explore(explore, options) ⇒ Object



33
34
35
36
37
38
# File 'lib/ayadn/api.rb', line 33

def get_explore(explore, options)
  url = Endpoints.new.trending(options) if explore == :trending
  url = Endpoints.new.photos(options) if explore == :photos
  url = Endpoints.new.conversations(options) if explore == :conversations
  get_parsed_response(url)
end

#get_file(file_id) ⇒ Object



149
150
151
# File 'lib/ayadn/api.rb', line 149

def get_file(file_id)
  get_parsed_response(Endpoints.new.file(file_id))
end

#get_files_list(options) ⇒ Object



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/ayadn/api.rb', line 132

def get_files_list(options)
  array_of_hashes = []
  unless options[:all]
    resp = get_parsed_response(Endpoints.new.files_list(options))
    resp['data'].each { |p| array_of_hashes << p }
  else
    options = {:count => 200, :before_id => nil}
    loop do
      resp = get_parsed_response(Endpoints.new.files_list(options))
      resp['data'].each { |p| array_of_hashes << p }
      break unless resp['meta']['more']
      options = {:count => 200, :before_id => resp['meta']['min_id']}
    end
  end
  array_of_hashes
end

#get_followers(username) ⇒ Object



100
101
102
# File 'lib/ayadn/api.rb', line 100

def get_followers(username)
  build_list(username, :followers)
end

#get_followings(username) ⇒ Object



96
97
98
# File 'lib/ayadn/api.rb', line 96

def get_followings(username)
  build_list(username, :followings)
end

#get_global(options) ⇒ Object



15
16
17
18
# File 'lib/ayadn/api.rb', line 15

def get_global(options)
  options = paginate options, 'global'
  get_parsed_response(Endpoints.new.global(options))
end

#get_hashtag(hashtag) ⇒ Object



72
73
74
# File 'lib/ayadn/api.rb', line 72

def get_hashtag(hashtag)
  get_parsed_response(Endpoints.new.hashtag(hashtag))
end

#get_interactionsObject



52
53
54
# File 'lib/ayadn/api.rb', line 52

def get_interactions
  get_parsed_response(Endpoints.new.interactions)
end

#get_mentions(username, options) ⇒ Object



40
41
42
# File 'lib/ayadn/api.rb', line 40

def get_mentions(username, options)
  get_parsed_response(Endpoints.new.mentions(username, options))
end

#get_messages(channel_id, options) ⇒ Object



220
221
222
223
# File 'lib/ayadn/api.rb', line 220

def get_messages(channel_id, options)
  options = paginate options, "channel:#{channel_id}"
  get_parsed_response(Endpoints.new.messages(channel_id, options))
end

#get_mutedObject



104
105
106
# File 'lib/ayadn/api.rb', line 104

def get_muted
  build_list(nil, :muted)
end

#get_photos(options) ⇒ Object



24
25
26
27
# File 'lib/ayadn/api.rb', line 24

def get_photos(options)
  options = paginate options, 'explore:photos'
  get_explore(:photos, options)
end

#get_posts(username, options) ⇒ Object



44
45
46
# File 'lib/ayadn/api.rb', line 44

def get_posts(username, options)
  get_parsed_response(Endpoints.new.posts(username, options))
end

#get_raw_list(username, target) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/ayadn/api.rb', line 112

def get_raw_list(username, target)
  options = {:count => 200, :before_id => nil}
  big = []
  loop do
    resp = get_parsed_response(get_list_url(username, target, options))
    big << resp
    break if resp['meta']['min_id'] == nil || resp['meta']['more'] == false
    options = {:count => 200, :before_id => resp['meta']['min_id']}
  end
  big
end

#get_search(words, options) ⇒ Object



76
77
78
# File 'lib/ayadn/api.rb', line 76

def get_search(words, options)
  get_parsed_response(Endpoints.new.search(words, options))
end

#get_token_infoObject



56
57
58
# File 'lib/ayadn/api.rb', line 56

def get_token_info
  get_parsed_response(Endpoints.new.token_info)
end


20
21
22
23
# File 'lib/ayadn/api.rb', line 20

def get_trending(options)
  options = paginate options, 'explore:trending'
  get_explore(:trending, options)
end

#get_unified(options) ⇒ Object



5
6
7
8
# File 'lib/ayadn/api.rb', line 5

def get_unified(options)
  options = paginate options, 'unified'
  get_parsed_response(Endpoints.new.unified(options))
end

#get_user(username) ⇒ Object



124
125
126
# File 'lib/ayadn/api.rb', line 124

def get_user(username)
  get_parsed_response(Endpoints.new.user(username))
end

#get_whatstarred(username, options) ⇒ Object



48
49
50
# File 'lib/ayadn/api.rb', line 48

def get_whatstarred(username, options)
  get_parsed_response(Endpoints.new.whatstarred(username, options))
end

#get_whoreposted(post_id) ⇒ Object



60
61
62
# File 'lib/ayadn/api.rb', line 60

def get_whoreposted(post_id)
  get_parsed_response(Endpoints.new.whoreposted(post_id))
end

#get_whostarred(post_id) ⇒ Object



64
65
66
# File 'lib/ayadn/api.rb', line 64

def get_whostarred(post_id)
  get_parsed_response(Endpoints.new.whostarred(post_id))
end

#mute(post_id) ⇒ Object



161
162
163
# File 'lib/ayadn/api.rb', line 161

def mute(post_id)
  JSON.parse(CNX.post(Endpoints.new.mute(post_id)))
end

#repost(post_id) ⇒ Object



169
170
171
# File 'lib/ayadn/api.rb', line 169

def repost(post_id)
  JSON.parse(CNX.post(Endpoints.new.repost(post_id)))
end

#search_annotations(words, options) ⇒ Object



84
85
86
# File 'lib/ayadn/api.rb', line 84

def search_annotations words, options
  get_parsed_response(Endpoints.new.search_annotations(words, options))
end

#search_channels(words, options) ⇒ Object



88
89
90
# File 'lib/ayadn/api.rb', line 88

def search_channels words, options
  get_parsed_response(Endpoints.new.search_channels(words, options))
end

#search_messages(channel_id, words, options) ⇒ Object



92
93
94
# File 'lib/ayadn/api.rb', line 92

def search_messages channel_id, words, options
  get_parsed_response(Endpoints.new.search_messages(channel_id, words, options))
end

#search_users(words, options) ⇒ Object



80
81
82
# File 'lib/ayadn/api.rb', line 80

def search_users words, options
  get_parsed_response(Endpoints.new.search_users(words, options))
end

#star(post_id) ⇒ Object



153
154
155
# File 'lib/ayadn/api.rb', line 153

def star(post_id)
  JSON.parse(CNX.post(Endpoints.new.star(post_id)))
end

#unblock(username) ⇒ Object



193
194
195
# File 'lib/ayadn/api.rb', line 193

def unblock(username)
  JSON.parse(CNX.delete(Endpoints.new.block(username)))
end

#unfollow(username) ⇒ Object



185
186
187
# File 'lib/ayadn/api.rb', line 185

def unfollow(username)
  JSON.parse(CNX.delete(Endpoints.new.follow(username)))
end

#unmute(username) ⇒ Object



189
190
191
# File 'lib/ayadn/api.rb', line 189

def unmute(username)
  JSON.parse(CNX.delete(Endpoints.new.mute(username)))
end

#unrepost(post_id) ⇒ Object



197
198
199
200
201
202
203
204
# File 'lib/ayadn/api.rb', line 197

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

#unstar(post_id) ⇒ Object



181
182
183
# File 'lib/ayadn/api.rb', line 181

def unstar(post_id)
  JSON.parse(CNX.delete(Endpoints.new.star(post_id)))
end