Class: SearchConsoleApi::Resources::SearchAnalytics::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/search_console_api/resources/search_analytics/query.rb

Instance Method Summary collapse

Constructor Details

#initialize(access_token:, site: nil, start_date: nil, end_date: nil, dimensions: [], type: nil, dimension_filter_groups: [], aggregation_type: nil, row_limit: nil, start_row: nil, data_state: nil) ⇒ Query

Returns a new instance of Query.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/search_console_api/resources/search_analytics/query.rb', line 7

def initialize(access_token:, site: nil, start_date: nil, end_date: nil, dimensions: [], type: nil, dimension_filter_groups: [], aggregation_type: nil, row_limit: nil, start_row: nil, data_state: nil)
  @access_token = access_token
  @site = site
  @start_date = DateTime.parse(start_date.to_s).strftime("%Y-%m-%d")
  @end_date = DateTime.parse(end_date.to_s).strftime("%Y-%m-%d")
  @dimensions = dimensions
  @type = type
  @dimension_filter_groups = dimension_filter_groups
  @aggregation_type = aggregation_type
  @row_limit = row_limit
  @start_row = start_row
  @data_state = data_state

  unless @site.is_a?(SearchConsoleApi::Objects::Site)
    @site = SearchConsoleApi::Objects::Site.new({"siteUrl" => @site})
  end
end

Instance Method Details

#callObject



25
26
27
28
29
30
31
# File 'lib/search_console_api/resources/search_analytics/query.rb', line 25

def call
  return [] unless response["rows"].is_a?(Array)

  response["rows"].each_with_object([]) do |attrs, rows|
    rows << Objects::QueryResponseRow.new(attrs, @dimensions)
  end
end

#request_pathObject



33
34
35
# File 'lib/search_console_api/resources/search_analytics/query.rb', line 33

def request_path
  "/sites/#{@site.encoded_site_url}/searchAnalytics/query"
end