lib/yao/resources/restfully_accessible.rb in yao-0.15.0 vs lib/yao/resources/restfully_accessible.rb in yao-0.16.0
- old
+ new
@@ -146,11 +146,11 @@
# @param id_or_name_or_permalink [Stirng]
# @param query [Hash]
# @return [Yao::Resources::*]
def get!(id_or_name_or_permalink, query={})
get(id_or_name_or_permalink, query)
- rescue Yao::ItemNotFound, Yao::NotFound
+ rescue Yao::ItemNotFound, Yao::NotFound, Yao::InvalidResponse
nil
end
def find_by_name(name, query={})
list(query.merge({"name" => name}))
@@ -186,10 +186,11 @@
# @return [String]
def destroy(id)
res = DELETE(create_url(id))
res.body
end
+ alias delete destroy
private
# returns pathname of resource URL
# @param subpath [String]
@@ -236,10 +237,10 @@
begin
GET(create_url(name), query)
rescue => e
raise e unless e.class == Yao::ItemNotFound || e.class == Yao::NotFound
- item = find_by_name(name)
+ item = find_by_name(name).select { |r| r.name == name }
if item.size > 1
raise Yao::TooManyItemFonud.new("More than one resource exists with the name '#{name}'")
elsif item.size.zero?
raise Yao::InvalidResponse.new("No resource exists with the name '#{name}'")
end