search_console_api 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5cd291d9d52be7af01d919c485db008c77e102cc7a11b91cb47bed9da882b1e5
4
- data.tar.gz: '09f0b97510c12afb3adf85b3969a8526b5b3e15a7ffa4209cc4dc62800617313'
3
+ metadata.gz: 3968aa346b7e66d1096c29eef5dbcfab5814196b722fe2890dfcc2f671d70d63
4
+ data.tar.gz: 9267710cb171c3974dc6d136ea3d2dc1429ae61e2606f0df0d167590338b0883
5
5
  SHA512:
6
- metadata.gz: f2c2ae2790058ea42f01533493ab8f6e11c4a9e6f1ac6a1917cb4189317cbe8385e2c07c465303fef3c03f325711ecd1724f5ed07d6c73f8645760c178a01726
7
- data.tar.gz: 77fc275c283e23aa72a9611d2a82963436dc9e4900bdbd600b32e8f56f714f872f218ef728e36c3eec6913c763e736e80c4540ad1ebb7f904784ecce6677bdb0
6
+ metadata.gz: 0c9905e38e8a5a0d891b52cd692e99fdd395380962d4b65adfb6d790fa944b01e761876b4c78c0c7834f432f2f0f2ecb394042bd3e41d085a974f0b111db1e23
7
+ data.tar.gz: bef1b28a7ee2fcf906ae732152762b300e37f67beb387b56c7eca6eabb7d8ce7235839436e9d7d2e5cd4195e93b55961f2ababeeb651dbea1f182ffaf62fe812
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- search_console_api (0.0.1)
4
+ search_console_api (0.0.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -45,7 +45,7 @@ You will probably want to add the `dimensions` parameters (like in the second ex
45
45
  response = client.query(site: my_site, start_date: "2024/03/01", end_date: "2024/04/01")
46
46
  => [#<SearchConsoleApi::Objects::QueryResponseRow:0x000000010929d510 @clicks=69, @ctr=0.04542462146148782, @impressions=1519, @keys=nil, @position=15.596445029624753>]
47
47
 
48
- # a more compled query:
48
+ # a more complex query:
49
49
  response = client.query(site: my_site, start_date: "2024/03/01", end_date: "2024/04/01", dimensions: ["query"], row_limit: 3)
50
50
  =>
51
51
  [#<SearchConsoleApi::Objects::QueryResponseRow:0x0000000109324c18
@@ -69,6 +69,9 @@ response = client.query(site: my_site, start_date: "2024/03/01", end_date: "2024
69
69
  @keys=["location agreement template"],
70
70
  @position=5.392857142857143,
71
71
  @query="location agreement template">]
72
+
73
+ # You can also use a simple url instead of a Site object in the parameters:
74
+ response = client.query(site: "https://example.com", start_date: "2024/03/01", end_date: "2024/04/01", dimensions: ["query"], row_limit: 3)
72
75
  ```
73
76
 
74
77
  The response will be an array of `SearchConsoleApi::Objects::QueryResponseRow` objects, representing each row of the original response.
@@ -21,7 +21,7 @@ module SearchConsoleApi
21
21
 
22
22
  http.request request
23
23
  end
24
- raise SearchConsoleApi::Error.new(response) unless response.is_a?(Net::HTTPSuccess)
24
+ raise SearchConsoleApi::Error.new(response.body) unless response.is_a?(Net::HTTPSuccess)
25
25
 
26
26
  JSON.parse response.body
27
27
  end
@@ -38,7 +38,7 @@ module SearchConsoleApi
38
38
  request.body = payload
39
39
 
40
40
  response = https.request(request)
41
- raise SearchConsoleApi::Error.new(response) unless response.is_a?(Net::HTTPSuccess)
41
+ raise SearchConsoleApi::Error.new(response.body) unless response.is_a?(Net::HTTPSuccess)
42
42
 
43
43
  JSON.parse response.body
44
44
  end
@@ -1,3 +1,5 @@
1
+ require "date"
2
+
1
3
  module SearchConsoleApi
2
4
  module Resources
3
5
  module SearchAnalytics
@@ -5,8 +7,8 @@ module SearchConsoleApi
5
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)
6
8
  @access_token = access_token
7
9
  @site = site
8
- @start_date = start_date
9
- @end_date = end_date
10
+ @start_date = DateTime.parse(start_date).strftime("%Y-%m-%d")
11
+ @end_date = DateTime.parse(end_date).strftime("%Y-%m-%d")
10
12
  @dimensions = dimensions
11
13
  @type = type
12
14
  @dimension_filter_groups = dimension_filter_groups
@@ -14,6 +16,10 @@ module SearchConsoleApi
14
16
  @row_limit = row_limit
15
17
  @start_row = start_row
16
18
  @data_state = data_state
19
+
20
+ unless @site.is_a?(SearchConsoleApi::Objects::Site)
21
+ @site = SearchConsoleApi::Objects::Site.new({"siteUrl" => @site})
22
+ end
17
23
  end
18
24
 
19
25
  def call
@@ -22,12 +28,16 @@ module SearchConsoleApi
22
28
  end
23
29
  end
24
30
 
31
+ def request_path
32
+ "/sites/#{@site.encoded_site_url}/searchAnalytics/query"
33
+ end
34
+
25
35
  private
26
36
 
27
37
  def response
28
38
  Request.post(
29
39
  access_token: @access_token,
30
- path: "/sites/#{@site.encoded_site_url}/searchAnalytics/query",
40
+ path: request_path,
31
41
  payload: payload
32
42
  )
33
43
  end
@@ -49,4 +59,4 @@ module SearchConsoleApi
49
59
  end
50
60
  end
51
61
  end
52
- end
62
+ end
@@ -1,3 +1,3 @@
1
1
  module SearchConsoleApi
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: search_console_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gustavo Garcia
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-10 00:00:00.000000000 Z
11
+ date: 2024-03-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A very humble wrapper for the Google Search Console API to be used in
14
14
  conjuntion with OAuth2