class MC2P::ResourceMixin
Basic info of the resource
Public Class Methods
new(api_request, path, object_item_class, paginator_class)
click to toggle source
Initializes a resource Params:
api_request
-
Api request used to make all the requests to the API
path
-
Path used to make all the requests to the API
object_item_class
-
Object item class used to return values
paginator_class
-
Paginator
class used to return values
# File lib/mixins.rb, line 203 def initialize(api_request, path, object_item_class, paginator_class) @api_request = api_request @path = path @object_item_class = object_item_class @paginator_class = paginator_class end
Public Instance Methods
_one_item(func, data = nil, resource_id = nil)
click to toggle source
Help function to make a request that return one item Params:
func
-
function to make the request
data
-
data passed in the request
resource_id
-
id to use on the requested url
Returns: an object item that represent the item returned
# File lib/mixins.rb, line 223 def _one_item(func, data = nil, resource_id = nil) url = resource_id.nil? ? @path : detail_url(resource_id) obj_data = @api_request.send( func, url, data, nil, self, resource_id ) @object_item_class.new(obj_data, self) end
detail_url(resource_id)
click to toggle source
Params:
resource_id
-
id used on the url returned
Returns: url to request or change an item
# File lib/mixins.rb, line 213 def detail_url(resource_id) "#{@path}#{resource_id}/" end