Module: Harpy::Resource::ClassMethods
- Defined in:
- lib/harpy/resource.rb
Instance Method Summary collapse
- #delete_from_id(id) ⇒ Object
- #delete_from_url(url) ⇒ Object
- #delete_from_urn(urn) ⇒ Object
- #from_id(id) ⇒ Object
- #from_url(url) ⇒ Object
- #from_urn(urn) ⇒ Object
- #lookup_ancestors ⇒ Object
- #resource_name ⇒ Object
- #search(conditions = {}) ⇒ Object
- #uman_attribute_name(attr, options = {}) ⇒ Object
- #urn(id) ⇒ Object
- #with_url(url) ⇒ Object
Instance Method Details
#delete_from_id(id) ⇒ Object
93 94 95 |
# File 'lib/harpy/resource.rb', line 93 def delete_from_id(id) delete_from_urn urn id end |
#delete_from_url(url) ⇒ Object
84 85 86 |
# 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) ⇒ Object
88 89 90 91 |
# 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) ⇒ Object
51 52 53 |
# File 'lib/harpy/resource.rb', line 51 def from_id(id) from_urn urn id end |
#from_url(url) ⇒ Object
37 38 39 40 41 42 43 44 |
# 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) ⇒ Object
46 47 48 49 |
# 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 ⇒ Object
101 102 103 |
# File 'lib/harpy/resource.rb', line 101 def lookup_ancestors [self] end |
#resource_name ⇒ Object
59 60 61 |
# File 'lib/harpy/resource.rb', line 59 def resource_name name.underscore end |
#search(conditions = {}) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# 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 = {}) ⇒ Object
97 98 99 |
# File 'lib/harpy/resource.rb', line 97 def uman_attribute_name(attr, = {}) attr end |
#urn(id) ⇒ Object
55 56 57 |
# File 'lib/harpy/resource.rb', line 55 def urn(id) raise NotImplementedError end |
#with_url(url) ⇒ Object
75 76 77 78 79 80 81 82 |
# 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 |