lib/ayadn/api.rb in ayadn-1.4.6 vs lib/ayadn/api.rb in ayadn-1.5.0
- old
+ new
@@ -123,10 +123,14 @@
def get_user(username)
get_parsed_response(Endpoints.new.user(username))
end
+ def get_users(usernames)
+ get_parsed_response(Endpoints.new.users(usernames))
+ end
+
def get_details(post_id, options = {})
get_parsed_response(Endpoints.new.single_post(post_id, options))
end
def get_files_list(options)
@@ -152,16 +156,16 @@
def star(post_id)
JSON.parse(CNX.post(Endpoints.new.star(post_id)))
end
- def follow(post_id)
- JSON.parse(CNX.post(Endpoints.new.follow(post_id)))
+ def follow(username)
+ JSON.parse(CNX.post(Endpoints.new.follow(username)))
end
- def mute(post_id)
- JSON.parse(CNX.post(Endpoints.new.mute(post_id)))
+ def mute(username)
+ JSON.parse(CNX.post(Endpoints.new.mute(username)))
end
def block(username)
JSON.parse(CNX.post(Endpoints.new.block(username)))
end
@@ -233,46 +237,23 @@
Errors.global_error({error: nil, caller: caller, data: [res['meta']]})
end
end
def self.build_query(arg)
- count = Settings.options[:counts][:default]
- if arg[:count]
- if arg[:count].to_s.is_integer?
- count = arg[:count]
- end
+ if arg[:count].to_s.is_integer?
+ count = arg[:count]
+ else
+ count = Settings.options[:counts][:default]
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
+ directed = arg[:directed] || Settings.options[:timeline][:directed]
+ html = arg[:html] || Settings.options[:timeline][:html]
if arg[:since_id]
- "&count=#{count}&include_html=#{html}&include_directed=#{directed}&include_deleted=#{deleted}&include_annotations=#{annotations}&since_id=#{arg[:since_id]}"
+ "&count=#{count}&include_html=#{html}&include_directed=#{directed}&include_deleted=0&include_annotations=1&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]}"
+ "&count=#{count}&include_html=#{html}&include_directed=#{directed}&include_deleted=0&include_annotations=1&include_recent_message=#{arg[:recent_message]}"
else
- "&count=#{count}&include_html=#{html}&include_directed=#{directed}&include_deleted=#{deleted}&include_annotations=#{annotations}"
+ "&count=#{count}&include_html=#{html}&include_directed=#{directed}&include_deleted=0&include_annotations=1"
end
end
private
@@ -299,10 +280,11 @@
options = {:count => 200, :before_id => nil}
big_hash = {}
loop do
resp = get_parsed_response(get_list_url(username, target, options))
abort(Status.user_404(username)) if resp['meta']['code'] == 404
- big_hash.merge!(Workers.extract_users(resp))
+ users = Workers.extract_users(resp)
+ big_hash.merge!(users)
break if resp['meta']['min_id'] == nil
options = {:count => 200, :before_id => resp['meta']['min_id']}
end
big_hash
end