semrush 3.0.6 → 3.0.7
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.
- data/README.rdoc +7 -0
- data/lib/semrush/report.rb +6 -1
- data/lib/semrush/version.rb +1 -1
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -51,6 +51,8 @@ You may use the following parameters:
|
|
51
51
|
:limit # (Integer) select only the first 'limit' entries (This parameter is required in order to avoid uncontrolled heavy usage)
|
52
52
|
:offset # (Integer) skip the first 'offset' entries
|
53
53
|
:export_columns # (String) select the columns you want to fetch, for instance: :export_columns => "Dn,Rk"
|
54
|
+
:before # (Proc or lambda) will be called before the call to SemRush (even if this return false it still runs the request)
|
55
|
+
:after # (Proc or lambda) will be called after the call to SemRush (if the call returns an exception, this will not be executed)
|
54
56
|
|
55
57
|
Some examples:
|
56
58
|
|
@@ -62,6 +64,11 @@ or
|
|
62
64
|
report = Semrush::Report.domain("seobook.com")
|
63
65
|
data = report.basics(:db => 'us', :limit => 100)
|
64
66
|
|
67
|
+
or
|
68
|
+
|
69
|
+
data = Semrush::Report.domain("seobook.com").basics(:db => 'us', :limit => 100, :before => lambda{|params| puts params})
|
70
|
+
data = Semrush::Report.domain("seobook.com").basics(:db => 'us', :limit => 100, :after => lambda{|params, results| puts results})
|
71
|
+
|
65
72
|
You will find more information about these parameters at http://www.semrush.com/api.html
|
66
73
|
|
67
74
|
== Reports
|
data/lib/semrush/report.rb
CHANGED
@@ -233,11 +233,14 @@ module Semrush
|
|
233
233
|
}
|
234
234
|
puts "[Semrush query] URL: #{temp_url}" if Semrush.debug
|
235
235
|
url = URI.parse(temp_url)
|
236
|
+
params[:before].call(params) if params[:before]
|
236
237
|
response = Net::HTTP.start(url.host, url.port) {|http|
|
237
238
|
http.get(url.path+"?"+url.query)
|
238
239
|
}.body rescue "ERROR :: RESPONSE ERROR (-1)" # Make this error up
|
239
240
|
response.force_encoding("utf-8")
|
240
|
-
response.starts_with?("ERROR") ? error(response) : parse(response)
|
241
|
+
output = response.starts_with?("ERROR") ? error(response) : parse(response)
|
242
|
+
params[:after].call(params, output) if params[:after]
|
243
|
+
output
|
241
244
|
end
|
242
245
|
|
243
246
|
# All parameters:
|
@@ -258,6 +261,8 @@ module Semrush
|
|
258
261
|
params.delete(:request_type) unless REQUEST_TYPES.include?(params[:request_type].try(:to_sym))
|
259
262
|
@parameters = {:db => "us", :api_key => Semrush.api_key, :limit => "", :offset => "", :export_columns => ""}.merge(@parameters).merge(params)
|
260
263
|
raise Semrush::Exception::Nolimit.new(self, "The limit parameter is missing: a limit is required.") unless @parameters[:limit].present?
|
264
|
+
raise Semrush::Exception::BadArgument.new(self, "Request parameter before is not a proc: proc type is required.") unless @parameters[:before].blank? || @parameters[:before].is_a?(Proc)
|
265
|
+
raise Semrush::Exception::BadArgument.new(self, "Request parameter after is not a proc: proc type is required.") unless @parameters[:after].blank? || @parameters[:after].is_a?(Proc)
|
261
266
|
raise Semrush::Exception::BadArgument.new(self, "Request parameter is missing: Domain name, URL, or keywords are required.") unless @parameters[:request].present?
|
262
267
|
raise Semrush::Exception::BadArgument.new(self, "Bad db: #{@parameters[:db]}") unless DBS.include?(@parameters[:db].try(:to_sym))
|
263
268
|
raise Semrush::Exception::BadArgument.new(self, "Bad report type: #{@parameters[:report_type]}") unless REPORT_TYPES.include?(@parameters[:report_type].try(:to_sym))
|
data/lib/semrush/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|