module Harpy::Resource::ClassMethods
Public Instance Methods
delete_from_id(id)
click to toggle source
# File lib/harpy/resource.rb, line 93 def delete_from_id(id) delete_from_urn urn id end
delete_from_url(url)
click to toggle source
# File lib/harpy/resource.rb, line 84 def delete_from_url(url) delete_from_url_handler Harpy.client.delete url end
delete_from_urn(urn)
click to toggle source
# File lib/harpy/resource.rb, line 88 def delete_from_urn(urn) url = Harpy.entry_point.urn urn url ? delete_from_url(url) : false end
from_id(id)
click to toggle source
# File lib/harpy/resource.rb, line 51 def from_id(id) from_urn urn id end
from_url(url)
click to toggle source
# File lib/harpy/resource.rb, line 37 def from_url(url) case url when Array Harpy.client.run(Harpy.client.get url).collect{|response| from_url_handler response} else from_url_handler Harpy.client.get url end end
from_urn(urn)
click to toggle source
# File lib/harpy/resource.rb, line 46 def from_urn(urn) url = Harpy.entry_point.urn urn from_url url if url end
lookup_ancestors()
click to toggle source
# File lib/harpy/resource.rb, line 101 def lookup_ancestors [self] end
resource_name()
click to toggle source
# File lib/harpy/resource.rb, line 59 def resource_name name.underscore end
search(conditions={})
click to toggle source
# File lib/harpy/resource.rb, line 63 def search(conditions={}) response = Harpy.client.get url, :params => conditions case response.code when 200 parsed = JSON.parse response.body items = parsed[resource_name].collect{|model| new model} Harpy::Collection.new parsed.merge(:items => items) else Harpy.client.invalid_code response end end
uman_attribute_name(attr, options = {})
click to toggle source
# File lib/harpy/resource.rb, line 97 def uman_attribute_name(attr, options = {}) attr end
urn(id)
click to toggle source
# File lib/harpy/resource.rb, line 55 def urn(id) raise NotImplementedError end
with_url(url) { || ... }
click to toggle source
# File lib/harpy/resource.rb, line 75 def with_url(url) raise ArgumentError unless block_given? key = "#{resource_name}_url" old, Thread.current[key] = Thread.current[key], url result = yield Thread.current[key] = old result end
Private Instance Methods
delete_from_url_handler(response)
click to toggle source
# File lib/harpy/resource.rb, line 122 def delete_from_url_handler(response) case response.code when 204 true when 404 false else Harpy.client.invalid_code response end end
from_url_handler(response)
click to toggle source
# File lib/harpy/resource.rb, line 111 def from_url_handler(response) case response.code when 200 new JSON.parse response.body when 404 nil else Harpy.client.invalid_code response end end
url()
click to toggle source
# File lib/harpy/resource.rb, line 107 def url Thread.current["#{resource_name}_url"] || Harpy.entry_point.resource_url(resource_name) end