Class: WpApiClient::Entities::Base
- Inherits:
-
Object
- Object
- WpApiClient::Entities::Base
show all
- Defined in:
- lib/wp_api_client/entities/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(resource) ⇒ Base
Returns a new instance of Base.
14
15
16
17
18
19
|
# File 'lib/wp_api_client/entities/base.rb', line 14
def initialize(resource)
unless resource.is_a? Hash
raise ArgumentError.new('Tried to initialize a WP-API resource with something other than a Hash')
end
@resource = resource
end
|
Instance Attribute Details
#resource ⇒ Object
Returns the value of attribute resource.
6
7
8
|
# File 'lib/wp_api_client/entities/base.rb', line 6
def resource
@resource
end
|
Class Method Details
.build(resource) ⇒ Object
8
9
10
11
12
|
# File 'lib/wp_api_client/entities/base.rb', line 8
def self.build(resource)
raise Exception if resource.nil?
type = WpApiClient::Entities::Types.find { |type| type.represents?(resource) }
type.new(resource)
end
|
Instance Method Details
#links ⇒ Object
21
22
23
|
# File 'lib/wp_api_client/entities/base.rb', line 21
def links
resource["_links"]
end
|
#relations(relation, relation_to_return = nil) ⇒ Object
25
26
27
28
29
30
31
32
33
|
# File 'lib/wp_api_client/entities/base.rb', line 25
def relations(relation, relation_to_return = nil)
relationship = Relationship.new(@resource, relation)
relations = relationship.get_relations
if relation_to_return
relations[relation_to_return]
else
relations
end
end
|