lib/garb/resource.rb in garb-0.8.0 vs lib/garb/resource.rb in garb-0.8.1
- old
+ new
@@ -42,10 +42,22 @@
def set_segment_id(id)
@segment = "gaid::#{id.to_i}"
end
+ def segment
+ @segment
+ end
+
+ def set_instance_klass(klass)
+ @instance_klass = klass
+ end
+
+ def instance_klass
+ @instance_klass || OpenStruct
+ end
+
def results(profile, opts = {}, &block)
@profile = profile.is_a?(Profile) ? profile : Profile.first(profile, opts.fetch(:session, Session))
if @profile
@start_date = opts.fetch(:start_date, Time.now - MONTH)
@@ -53,11 +65,11 @@
@limit = opts.fetch(:limit, nil)
@offset = opts.fetch(:offset, nil)
instance_eval(&block) if block_given?
- ReportResponse.new(send_request_for_body).results
+ ReportResponse.new(send_request_for_body, instance_klass).results
else
[]
end
end
@@ -70,10 +82,10 @@
'start-date' => format_time(@start_date),
'end-date' => format_time(@end_date)}
end
def segment_params
- @segment ? {'segment' => @segment} : {}
+ segment.nil? ? {} : {'segment' => segment}
end
def params
[
metrics.to_params,