class Contentful::Management::ResourceRequester
Attributes
client[R]
resource_class[R]
Public Class Methods
new(client, resource_class)
click to toggle source
# File lib/contentful/management/resource_requester.rb, line 10 def initialize(client, resource_class) @client = client @resource_class = resource_class end
Public Instance Methods
all(endpoint_options = {}, query = {}, headers = {})
click to toggle source
# File lib/contentful/management/resource_requester.rb, line 15 def all(endpoint_options = {}, query = {}, headers = {}) query = resource_class.pre_process_params(query) get(endpoint_options, query, headers) end
archive(object, endpoint_options = {}, headers = {})
click to toggle source
# File lib/contentful/management/resource_requester.rb, line 47 def archive(object, endpoint_options = {}, headers = {}) update(object, endpoint_options, {}, headers) end
Also aliased as: publish
create(endpoint_options = {}, attributes = {})
click to toggle source
# File lib/contentful/management/resource_requester.rb, line 24 def create(endpoint_options = {}, attributes = {}) custom_id = attributes.is_a?(Hash) ? attributes[:id] : nil request = Request.new( client, resource_class.build_endpoint(endpoint_options), resource_class.create_attributes(client, attributes.clone), nil, resource_class.create_headers(client, attributes) ) response = custom_id.nil? ? request.post : request.put resource = ResourceBuilder.new(response, client).run resource.after_create(attributes) if resource_class?(resource) resource end
destroy(endpoint_options = {}, attributes = {}, headers = {})
click to toggle source
# File lib/contentful/management/resource_requester.rb, line 43 def destroy(endpoint_options = {}, attributes = {}, headers = {}) delete(endpoint_options, attributes, headers) end
find(endpoint_options = {})
click to toggle source
# File lib/contentful/management/resource_requester.rb, line 20 def find(endpoint_options = {}) get(endpoint_options) end
unarchive(object, endpoint_options = {}, headers = {})
click to toggle source
# File lib/contentful/management/resource_requester.rb, line 52 def unarchive(object, endpoint_options = {}, headers = {}) object.refresh_data(delete(endpoint_options, {}, headers)) end
Also aliased as: unpublish
update(object, endpoint_options = {}, attributes = {}, headers = {})
click to toggle source
# File lib/contentful/management/resource_requester.rb, line 39 def update(object, endpoint_options = {}, attributes = {}, headers = {}) object.refresh_data(put(endpoint_options, attributes, headers, object)) end
Private Instance Methods
delete(endpoint_options = {}, attributes = {}, headers = {})
click to toggle source
# File lib/contentful/management/resource_requester.rb, line 88 def delete(endpoint_options = {}, attributes = {}, headers = {}) request = Request.new( client, resource_class.build_endpoint(endpoint_options), attributes, nil, headers ) response = request.delete return true if response.status == :no_content ResourceBuilder.new(response, client).run end
get(endpoint_options = {}, query = {}, headers = {})
click to toggle source
# File lib/contentful/management/resource_requester.rb, line 65 def get(endpoint_options = {}, query = {}, headers = {}) request = Request.new( client, resource_class.build_endpoint(endpoint_options), query, nil, headers ) ResourceBuilder.new(request.get, client).run end
put(endpoint_options = {}, attributes = {}, headers = {}, object = nil)
click to toggle source
# File lib/contentful/management/resource_requester.rb, line 76 def put(endpoint_options = {}, attributes = {}, headers = {}, object = nil) is_update = !object.nil? && object.id request = Request.new( client, resource_class.build_endpoint(endpoint_options), attributes, nil, headers ) ResourceBuilder.new(is_update ? request.put : request.post, client).run end
resource_class?(object)
click to toggle source
# File lib/contentful/management/resource_requester.rb, line 59 def resource_class?(object) object.resource? rescue StandardError false end