semrush 3.0.5 → 3.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +8 -3
- data/lib/semrush.rb +1 -1
- data/lib/semrush/report.rb +22 -0
- data/lib/semrush/version.rb +1 -1
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -37,13 +37,18 @@ or
|
|
37
37
|
|
38
38
|
keywords_data = report.keywords_organic
|
39
39
|
|
40
|
+
If you want to know your remaining api units:
|
41
|
+
|
42
|
+
units = Semrush::Report.remaining_quota
|
43
|
+
|
44
|
+
|
40
45
|
== Parameters
|
41
46
|
|
42
47
|
You may use the following parameters:
|
43
48
|
|
44
|
-
:db # (String) select the google engine ('us' for google.
|
49
|
+
:db # (String) select the google engine ('us' for google.com 'fr' for google.fr)
|
45
50
|
:api_key # (String) change the api_key
|
46
|
-
:limit # (Integer) select only the first 'limit' entries
|
51
|
+
:limit # (Integer) select only the first 'limit' entries (This parameter is required in order to avoid uncontrolled heavy usage)
|
47
52
|
:offset # (Integer) skip the first 'offset' entries
|
48
53
|
:export_columns # (String) select the columns you want to fetch, for instance: :export_columns => "Dn,Rk"
|
49
54
|
|
@@ -90,4 +95,4 @@ This gem is inspired by the work of Cramer Development for the semrush-client pl
|
|
90
95
|
|
91
96
|
It has been rewritten and gemified for the internal use in Weboglobin (http://fr.weboglobin.com).
|
92
97
|
|
93
|
-
This project rocks and uses MIT-LICENSE.
|
98
|
+
This project rocks and uses MIT-LICENSE.
|
data/lib/semrush.rb
CHANGED
@@ -9,7 +9,7 @@ require 'semrush/report'
|
|
9
9
|
|
10
10
|
module Semrush
|
11
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
|
-
|
12
|
+
API_UNITS_URL = "http://fr.semrush.com/users/countapiunits.html?key=%API_KEY%"
|
13
13
|
mattr_accessor :api_key
|
14
14
|
@@api_key = ""
|
15
15
|
mattr_accessor :debug
|
data/lib/semrush/report.rb
CHANGED
@@ -59,6 +59,28 @@ module Semrush
|
|
59
59
|
self.new(params.merge(:request_type => :url, :request => url))
|
60
60
|
end
|
61
61
|
|
62
|
+
# Initializes & calls a report for the remaining API units
|
63
|
+
# Takes a hash parameter that may contain the following keys :
|
64
|
+
# * :api_key (ex: :api_key => 'gt97s6d4a6w')
|
65
|
+
def self.remaining_quota params = {}
|
66
|
+
temp_url = "#{API_UNITS_URL}" #do not copy the constant as is or else the constant would be modified !!
|
67
|
+
params = {:api_key => Semrush.api_key}.merge(params)
|
68
|
+
params.each {|k, v|
|
69
|
+
if v.blank?
|
70
|
+
temp_url.gsub!(/&[^&=]+=%#{k.to_s}%/i, '')
|
71
|
+
else
|
72
|
+
temp_url.gsub!("%#{k.to_s.upcase}%", URI.escape(v.to_s).gsub('&', '%26'))
|
73
|
+
end
|
74
|
+
}
|
75
|
+
puts "[Semrush query] URL: #{temp_url}" if Semrush.debug
|
76
|
+
url = URI.parse(temp_url)
|
77
|
+
response = Net::HTTP.start(url.host, url.port) {|http|
|
78
|
+
http.get(url.path+"?"+url.query)
|
79
|
+
}.body rescue "ERROR :: RESPONSE ERROR (-1)" # Make this error up
|
80
|
+
response.force_encoding("utf-8")
|
81
|
+
response.starts_with?("ERROR") ? error(response) : response.to_i
|
82
|
+
end
|
83
|
+
|
62
84
|
# Main report.
|
63
85
|
# Available for a phrase or a domain.
|
64
86
|
# Default columns for a domain:
|
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.6
|
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-03-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|