Module: Ribose::ResourceHelper

Included in:
Base, Message
Defined in:
lib/ribose/resource_helper.rb

Instance Method Summary collapse

Instance Method Details

#resourceObject

Resource

This is the key interface for any resource and every single resource should implement this method.Ideally this should reflect resource name in singular form, eg: space.

Once we’ve this method implemented then this module will try to auto-generate all of the related helper methods, but if we need something different that the standard format then we can always overirde that in those classes.

Raises:

  • (NotImplementedError)


15
16
17
# File 'lib/ribose/resource_helper.rb', line 15

def resource
  raise NotImplementedError
end

#resource_idObject

Resource Id

The id for the key component of any of the classes in Ribose module, ideally we will have that one as default attribtue to the base class, but we can override it if necessary.

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/ribose/resource_helper.rb', line 27

def resource_id
  raise NotImplementedError
end

#resource_keyObject

Resource Key

The resource key is the key that we use to build any of the post/put request body, and ideally it’s the resoruce value, but occassionally it might be diffrent for any of the reason, so this method will keep that on portable.



49
50
51
# File 'lib/ribose/resource_helper.rb', line 49

def resource_key
  resource
end

#resource_pathObject

Resource Path

This represent a single resource in a Restfull API. In Ribose API structure, it’s ‘resources/:id`, so we will use that one as default. If we need something different then please override this method.



77
78
79
# File 'lib/ribose/resource_helper.rb', line 77

def resource_path
  [resources_path, resource_id].join("/")
end

#resourcesObject

Resources

The plural version of the resoruce name, ideally we will use this one to to identify an array or resources.



37
38
39
# File 'lib/ribose/resource_helper.rb', line 37

def resources
  [resource, "s"].join
end

#resources_pathObject

Resources Path

This represent a restfull resoruce path, and internally this will be used to build the the api endpoint path for any specifies resources.

Based on the Ribose API structure it’s pretty similiar to the resources value with some minor exception of the nested resoruces, so we are keeping the resources as default but we can override this when necessary.



65
66
67
# File 'lib/ribose/resource_helper.rb', line 65

def resources_path
  resources
end