lib/puree/rest/base.rb in puree-2.2.0 vs lib/puree/rest/base.rb in puree-2.3.0
- old
+ new
@@ -23,13 +23,21 @@
end
@http_client = @http_client.headers(api_key_header(config[:api_key]))
@url = config[:url]
end
- # @param params [Hash]
+ # @param params [Hash] Combined GET and POST parameters for all records
# @param accept [Symbol]
# @return [HTTP::Response]
+ def all_complex(params: {}, accept: :xml)
+ post_request_collection params: params,
+ accept: accept
+ end
+
+ # @param params [Hash] GET parameters for all records
+ # @param accept [Symbol]
+ # @return [HTTP::Response]
def all(params: {}, accept: :xml)
get_request_collection params: params,
accept: accept
end
@@ -66,10 +74,19 @@
when :xml
return { 'Accept' => 'application/xml' }
end
end
+ def content_type_header(content_type)
+ case content_type
+ when :json
+ return { 'Content-Type' => 'application/json' }
+ when :xml
+ return { 'Content-Type' => 'application/xml' }
+ end
+ end
+
def api_key_header(key)
msg = 'API key incomplete in configuration'
raise msg if !key
{ 'api-key' => key }
end
@@ -92,19 +109,26 @@
def meta(type)
File.join "#{url_collection}-meta", type
end
+ # @return (see Puree::REST::Base#all_complex)
+ def post_request_collection(params: {}, accept: :xml)
+ @http_client = @http_client.headers(accept_header(accept))
+ @http_client = @http_client.headers(content_type_header(:json))
+ @http_client.post url_collection, json: params
+ end
+
# @return (see Puree::REST::Base#all)
def get_request_collection(params: {}, accept: :xml)
@http_client = @http_client.headers(accept_header(accept))
@http_client.get url_collection, params: params
end
# @return (see Puree::REST::Base#all)
def get_request_collection_subcollection(subcollection:, params: {}, accept: :xml)
@http_client = @http_client.headers(accept_header(accept))
- @http_client.get meta(url_collection_subcollection(subcollection)), params: params
+ @http_client.get url_collection_subcollection(subcollection), params: params
end
# @return (see Puree::REST::Base#all)
def get_request_singleton(id:, params: {}, accept: :xml)
@http_client = @http_client.headers(accept_header(accept))
\ No newline at end of file