semrush 3.0.22 → 3.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.rdoc +13 -2
- data/lib/semrush/analytics.rb +94 -0
- data/lib/semrush/base.rb +78 -0
- data/lib/semrush/report.rb +14 -82
- data/lib/semrush/version.rb +1 -1
- data/lib/semrush.rb +4 -0
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10cb05ec42e77de2e49cc3c374e330478cf5f09666f62519c2ce8cb3045cfbf3
|
4
|
+
data.tar.gz: ffb593df0c6ff6c41a28958d1912ce0ffb4d90243c5cac50f54a5f0ba683c505
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd0ea77440b7c8fac7eb81406847a1e09277f13e144527d56c79d9f4b3372f4cef504f5f6880178694e5300636467ef192bc3bfe00b088997f0023f8c46bccd3
|
7
|
+
data.tar.gz: af1fdf963f5ec2244462b9c5e12f0382adb275356604d87eec894c057fa7cea052c371b9d2f6a85faa799c0aaebd3beade463c27677675d554bb8c9ae6744533
|
data/README.rdoc
CHANGED
@@ -4,8 +4,8 @@ Semrush is a ruby wrapper for the SEMRush API.
|
|
4
4
|
|
5
5
|
== Requirements
|
6
6
|
|
7
|
-
- Ruby 1.9
|
8
|
-
- ActiveSupport
|
7
|
+
- Ruby 1.9, 2.x, 3.1<
|
8
|
+
- ActiveSupport
|
9
9
|
|
10
10
|
== Installation
|
11
11
|
|
@@ -70,6 +70,9 @@ or
|
|
70
70
|
report = Semrush::Report.domain("seobook.com")
|
71
71
|
data = report.basics(:db => 'us', :limit => 100)
|
72
72
|
|
73
|
+
or
|
74
|
+
analytics = Semrush::Analytics.backlinks_refdomains("seobook.com")
|
75
|
+
|
73
76
|
You will find more information about these parameters at http://www.semrush.com/api.html
|
74
77
|
|
75
78
|
== Reports
|
@@ -101,6 +104,14 @@ For more information about the report types, please read http://www.semrush.com/
|
|
101
104
|
|
102
105
|
== ChangeLog
|
103
106
|
|
107
|
+
=== 3.0.24, 2023-05-15
|
108
|
+
|
109
|
+
* Added Analytics class for the new Analytics API, not covered all the reports yet
|
110
|
+
|
111
|
+
=== 3.0.23, 2020-03-19
|
112
|
+
|
113
|
+
* Add New Zealand 'nz' to allowed databases (countries)
|
114
|
+
|
104
115
|
=== 3.0.22, 2019-06-14
|
105
116
|
|
106
117
|
* Add India to the list of allowed countries
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module Semrush
|
2
|
+
# = Analytics Class
|
3
|
+
# Most of these methods take a hash parameter that may contain the following keys :
|
4
|
+
# There is no db filter for analytics api but you can use :display_filter to filter the results,
|
5
|
+
# example: :display_filter => "+|country||us" will only return results from the US.
|
6
|
+
# See https://developer.semrush.com/api/v3/analytics/basic-docs/
|
7
|
+
# * :api_key (ex: :api_key => 'gt97s6d4a6w')
|
8
|
+
# * :limit (ex: :limit => 2000)
|
9
|
+
# * :offset (ex: :offset => 5)
|
10
|
+
# * :export_columns (ex: :export_columns => "Dn,Rk")
|
11
|
+
class Analytics < Base
|
12
|
+
ANALYTIC_TYPES = [:backlinks_refdomains]
|
13
|
+
REQUEST_TYPES = [:root_domain, :domain, :url]
|
14
|
+
|
15
|
+
def initialize params = {}
|
16
|
+
@parameters = params
|
17
|
+
@target_types = REQUEST_TYPES
|
18
|
+
@api_report_url = API_ANALYTICS_URL
|
19
|
+
end
|
20
|
+
|
21
|
+
# Get lists domains pointing to the queried domain, root domain, or URL.
|
22
|
+
# * :api_key (ex: :api_key => 'gt97s6d4a6w')
|
23
|
+
# * :limit (ex: :limit => "")
|
24
|
+
# * :offset (ex: :offset => "")
|
25
|
+
# * :target_type (ex: :target_type => "") One of `REQUEST_TYPES`
|
26
|
+
# * :export_columns (ex: :export_columns => "")
|
27
|
+
# * :display_filter one or many of "zone, country, ip, newdomain, lostdomain, category"
|
28
|
+
# See: https://developer.semrush.com/api/v3/analytics/backlinks/#reffering_domains
|
29
|
+
def self.backlinks_refdomains(domain, params = {})
|
30
|
+
export_columns = params.delete(:export_columns).presence ||
|
31
|
+
"domain_ascore,domain,backlinks_num,ip,country,first_seen,last_seen"
|
32
|
+
|
33
|
+
self.new(params.merge(:report_type => :backlinks_refdomains, :target => domain,
|
34
|
+
:export_columns => export_columns))
|
35
|
+
.request
|
36
|
+
end
|
37
|
+
|
38
|
+
# Compare your and your competitors' backlink profiles and link-building progress.
|
39
|
+
# * :api_key (ex: :api_key => 'gt97s6d4a6w')
|
40
|
+
# * :targets (ex: :targets => ["domain1.com", "domain2.com"]) Array of domains to compare
|
41
|
+
# * :target_types (ex: :target_type => ["root_domain", "root_domain"]) Array to match with corresponding targets index
|
42
|
+
# * :export_columns (ex: :export_columns => ""), available columns: "target,target_type,ascore,backlinks_num,domains_num,ips_num,follows_num,nofollows_num,texts_num,images_num,forms_num,frames_num"
|
43
|
+
#
|
44
|
+
# * Return array of data
|
45
|
+
# @see https://developer.semrush.com/api/v3/analytics/backlinks/#batch_comparason
|
46
|
+
# @see https://www.semrush.com/batch/report/ for UI demo
|
47
|
+
def self.backlinks_comparison(targets, target_types, params = {})
|
48
|
+
target_types.each do |target_type|
|
49
|
+
raise Exception::BadArgument.new(self, "One of `target_types` is not valid: #{target_type}") unless REQUEST_TYPES.include?(target_type.to_sym)
|
50
|
+
end
|
51
|
+
|
52
|
+
raise Exception::BadArgument.new(self, "`targets` and `target_types` must be the same size") unless targets.size == target_types.size
|
53
|
+
|
54
|
+
export_columns = params.delete(:export_columns).presence ||
|
55
|
+
"target,target_type,ascore,backlinks_num,domains_num,ips_num,follows_num,nofollows_num,texts_num,images_num,forms_num,frames_num"
|
56
|
+
# Have to add target and target_type to params to cleaup API_ANALYTICS_URL (in #request v.blank? check)
|
57
|
+
self.new(params.merge(:report_type => :backlinks_comparison, :targets => targets, :target_types => target_types,
|
58
|
+
:export_columns => export_columns,
|
59
|
+
))
|
60
|
+
.request
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
# All parameters:
|
66
|
+
# * report_type - type of the report
|
67
|
+
# * api_key - user identification key, you can find it in your profile on the Semrush site
|
68
|
+
# * target_type - type of the request.
|
69
|
+
# * target - your domain/url
|
70
|
+
# * limit - number of results returned
|
71
|
+
# * offset - says to skip that many results before beginning to return results to you
|
72
|
+
# * export_columns - list of column names, separated by coma. You may list just the column names you need in an order you need.
|
73
|
+
# * display_sort - a sorting as a String eg: 'am_asc' or 'am_desc'(read http://www.semrush.com/api)
|
74
|
+
# * display_filter - list of filters separated by "|" (maximum number - 25). A filter consists of <sign>|<field>|<operation>|<value> (read http://www.semrush.com/api)
|
75
|
+
#
|
76
|
+
# more details in http://www.semrush.com/api.html
|
77
|
+
def validate_parameters params = {}
|
78
|
+
params.symbolize_keys!
|
79
|
+
params.delete(:report_type) unless ANALYTIC_TYPES.include?(params[:report_type].try(:to_sym))
|
80
|
+
params.delete(:target_type) unless @target_types.include?(params[:target_type].try(:to_sym)) unless params[:targets]
|
81
|
+
@parameters = {:api_key => Semrush.api_key, :limit => "", :offset => "", :export_columns => "",
|
82
|
+
:target => "", :target_type => "", :targets => "", :target_types => "",
|
83
|
+
:display_sort => "", :display_filter => "", :display_date => ""}.merge(@parameters).merge(params)
|
84
|
+
# When(if) we will have another method that use `targets` as an Array(like backlinks_comparison) improve this
|
85
|
+
# and move validations from backlinks_comparison to here
|
86
|
+
unless @parameters[:targets]
|
87
|
+
raise Semrush::Exception::Nolimit.new(self, "The limit parameter is missing: a limit is required.") unless @parameters[:limit].present? && @parameters[:limit].to_i>0
|
88
|
+
raise Semrush::Exception::BadArgument.new(self, "Target parameter is missing: Domain name, URL.") unless @parameters[:target].present?
|
89
|
+
raise Semrush::Exception::BadArgument.new(self, "Bad report_type: #{@parameters[:report_type]}") unless ANALYTIC_TYPES.include?(@parameters[:report_type].try(:to_sym))
|
90
|
+
raise Semrush::Exception::BadArgument.new(self, "Bad target_type: #{@parameters[:target_type]}") unless @target_types.include?(@parameters[:target_type].try(:to_sym))
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/lib/semrush/base.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
module Semrush
|
2
|
+
# = Base Class for all Semrush API classes
|
3
|
+
class Base
|
4
|
+
def request params = {}
|
5
|
+
validate_parameters params
|
6
|
+
temp_url = "#{@api_report_url}" #do not copy the constant as is or else the constant would be modified !!
|
7
|
+
@parameters.each {|k, v|
|
8
|
+
if v.blank?
|
9
|
+
temp_url.gsub!(/&[^&=]+=%#{k.to_s}%/i, '')
|
10
|
+
elsif k.to_sym==:display_filter
|
11
|
+
temp_url.gsub!("%#{k.to_s.upcase}%", CGI.escape(v.to_s).gsub('&', '%26').gsub('+', '%2B'))
|
12
|
+
elsif v.is_a?(Array)
|
13
|
+
# remove placeholder with value into query string of array of values
|
14
|
+
temp_url.gsub!("#{k}=%#{k.to_s.upcase}%", v.to_query(k.to_s))
|
15
|
+
else
|
16
|
+
temp_url.gsub!("%#{k.to_s.upcase}%", CGI.escape(v.to_s).gsub('&', '%26'))
|
17
|
+
end
|
18
|
+
}
|
19
|
+
puts "[Semrush query] URL: #{temp_url}" if Semrush.debug
|
20
|
+
url = URI.parse(temp_url)
|
21
|
+
Semrush.before.call(@parameters.merge(:url => url))
|
22
|
+
response = Net::HTTP.start(url.host, url.port, :use_ssl => true) {|http|
|
23
|
+
http.get(url.path+"?"+url.query)
|
24
|
+
}.body rescue "ERROR :: RESPONSE ERROR (-1)" # Make this error up
|
25
|
+
response.force_encoding("utf-8")
|
26
|
+
output = response.starts_with?("ERROR") ? error(response) : parse(response)
|
27
|
+
Semrush.after.call(@parameters.merge(:url => url), output)
|
28
|
+
output
|
29
|
+
end
|
30
|
+
|
31
|
+
# Format and raise an error
|
32
|
+
def error(text = "")
|
33
|
+
e = /ERROR\s(\d+)\s::\s(.*)/.match(text) || {}
|
34
|
+
name = (e[2] || "UnknownError").titleize
|
35
|
+
code = e[1] || -1
|
36
|
+
error_class = name.gsub(/\s/, "")
|
37
|
+
|
38
|
+
if error_class == "NothingFound"
|
39
|
+
[]
|
40
|
+
else
|
41
|
+
begin
|
42
|
+
raise Semrush::Exception.const_get(error_class).new(self, "#{name} (#{code})")
|
43
|
+
rescue
|
44
|
+
raise Semrush::Exception::Base.new(self, "#{name} (#{code}) *** error_class=#{error_class} not implemented ***")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def parse(text = "")
|
50
|
+
return [] if text.empty?
|
51
|
+
csv = CSV.parse(text.to_s, :col_sep => ";")
|
52
|
+
format_key = lambda do |k|
|
53
|
+
r = {
|
54
|
+
/\s/ => "_",
|
55
|
+
/[|\.|\)|\(]/ => "",
|
56
|
+
/%/ => "percent",
|
57
|
+
/\*/ => "times"
|
58
|
+
}
|
59
|
+
k = k.to_s.downcase
|
60
|
+
r.each_pair {|pattern, replace| k.gsub!(pattern, replace) }
|
61
|
+
k.to_sym
|
62
|
+
end
|
63
|
+
|
64
|
+
# (thanks http://snippets.dzone.com/posts/show/3899)
|
65
|
+
keys = csv.shift.map(&format_key)
|
66
|
+
string_data = csv.map {|row| row.map {|cell| cell.to_s } }
|
67
|
+
string_data.map {|row| Hash[*keys.zip(row).flatten] }
|
68
|
+
rescue CSV::MalformedCSVError => csvife
|
69
|
+
tries ||= 0
|
70
|
+
if (tries += 1) < 3
|
71
|
+
retry
|
72
|
+
else
|
73
|
+
raise CSV::MalformedCSVError.new("Bad format for CSV: #{text.inspect}").tap{|e|
|
74
|
+
e.set_backtrace(csvife.backtrace)}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/semrush/report.rb
CHANGED
@@ -6,14 +6,13 @@ module Semrush
|
|
6
6
|
# * :limit (ex: :limit => 2000)
|
7
7
|
# * :offset (ex: :offset => 5)
|
8
8
|
# * :export_columns (ex: :export_columns => "Dn,Rk")
|
9
|
-
class Report
|
10
|
-
DBS = [:us, :uk, :ca, :ru, :de, :fr, :es, :it, :br, :au, :ar, :be, :ch, :dk, :fi, :hk, :ie, :il, :mx, :nl, :no, :pl, :se, :sg, :tr, :in] #"us" - for Google.com, "uk" - for Google.co.uk, "ru" - for Google.ru, "de" for Google.de, "fr" for Google.fr, "es" for Google.es, "it" for Google.it Beta, "br" for Google.com.br Beta, "au" for Google.com.au Beta, etc
|
9
|
+
class Report < Base
|
10
|
+
DBS = [:us, :uk, :ca, :ru, :de, :fr, :es, :it, :br, :au, :ar, :be, :ch, :dk, :fi, :hk, :ie, :il, :mx, :nl, :no, :pl, :se, :sg, :tr, :in, :nz] #"us" - for Google.com, "uk" - for Google.co.uk, "ru" - for Google.ru, "de" for Google.de, "fr" for Google.fr, "es" for Google.es, "it" for Google.it Beta, "br" for Google.com.br Beta, "au" for Google.com.au Beta, etc
|
11
11
|
REPORT_TYPES = [:domain_rank, :domain_organic, :domain_adwords, :domain_organic_organic, :domain_adwords_adwords, :domain_organic_adwords, :domain_adwords_organic, :domain_adwords_historical,
|
12
12
|
:phrase_this, :phrase_organic, :phrase_related, :phrase_adwords_historical, :phrase_fullsearch, :phrase_kdi,
|
13
13
|
:url_organic, :url_adwords]
|
14
14
|
REQUEST_TYPES = [:domain, :phrase, :url]
|
15
15
|
|
16
|
-
|
17
16
|
# Tries to make the api call for the report called as method (see samples on http://www.semrush.com/api.html).
|
18
17
|
# Allows calls like:
|
19
18
|
# * Semrush::Report.new.domain_rank(:request_type => :domain, :request => 'thedomain.com')
|
@@ -22,11 +21,14 @@ module Semrush
|
|
22
21
|
# * Semrush::Report.new.phrase_fullsearch(:request_type => :phrase, :request => 'the+phrase')
|
23
22
|
def method_missing(method, *args)
|
24
23
|
return super unless REPORT_TYPES.include?(method) && args.first.is_a?(Hash)
|
24
|
+
|
25
25
|
request args.first.merge(:report_type => method)
|
26
26
|
end
|
27
27
|
|
28
28
|
def initialize params = {}
|
29
29
|
@parameters = params
|
30
|
+
@request_types = REQUEST_TYPES
|
31
|
+
@api_report_url = API_REPORT_URL
|
30
32
|
end
|
31
33
|
|
32
34
|
# Initializes a report for a specific domain.
|
@@ -39,6 +41,7 @@ module Semrush
|
|
39
41
|
def self.domain domain, params = {}
|
40
42
|
self.new(params.merge(:request_type => :domain, :request => domain))
|
41
43
|
end
|
44
|
+
|
42
45
|
# Initializes a report for a specific phrase (or keyword).
|
43
46
|
# Takes a hash parameter that may contain the following keys :
|
44
47
|
# * :db (ex: :db => "us")
|
@@ -49,6 +52,7 @@ module Semrush
|
|
49
52
|
def self.phrase phrase, params = {}
|
50
53
|
self.new(params.merge(:request_type => :phrase, :request => phrase))
|
51
54
|
end
|
55
|
+
|
52
56
|
# Initializes a report for a specific domain.
|
53
57
|
# Takes a hash parameter that may contain the following keys :
|
54
58
|
# * :db (ex: :db => "us")
|
@@ -71,7 +75,7 @@ module Semrush
|
|
71
75
|
if v.blank?
|
72
76
|
temp_url.gsub!(/&[^&=]+=%#{k.to_s}%/i, '')
|
73
77
|
else
|
74
|
-
temp_url.gsub!("%#{k.to_s.upcase}%",
|
78
|
+
temp_url.gsub!("%#{k.to_s.upcase}%", CGI.escape(v.to_s).gsub('&', '%26'))
|
75
79
|
end
|
76
80
|
}
|
77
81
|
temp_url
|
@@ -261,7 +265,7 @@ module Semrush
|
|
261
265
|
def fullsearch params = {}
|
262
266
|
request(params.merge(:report_type => :phrase_fullsearch))
|
263
267
|
end
|
264
|
-
|
268
|
+
|
265
269
|
# Keyword Difficulty report
|
266
270
|
# Usage:
|
267
271
|
# > report = Semrush::Report.phrase(phrases.join(';'), database: 'us', limit: 100).kdi
|
@@ -274,30 +278,6 @@ module Semrush
|
|
274
278
|
|
275
279
|
private
|
276
280
|
|
277
|
-
def request params = {}
|
278
|
-
validate_parameters params
|
279
|
-
temp_url = "#{API_REPORT_URL}" #do not copy the constant as is or else the constant would be modified !!
|
280
|
-
@parameters.each {|k, v|
|
281
|
-
if v.blank?
|
282
|
-
temp_url.gsub!(/&[^&=]+=%#{k.to_s}%/i, '')
|
283
|
-
elsif k.to_sym==:display_filter
|
284
|
-
temp_url.gsub!("%#{k.to_s.upcase}%", URI.escape(v.to_s).gsub('&', '%26').gsub('+', '%2B'))
|
285
|
-
else
|
286
|
-
temp_url.gsub!("%#{k.to_s.upcase}%", URI.escape(v.to_s).gsub('&', '%26'))
|
287
|
-
end
|
288
|
-
}
|
289
|
-
puts "[Semrush query] URL: #{temp_url}" if Semrush.debug
|
290
|
-
url = URI.parse(temp_url)
|
291
|
-
Semrush.before.call(@parameters.merge(:url => url))
|
292
|
-
response = Net::HTTP.start(url.host, url.port, :use_ssl => true) {|http|
|
293
|
-
http.get(url.path+"?"+url.query)
|
294
|
-
}.body rescue "ERROR :: RESPONSE ERROR (-1)" # Make this error up
|
295
|
-
response.force_encoding("utf-8")
|
296
|
-
output = response.starts_with?("ERROR") ? error(response) : parse(response)
|
297
|
-
Semrush.after.call(@parameters.merge(:url => url), output)
|
298
|
-
output
|
299
|
-
end
|
300
|
-
|
301
281
|
# All parameters:
|
302
282
|
# * db - requested database
|
303
283
|
# * report_type - type of the report
|
@@ -324,64 +304,16 @@ module Semrush
|
|
324
304
|
raise Semrush::Exception::BadArgument.new(self, "Bad request type: #{@parameters[:request_type]}") unless REQUEST_TYPES.include?(@parameters[:request_type].try(:to_sym))
|
325
305
|
end
|
326
306
|
|
327
|
-
# Format and raise an error
|
328
|
-
def error(text = "")
|
329
|
-
e = /ERROR\s(\d+)\s::\s(.*)/.match(text) || {}
|
330
|
-
name = (e[2] || "UnknownError").titleize
|
331
|
-
code = e[1] || -1
|
332
|
-
error_class = name.gsub(/\s/, "")
|
333
|
-
|
334
|
-
if error_class == "NothingFound"
|
335
|
-
[]
|
336
|
-
else
|
337
|
-
begin
|
338
|
-
raise Semrush::Exception.const_get(error_class).new(self, "#{name} (#{code})")
|
339
|
-
rescue
|
340
|
-
raise Semrush::Exception::Base.new(self, "#{name} (#{code}) *** error_class=#{error_class} not implemented ***")
|
341
|
-
end
|
342
|
-
end
|
343
|
-
end
|
344
|
-
|
345
|
-
def parse(text = "")
|
346
|
-
return [] if text.empty?
|
347
|
-
csv = CSV.parse(text.to_s, :col_sep => ";")
|
348
|
-
data = {}
|
349
|
-
format_key = lambda do |k|
|
350
|
-
r = {
|
351
|
-
/\s/ => "_",
|
352
|
-
/[|\.|\)|\(]/ => "",
|
353
|
-
/%/ => "percent",
|
354
|
-
/\*/ => "times"
|
355
|
-
}
|
356
|
-
k = k.to_s.downcase
|
357
|
-
r.each_pair {|pattern, replace| k.gsub!(pattern, replace) }
|
358
|
-
k.to_sym
|
359
|
-
end
|
360
|
-
|
361
|
-
# (thanks http://snippets.dzone.com/posts/show/3899)
|
362
|
-
keys = csv.shift.map(&format_key)
|
363
|
-
string_data = csv.map {|row| row.map {|cell| cell.to_s } }
|
364
|
-
string_data.map {|row| Hash[*keys.zip(row).flatten] }
|
365
|
-
rescue CSV::MalformedCSVError => csvife
|
366
|
-
tries ||= 0
|
367
|
-
if (tries += 1) < 3
|
368
|
-
retry
|
369
|
-
else
|
370
|
-
raise CSV::MalformedCSVError.new("Bad format for CSV: #{text.inspect}").tap{|e|
|
371
|
-
e.set_backtrace(csvife.backtrace)}
|
372
|
-
end
|
373
|
-
end
|
374
|
-
|
375
307
|
def domain?
|
376
|
-
@parameters[:request_type].present? &&
|
308
|
+
@parameters[:request_type].present? && @request_types.include?(@parameters[:request_type].to_sym) && @parameters[:request_type].to_sym==:domain
|
377
309
|
end
|
310
|
+
|
378
311
|
def url?
|
379
|
-
@parameters[:request_type].present? &&
|
312
|
+
@parameters[:request_type].present? && @request_types.include?(@parameters[:request_type].to_sym) && @parameters[:request_type].to_sym==:url
|
380
313
|
end
|
314
|
+
|
381
315
|
def phrase?
|
382
|
-
@parameters[:request_type].present? &&
|
316
|
+
@parameters[:request_type].present? && @request_types.include?(@parameters[:request_type].to_sym) && @parameters[:request_type].to_sym==:phrase
|
383
317
|
end
|
384
|
-
|
385
|
-
|
386
318
|
end
|
387
319
|
end
|
data/lib/semrush/version.rb
CHANGED
data/lib/semrush.rb
CHANGED
@@ -5,10 +5,14 @@ require 'csv'
|
|
5
5
|
require 'rubygems'
|
6
6
|
require 'active_support/all'
|
7
7
|
require 'semrush/exception'
|
8
|
+
require 'semrush/base'
|
8
9
|
require 'semrush/report'
|
10
|
+
require 'semrush/analytics'
|
9
11
|
|
10
12
|
module Semrush
|
13
|
+
# See https://developer.semrush.com/api/v3/analytics/basic-docs/
|
11
14
|
API_REPORT_URL = "https://api.semrush.com/?type=%REPORT_TYPE%&%REQUEST_TYPE%=%REQUEST%&key=%API_KEY%&display_limit=%LIMIT%&display_offset=%OFFSET%&export=api&database=%DB%&export_columns=%EXPORT_COLUMNS%&display_sort=%DISPLAY_SORT%&display_filter=%DISPLAY_FILTER%&display_date=%DISPLAY_DATE%"
|
15
|
+
API_ANALYTICS_URL = "https://api.semrush.com/analytics/v1?type=%REPORT_TYPE%&targets=%TARGETS%&target_types=%TARGET_TYPES%&target=%TARGET%&target_type=%TARGET_TYPE%&key=%API_KEY%&display_limit=%LIMIT%&display_offset=%OFFSET%&export_columns=%EXPORT_COLUMNS%&display_sort=%DISPLAY_SORT%&display_filter=%DISPLAY_FILTER%"
|
12
16
|
API_UNITS_URL = "https://www.semrush.com/users/countapiunits.html?key=%API_KEY%"
|
13
17
|
mattr_accessor :api_key
|
14
18
|
@@api_key = ""
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: semrush
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.25
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- arambert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 6.1.5
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 6.1.5
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 3.11.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 3.11.0
|
55
55
|
description: This gem is a ruby client for the SemRush API.
|
56
56
|
email:
|
57
57
|
- adrien@rambert.me
|
@@ -63,6 +63,8 @@ files:
|
|
63
63
|
- README.rdoc
|
64
64
|
- Rakefile
|
65
65
|
- lib/semrush.rb
|
66
|
+
- lib/semrush/analytics.rb
|
67
|
+
- lib/semrush/base.rb
|
66
68
|
- lib/semrush/exception.rb
|
67
69
|
- lib/semrush/exception/api_access_disabled.rb
|
68
70
|
- lib/semrush/exception/api_report_type_disabled.rb
|
@@ -93,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
95
|
- !ruby/object:Gem::Version
|
94
96
|
version: '0'
|
95
97
|
requirements: []
|
96
|
-
rubygems_version: 3.
|
98
|
+
rubygems_version: 3.1.4
|
97
99
|
signing_key:
|
98
100
|
specification_version: 4
|
99
101
|
summary: This gem is a ruby client for the SemRush API.
|