Module: Celery::EndpointMethods::ClassMethods

Included in:
Order, Product
Defined in:
lib/celery/endpoint_methods.rb

Instance Method Summary collapse

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}?#{options}")
  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}?#{options}",
    body:    { object_root => attrs }.to_json,
    headers: { 'Content-Type' => 'application/json' }
  )

  self.new(response[self::ENDPOINT_RESOURCE_SINGULAR])
end

#endpoint_pathObject



30
31
32
# File 'lib/celery/endpoint_methods.rb', line 30

def endpoint_path
  Celery.endpoint + endpoint_resource
end

#endpoint_resourceObject



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}?#{options}")
  self.new(response[self::ENDPOINT_RESOURCE_SINGULAR])
end

#object_rootObject



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 options(args={})
  Celery.parameterize_options(args)
end