Class: ApipieBindings::Resource
- Inherits:
-
Object
- Object
- ApipieBindings::Resource
- Defined in:
- lib/apipie_bindings/resource.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#action(name) ⇒ ApipieBindings::Action
Get ApipieBindings::Action.
-
#actions ⇒ Array<ApipieBindings::Action>
Get list of all actions for a resource.
-
#apidoc ⇒ Hash
Get API documentation for a resource.
-
#call(action, params = {}, headers = {}, options = {}) ⇒ Hash
Execute an action on a resource.
-
#has_action?(name) ⇒ Bool
Determine if resource has a particular action.
-
#initialize(name, api) ⇒ Resource
constructor
A new instance of Resource.
-
#inspect ⇒ String
Get string representation.
-
#singular_name ⇒ String
Get simiple string representation.
-
#to_s ⇒ String
Get string representation.
Constructor Details
#initialize(name, api) ⇒ Resource
Returns a new instance of Resource.
7 8 9 10 11 |
# File 'lib/apipie_bindings/resource.rb', line 7 def initialize(name, api) raise NameError.new("Resource '#{name}' does not exist in the API") unless api.apidoc[:docs][:resources].key?(name) @name = name @api = api end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/apipie_bindings/resource.rb', line 5 def name @name end |
Instance Method Details
#action(name) ⇒ ApipieBindings::Action
Get ApipieBindings::Action
50 51 52 |
# File 'lib/apipie_bindings/resource.rb', line 50 def action(name) ApipieBindings::Action.new(@name, name, @api) end |
#actions ⇒ Array<ApipieBindings::Action>
Get list of all actions for a resource
34 35 36 |
# File 'lib/apipie_bindings/resource.rb', line 34 def actions apidoc[:methods].map { |a| action(a[:name].to_sym) } end |
#apidoc ⇒ Hash
Get API documentation for a resource
27 28 29 |
# File 'lib/apipie_bindings/resource.rb', line 27 def apidoc @api.apidoc[:docs][:resources][@name] end |
#call(action, params = {}, headers = {}, options = {}) ⇒ Hash
Execute an action on a resource
20 21 22 |
# File 'lib/apipie_bindings/resource.rb', line 20 def call(action, params={}, headers={}, ={}) @api.call(@name, action, params, headers, ) end |
#has_action?(name) ⇒ Bool
Determine if resource has a particular action
42 43 44 |
# File 'lib/apipie_bindings/resource.rb', line 42 def has_action?(name) apidoc[:methods].any? { |action| action[:name].to_sym == name } end |
#inspect ⇒ String
Note:
same as to_s method
Get string representation
72 73 74 |
# File 'lib/apipie_bindings/resource.rb', line 72 def inspect to_s end |
#singular_name ⇒ String
Get simiple string representation
57 58 59 |
# File 'lib/apipie_bindings/resource.rb', line 57 def singular_name ApipieBindings::Inflector.singularize(@name.to_s) end |
#to_s ⇒ String
Get string representation
64 65 66 |
# File 'lib/apipie_bindings/resource.rb', line 64 def to_s "<Resource :#{@name}>" end |