semrush 3.0.7 → 3.0.8

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 CHANGED
@@ -21,6 +21,11 @@ Create an initializer, for instance semrush.rb with the following:
21
21
 
22
22
  Replace '7899esf6874' with your SEMRush api key.
23
23
 
24
+ You may also use the following parameters in config:
25
+
26
+ config.before = lambda{|params| puts params} # (Proc or lambda) will be called before the call to SemRush (even if this return false it still runs the request)
27
+ config.after = lambda{|params, results| puts results} # (Proc or lambda) will be called after the call to SemRush (if the call returns an exception, this will not be executed)
28
+
24
29
  == Getting started
25
30
 
26
31
  First, create a report for a domain, a URL or a phrase with:
@@ -51,8 +56,6 @@ You may use the following parameters:
51
56
  :limit # (Integer) select only the first 'limit' entries (This parameter is required in order to avoid uncontrolled heavy usage)
52
57
  :offset # (Integer) skip the first 'offset' entries
53
58
  :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)
56
59
 
57
60
  Some examples:
58
61
 
@@ -64,11 +67,6 @@ or
64
67
  report = Semrush::Report.domain("seobook.com")
65
68
  data = report.basics(:db => 'us', :limit => 100)
66
69
 
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
-
72
70
  You will find more information about these parameters at http://www.semrush.com/api.html
73
71
 
74
72
  == Reports
data/lib/semrush.rb CHANGED
@@ -14,6 +14,10 @@ module Semrush
14
14
  @@api_key = ""
15
15
  mattr_accessor :debug
16
16
  @@debug = false
17
+ mattr_accessor :before
18
+ @@before = Proc.new{}
19
+ mattr_accessor :after
20
+ @@after = Proc.new{}
17
21
 
18
22
 
19
23
  # Email Options (TODO: remove if unnecessary)
@@ -33,6 +37,8 @@ module Semrush
33
37
  yield self
34
38
  Pony.options = @@email_options
35
39
  raise Exception::BadApiKey.new if @@api_key.nil? || @@api_key.empty?
40
+ raise Exception::BadArgument.new(self, "before is not a proc: proc type is required.") unless @@before.is_a?(Proc)
41
+ raise Exception::BadArgument.new(self, "after is not a proc: proc type is required.") unless @@after.is_a?(Proc)
36
42
  end
37
43
 
38
44
  end
@@ -233,13 +233,13 @@ 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
+ Semrush.before.call(params)
237
237
  response = Net::HTTP.start(url.host, url.port) {|http|
238
238
  http.get(url.path+"?"+url.query)
239
239
  }.body rescue "ERROR :: RESPONSE ERROR (-1)" # Make this error up
240
240
  response.force_encoding("utf-8")
241
241
  output = response.starts_with?("ERROR") ? error(response) : parse(response)
242
- params[:after].call(params, output) if params[:after]
242
+ Semrush.after.call(params, output)
243
243
  output
244
244
  end
245
245
 
@@ -261,8 +261,6 @@ module Semrush
261
261
  params.delete(:request_type) unless REQUEST_TYPES.include?(params[:request_type].try(:to_sym))
262
262
  @parameters = {:db => "us", :api_key => Semrush.api_key, :limit => "", :offset => "", :export_columns => ""}.merge(@parameters).merge(params)
263
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)
266
264
  raise Semrush::Exception::BadArgument.new(self, "Request parameter is missing: Domain name, URL, or keywords are required.") unless @parameters[:request].present?
267
265
  raise Semrush::Exception::BadArgument.new(self, "Bad db: #{@parameters[:db]}") unless DBS.include?(@parameters[:db].try(:to_sym))
268
266
  raise Semrush::Exception::BadArgument.new(self, "Bad report type: #{@parameters[:report_type]}") unless REPORT_TYPES.include?(@parameters[:report_type].try(:to_sym))
@@ -1,3 +1,3 @@
1
1
  module Semrush
2
- VERSION = "3.0.7" # we want to follow the API version: for API 3.0, the gem will be version 3.0.x
2
+ VERSION = "3.0.8" # we want to follow the API version: for API 3.0, the gem will be version 3.0.x
3
3
  end
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.7
4
+ version: 3.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: