Class: MC2P::ResourceMixin
- Inherits:
-
Object
- Object
- MC2P::ResourceMixin
- Defined in:
- lib/mixins.rb
Overview
Basic info of the resource
Direct Known Subclasses
ActionsResourceMixin, ChangeResourceMixin, CreateResourceMixin, DeleteResourceMixin, DetailOnlyResourceMixin, Resource
Instance Method Summary collapse
-
#_one_item(func, data = nil, resource_id = nil) ⇒ Object
- 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.
- data passed in the request
- function to make the request
- Help function to make a request that return one item Params:
-
#detail_url(resource_id) ⇒ Object
- Params:
resource_id -
id used on the url returned Returns: url to request or change an item.
- Params:
-
#initialize(api_request, path, object_item_class, paginator_class) ⇒ ResourceMixin
constructor
- 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.
- Object item class used to return values
- Path used to make all the requests to the API
- Api request used to make all the requests to the API
- Initializes a resource Params:
Constructor Details
#initialize(api_request, path, object_item_class, paginator_class) ⇒ ResourceMixin
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
203 204 205 206 207 208 |
# 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 |
Instance Method Details
#_one_item(func, data = nil, resource_id = nil) ⇒ Object
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
223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# 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) ⇒ Object
Params:
resource_id-
id used on the url returned
Returns: url to request or change an item
213 214 215 |
# File 'lib/mixins.rb', line 213 def detail_url(resource_id) "#{@path}#{resource_id}/" end |