Module: Celery::EndpointMethods::ClassMethods
Instance Method Summary collapse
- #all(args = {}) ⇒ Object
- #build_collection(collection) ⇒ Object
- #create(attrs = {}) ⇒ Object
- #endpoint_path ⇒ Object
- #endpoint_resource ⇒ Object
- #get(id) ⇒ Object
- #object_root ⇒ Object
- #options(args = {}) ⇒ Object
Instance Method Details
#all(args = {}) ⇒ Object
6 7 8 9 |
# File 'lib/celery/endpoint_methods.rb', line 6 def all(args={}) response = HTTParty.get("#{endpoint_path}?#{}") return build_collection(response[endpoint_resource]) end |
#build_collection(collection) ⇒ Object
11 12 13 |
# File 'lib/celery/endpoint_methods.rb', line 11 def build_collection(collection) collection.map { |item| self.new(item) } end |
#create(attrs = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/celery/endpoint_methods.rb', line 20 def create(attrs={}) response = HTTParty.post( "#{endpoint_path}?#{}", body: { object_root => attrs }.to_json, headers: { 'Content-Type' => 'application/json' } ) self.new(response[self::ENDPOINT_RESOURCE_SINGULAR]) end |
#endpoint_path ⇒ Object
30 31 32 |
# File 'lib/celery/endpoint_methods.rb', line 30 def endpoint_path Celery.endpoint + endpoint_resource end |
#endpoint_resource ⇒ Object
34 35 36 |
# File 'lib/celery/endpoint_methods.rb', line 34 def endpoint_resource self::ENDPOINT_RESOURCE end |
#get(id) ⇒ Object
15 16 17 18 |
# File 'lib/celery/endpoint_methods.rb', line 15 def get(id) response = HTTParty.get("#{endpoint_path}/#{id}?#{}") self.new(response[self::ENDPOINT_RESOURCE_SINGULAR]) end |
#object_root ⇒ Object
38 39 40 |
# File 'lib/celery/endpoint_methods.rb', line 38 def object_root self::ENDPOINT_RESOURCE_SINGULAR end |
#options(args = {}) ⇒ Object
42 43 44 |
# File 'lib/celery/endpoint_methods.rb', line 42 def (args={}) Celery.(args) end |