Module: Garb::Model
- Defined in:
- lib/garb/model.rb
Constant Summary collapse
- MONTH =
2592000
- URL =
"https://www.googleapis.com/analytics/v2.4/data"
Class Method Summary collapse
Instance Method Summary collapse
- #dimensions(*fields) ⇒ Object
- #instance_klass ⇒ Object
- #metrics(*fields) ⇒ Object
- #results(profile, options = {}) ⇒ Object
- #set_instance_klass(klass) ⇒ Object
Class Method Details
.extended(base) ⇒ Object
6 7 8 |
# File 'lib/garb/model.rb', line 6 def self.extended(base) ProfileReports.add_report_method(base) end |
Instance Method Details
#dimensions(*fields) ⇒ Object
15 16 17 18 |
# File 'lib/garb/model.rb', line 15 def dimensions(*fields) @dimensions ||= ReportParameter.new(:dimensions) @dimensions << fields end |
#instance_klass ⇒ Object
24 25 26 |
# File 'lib/garb/model.rb', line 24 def instance_klass @instance_klass || OpenStruct end |
#metrics(*fields) ⇒ Object
10 11 12 13 |
# File 'lib/garb/model.rb', line 10 def metrics(*fields) @metrics ||= ReportParameter.new(:metrics) @metrics << fields end |
#results(profile, options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/garb/model.rb', line 28 def results(profile, = {}) start_date = .fetch(:start_date, Time.now - MONTH) end_date = .fetch(:end_date, Time.now) default_params = build_default_params(profile, start_date, end_date) param_set = [ default_params, metrics.to_params, dimensions.to_params, parse_filters().to_params, parse_segment(), parse_sort().to_params, build_page_params() ] data = send_request_for_data(profile, build_params(param_set)) ReportResponse.new(data, instance_klass).results end |
#set_instance_klass(klass) ⇒ Object
20 21 22 |
# File 'lib/garb/model.rb', line 20 def set_instance_klass(klass) @instance_klass = klass end |