semrush 3.0.12 → 3.0.13

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -56,6 +56,8 @@ You may use the following parameters:
56
56
  :limit # (Integer) select only the first 'limit' entries (This parameter is required in order to avoid uncontrolled heavy usage)
57
57
  :offset # (Integer) skip the first 'offset' entries
58
58
  :export_columns # (String) select the columns you want to fetch, for instance: :export_columns => "Dn,Rk"
59
+ :display_sort # (String) select the column and the order you want to sort with, for instance: :display_sort => 'tr_asc'
60
+ :display_filter # (String) list of filters for the report, separated by '|' (maximum number - 25). A filter consists of <sign>|<field>|<operation>|<value> (read http://www.semrush.com/api), for instance: :display_filter => '+|Po|Lt|5'
59
61
 
60
62
  Some examples:
61
63
 
@@ -84,8 +86,8 @@ They are 3 sources for the reports: domain, url and phrase.
84
86
  You may call for one of the following report types:
85
87
 
86
88
  data = report.basics # main report for either a domain or a phrase
87
- data = report.keywords_organic # keywords organic report for either a domain or a URL
88
- data = report.keywords_adwords # keywords adwords report for either a domain or a URL
89
+ data = report.organic # organic report for either a domain, a URL or a phrase
90
+ data = report.adwords # adwords report for either a domain or a URL
89
91
  data = report.competitors_organic # for a domain
90
92
  data = report.competitors_adwords # for a domain
91
93
  data = report.competitors_organic_by_adwords # for a domain
@@ -94,6 +96,42 @@ You may call for one of the following report types:
94
96
 
95
97
  For more information about the report types, please read http://www.semrush.com/api.html
96
98
 
99
+ == ChangeLog
100
+
101
+ === 3.0.13, 2013-06-10
102
+
103
+ * Add report type 'phrase_oganic'
104
+ * Add parameter 'display_sort'
105
+ * Add parameter 'display_filter'
106
+
107
+ === 3.0.12, 2013-05-31
108
+
109
+ * Force parameter 'limit' > 0 to prevent limit=0
110
+
111
+ === 3.0.11, 2013-05-22
112
+
113
+ * Fix parameters accessible through Semrush.before & Semrush.after
114
+
115
+ === 3.0.10, 2013-05-21
116
+
117
+ * Fix remaining_quota (problem with redirections)
118
+
119
+ === 3.0.9, 2013-05-21
120
+
121
+ * Add url in parameters accessible through Semrush.before & Semrush.after
122
+
123
+ === 3.0.8, 2013-05-21
124
+
125
+ * Move after & before callbacks to Semrush module: Semrush.before & Semrush.after
126
+
127
+ === 3.0.7, 2013-05-21
128
+
129
+ * Add after & before callbacks
130
+
131
+ === 3.0.6, 2013-05-7
132
+
133
+ * Add method remaining_quota
134
+
97
135
  == About authors
98
136
 
