Class: Jirafe::Resource::JirafeResource
Direct Known Subclasses
Application, Resources, Site, Sites::AbandonRate, Sites::AbandonedAverageOrderValue, Sites::AbandonedCarts, Sites::AbandonedRevenue, Sites::AverageOrderValue, Sites::BouncesRate, Sites::CartSegmentation, Sites::ConversionRate, Sites::Conversions, Sites::Customers, Sites::Dashboard, Sites::Keywords, Sites::OrdersStatus, Sites::Origins, Sites::PeriodData, Sites::Products, Sites::Referers, Sites::Revenues, Sites::RevenuesAverage, Sites::SegmentsCarts, Sites::SegmentsSales, Sites::TotalCarts, Sites::Translations, Sites::VisitorsInterest, Sites::Visits, Status, Version
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Model
#attributes, #attributes_for_change, #create, included, #initialize, #reinitialize, #update
included
Class Method Details
.create(resource) ⇒ Object
54
55
56
57
58
|
# File 'lib/jirafe/resource/jirafe_resource.rb', line 54
def create(resource)
resource_id, parent_identifiers = identifiers_from_resource(resource)
response = post(resource_url(resource_id, *parent_identifiers), options_with_token({:body => resource.attributes_for_change(:create)}))
handle_response(resource, response)
end
|
.list(*parent_identifiers) ⇒ Object
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/jirafe/resource/jirafe_resource.rb', line 35
def list(*parent_identifiers)
if parent_identifiers.last.is_a?(Hash)
options = {:query => parent_identifiers.pop }
end
response = get(resource_url(nil, *parent_identifiers), options_with_token(options || {}))
check_response_for_exception(response)
response.parsed_response.map do |item|
self.new(item)
end
end
|
.parent(parent = nil) ⇒ Object
.parent_path(*parent_identifiers) ⇒ Object
27
28
29
|
# File 'lib/jirafe/resource/jirafe_resource.rb', line 27
def parent_path(*parent_identifiers)
parent.nil? ? nil : parent.resource_url(*parent_identifiers)
end
|
.path(path = nil) ⇒ Object
Also known as:
url
.resource_url(identifier = nil, *parent_identifiers) ⇒ Object
31
32
33
|
# File 'lib/jirafe/resource/jirafe_resource.rb', line 31
def resource_url(identifier = nil, *parent_identifiers)
[parent_path(*parent_identifiers), path, identifier].compact.join("/")
end
|
.retrieve(identifier = nil, *parent_identifiers) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/jirafe/resource/jirafe_resource.rb', line 46
def retrieve(identifier = nil, *parent_identifiers)
if parent_identifiers.last.is_a?(Hash)
options = {:query => parent_identifiers.pop }
end
response = get(resource_url(identifier, *parent_identifiers), options_with_token(options || {}))
handle_response(self.new, response)
end
|
.update(resource) ⇒ Object
60
61
62
63
64
|
# File 'lib/jirafe/resource/jirafe_resource.rb', line 60
def update(resource)
resource_id, parent_identifiers = identifiers_from_resource(resource)
response = put(resource_url(resource_id, parent_identifiers), options_with_token({:body => resource.attributes_for_change(:update)}))
handle_response(resource, response)
end
|
Instance Method Details
#identifier ⇒ Object
103
104
|
# File 'lib/jirafe/resource/jirafe_resource.rb', line 103
def identifier
end
|
#parent ⇒ Object
87
88
89
90
91
92
93
|
# File 'lib/jirafe/resource/jirafe_resource.rb', line 87
def parent
if self.class.parent == Jirafe::Resource::JirafeResource
self.class.parent
else
@parent
end
end
|
#parent=(parent_instance) ⇒ Object
95
96
97
|
# File 'lib/jirafe/resource/jirafe_resource.rb', line 95
def parent=(parent_instance)
@parent = parent_instance
end
|
#parent_resource_url ⇒ Object
99
100
101
|
# File 'lib/jirafe/resource/jirafe_resource.rb', line 99
def parent_resource_url
parent.nil? ? nil : parent.resource_url
end
|
#resource_url ⇒ Object
106
107
108
|
# File 'lib/jirafe/resource/jirafe_resource.rb', line 106
def resource_url
[parent_resource_url, self.class.path, self.identifier].compact.join("/")
end
|