99
137
  This gem is inspired by the work of Cramer Development for the semrush-client plugin (https://github.com/cramerdev/semrush-client).
data/Rakefile CHANGED
@@ -21,7 +21,7 @@ require "rspec/core/rake_task"
21
21
  desc "Run all test with spec"
22
22
  RSpec::Core::RakeTask.new(:spec) do |t|
23
23
  t.rspec_opts = %w[--color]
24
- t.pattern = 'spec/*_spec.rb'
24
+ t.pattern = 'spec/**/*_spec.rb'
25
25
  end
26
26
  desc "Run tests"
27
27
  task :default => :spec
data/lib/semrush.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'uri'
2
+ require 'cgi'
2
3
  require 'net/http'
3
4
  require 'csv'
4
5
  require 'rubygems'
@@ -8,7 +9,7 @@ require 'semrush/exception'
8
9
  require 'semrush/report'
9
10
 
10
11
  module Semrush
11
- API_REPORT_URL = "http://%DB%.api.semrush.com/?action=report&type=%REPORT_TYPE%&%REQUEST_TYPE%=%REQUEST%&key=%API_KEY%&display_limit=%LIMIT%&display_offset=%OFFSET%&export=api&export_columns=%EXPORT_COLUMNS%"
12
+ API_REPORT_URL = "http://%DB%.api.semrush.com/?action=report&type=%REPORT_TYPE%&%REQUEST_TYPE%=%REQUEST%&key=%API_KEY%&display_limit=%LIMIT%&display_offset=%OFFSET%&export=api&export_columns=%EXPORT_COLUMNS%&display_sort=%DISPLAY_SORT%&display_filter=%DISPLAY_FILTER%"
12
13
  API_UNITS_URL = "http://www.semrush.com/users/countapiunits.html?key=%API_KEY%"
13
14
  mattr_accessor :api_key
14
15
  @@api_key = ""
@@ -9,7 +9,7 @@ module Semrush
9
9
  class Report
10
10
  DBS = [:us, :uk, :ru, :de, :fr, :es, :it, :br, :au] #"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.
11
11
  REPORT_TYPES = [:domain_rank, :domain_organic, :domain_adwords, :domain_organic_organic, :domain_adwords_adwords, :domain_organic_adwords, :domain_adwords_organic,
12
- :phrase_this, :phrase_related,
12
+ :phrase_this, :phrase_organic, :phrase_related,
13
13
  :url_organic, :url_adwords]
14
14
  REQUEST_TYPES = [:domain, :phrase, :url]
15
15
 
@@ -111,7 +111,7 @@ module Semrush
111
111
  domain? ? request(params.merge(:report_type => :domain_rank)) : request(params.merge(:report_type => :phrase_this))
112
112
  end
113
113
 
114
- # Organic Keywords report
114
+ # Organic report
115
115
  # Can be called for a domain or a URL.
116
116
  # Default columns for a domain:
117
117
  # * Ph - The search query which the site has within the first 20 Google search results
@@ -135,11 +135,22 @@ module Semrush
135
135
  # * Tc - The ratio of the estimated cost of buying the same number of visitors for this search query to the estimated cost of purchasing the same number of targeted visitors coming to this URL
136
136
  # * Nr - The number of search results - how many pages does Google know for this query
137
137
  # * Td - Dynamics of change in the number of search queries in the past 12 months (estimated)
138
+ # Default columns for a phrase:
139
+ # * Dn - A site name
140
+ # * Ur - Target URL
141
+ def organic params = {}
142
+ case
143
+ when url? then request(params.merge(:report_type => :url_organic))
144
+ when phrase? then request(params.merge(:report_type => :phrase_organic))
145
+ else request(params.merge(:report_type => :domain_organic))
146
+ end
147
+ end
138
148
  def keywords_organic params = {}
139
- url? ? request(params.merge(:report_type => :url_organic)) : request(params.merge(:report_type => :domain_organic))
149
+ warn "[DEPRECATION] `keywords_organic` is deprecated. Please use `organic` instead."
150
+ organic(params)
140
151
  end
141
152
 
142
- # AdWords keywords report
153
+ # AdWords report
143
154
  # Can be called for a domain or a URL.
144
155
  # Default columns for a domain:
145
156
  # * Ph - Search query which the site buys in AdWords in Google
@@ -164,9 +175,13 @@ module Semrush
164
175
  # * Tc - The ratio of the estimated cost of buying the same number of visitors for this search query to the estimated cost of purchasing the same number of targeted visitors coming to this URL
165
176
  # * Nr - The number of search results - how many pages does Google know for this query
166
177
  # * Td - Dynamics of change in the number of search queries in the past 12 months (estimated)
167
- def keywords_adwords params = {}
178
+ def adwords params = {}
168
179
  url? ? request(params.merge(:report_type => :url_adwords)) : request(params.merge(:report_type => :domain_adwords))
169
180
  end
181
+ def keywords_adwords params = {}
182
+ warn "[DEPRECATION] `keywords_adwords` is deprecated. Please use `adwords` instead."
183
+ adwords(params)
184
+ end
170
185
 
171
186
  # Competitors in organic search report
172
187
  # Default columns:
@@ -237,7 +252,7 @@ module Semrush
237
252
  if v.blank?
238
253
  temp_url.gsub!(/&[^&=]+=%#{k.to_s}%/i, '')
239
254
  else
240
- temp_url.gsub!("%#{k.to_s.upcase}%", URI.escape(v.to_s).gsub('&', '%26'))
255
+ temp_url.gsub!("%#{k.to_s.upcase}%", URI.escape(v.to_s).gsub('&', '%26').gsub('+', '%2B'))
241
256
  end
242
257
  }
243
258
  puts "[Semrush query] URL: #{temp_url}" if Semrush.debug
@@ -261,6 +276,8 @@ module Semrush
261
276
  # * limit - number of results returned
262
277
  # * offset - says to skip that many results before beginning to return results to you
263
278
  # * export_columns - list of column names, separated by coma. You may list just the column names you need in an order you need.
279
+ # * display_sort - a sorting as a String eg: 'am_asc' or 'am_desc'(read http://www.semrush.com/api)
280
+ # * display_filter - list of filters separated by "|" (maximum number - 25). A filter consists of <sign>|<field>|<operation>|<value> (read http://www.semrush.com/api)
264
281
  #
265
282
  # more details in http://www.semrush.com/api.html
266
283
  def validate_parameters params = {}
@@ -268,7 +285,7 @@ module Semrush
268
285
  params.delete(:db) unless DBS.include?(params[:db].try(:to_sym))
269
286
  params.delete(:report_type) unless REPORT_TYPES.include?(params[:report_type].try(:to_sym))
270
287
  params.delete(:request_type) unless REQUEST_TYPES.include?(params[:request_type].try(:to_sym))
271
- @parameters = {:db => "us", :api_key => Semrush.api_key, :limit => "", :offset => "", :export_columns => ""}.merge(@parameters).merge(params)
288
+ @parameters = {:db => "us", :api_key => Semrush.api_key, :limit => "", :offset => "", :export_columns => "", :display_sort => "", :display_filter => ""}.merge(@parameters).merge(params)
272
289
  raise Semrush::Exception::Nolimit.new(self, "The limit parameter is missing: a limit is required.") unless @parameters[:limit].present? && @parameters[:limit].to_i>0
273
290
  raise Semrush::Exception::BadArgument.new(self, "Request parameter is missing: Domain name, URL, or keywords are required.") unless @parameters[:request].present?
274
291
  raise Semrush::Exception::BadArgument.new(self, "Bad db: #{@parameters[:db]}") unless DBS.include?(@parameters[:db].try(:to_sym))
@@ -1,3 +1,3 @@
1
1
  module Semrush
2
- VERSION = "3.0.12" # we want to follow the API version: for API 3.0, the gem will be version 3.0.x
2
+ VERSION = "3.0.13" # 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.12
4
+ version: 3.0.13
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-05-31 00:00:00.000000000 Z
12
+ date: 2013-06-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport