majestic_seo_api 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
@@ -34,9 +34,9 @@ module MajesticSeo
|
|
34
34
|
module Api
|
35
35
|
class DataTable
|
36
36
|
attr_accessor :node, :name, :row_count, :headers, :rows
|
37
|
-
|
37
|
+
|
38
38
|
def initialize(node)
|
39
|
-
@node
|
39
|
+
@node = node
|
40
40
|
|
41
41
|
if (@node)
|
42
42
|
@name = @node["Name"] || nil
|
@@ -64,11 +64,18 @@ module MajesticSeo
|
|
64
64
|
if (row && row.content)
|
65
65
|
row = row.content
|
66
66
|
row_hash = {}
|
67
|
-
splitted_row = split(row)
|
68
|
-
|
67
|
+
splitted_row = split(row, true)
|
68
|
+
|
69
69
|
@headers.each_with_index do |header, index|
|
70
70
|
value = splitted_row[index].strip
|
71
71
|
value = (value && value != "") ? value : nil
|
72
|
+
|
73
|
+
#If the title element contains a |-sign (the separator) the title will be splitted into two rows, thus breaking the parsing of the remaining rows
|
74
|
+
if (header.eql?("Title") && splitted_row.size > @headers.size)
|
75
|
+
remaining_title = splitted_row.delete_at(index+1).strip
|
76
|
+
value += remaining_title if value
|
77
|
+
end
|
78
|
+
|
72
79
|
row_hash[header] = value
|
73
80
|
end
|
74
81
|
|
@@ -76,8 +83,9 @@ module MajesticSeo
|
|
76
83
|
end
|
77
84
|
end
|
78
85
|
|
79
|
-
def split(text)
|
80
|
-
|
86
|
+
def split(text, remove_excess_separators = false)
|
87
|
+
text = text.gsub(/\|{2,}/i, "|") if remove_excess_separators
|
88
|
+
splitted = text.split(/\|(?!\|)/)
|
81
89
|
end
|
82
90
|
|
83
91
|
def row_count
|
data/lib/majestic_seo_api.rb
CHANGED
data/majestic_seo_api.gemspec
CHANGED
@@ -3,7 +3,7 @@ Gem::Specification.new do |s|
|
|
3
3
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.3.5") if s.respond_to? :required_rubygems_version=
|
4
4
|
|
5
5
|
s.name = 'majestic_seo_api'
|
6
|
-
s.version = '1.2.
|
6
|
+
s.version = '1.2.2'
|
7
7
|
|
8
8
|
s.homepage = "http://developer-support.majesticseo.com/connectors/"
|
9
9
|
s.email = "sebastian@agiley.se"
|
@@ -185,7 +185,7 @@ describe MajesticSeo::Api::ItemInfoResponse do
|
|
185
185
|
@table.should_not be_nil
|
186
186
|
end
|
187
187
|
|
188
|
-
it "should have a data table with the name 'Results' containing
|
188
|
+
it "should have a data table with the name 'Results' containing 1 row" do
|
189
189
|
@table.row_count.should == 1
|
190
190
|
end
|
191
191
|
|
@@ -203,4 +203,62 @@ describe MajesticSeo::Api::ItemInfoResponse do
|
|
203
203
|
end
|
204
204
|
end
|
205
205
|
|
206
|
+
#Example XML:
|
207
|
+
#<Result Code="OK" ErrorMessage="" FullError="">
|
208
|
+
# <GlobalVars FirstBackLinkDate="2007-03-14" IndexBuildDate="2012-11-05 04:42:33" IndexType="0" MostRecentBackLinkDate="2012-10-14" ServerBuild="2012-11-07 12:42:57" ServerName="PWRGURU" ServerVersion="1.0.4694.22888" UniqueIndexID="20121105044233-HISTORICAL"/>
|
209
|
+
# <DataTables Count="1">
|
210
|
+
# <DataTable Name="Results" RowsCount="1" Headers="ItemNum|Item|ResultCode|Status|ExtBackLinks|RefDomains|AnalysisResUnitsCost|ACRank|ItemType|IndexedURLs|GetTopBackLinksAnalysisResUnitsCost|DownloadBacklinksAnalysisResUnitsCost|RefIPs|RefSubNets|RefDomainsEDU|ExtBackLinksEDU|RefDomainsGOV|ExtBackLinksGOV|RefDomainsEDU_Exact|ExtBackLinksEDU_Exact|RefDomainsGOV_Exact|ExtBackLinksGOV_Exact|CrawledFlag|LastCrawlDate|LastCrawlResult|RedirectFlag|FinalRedirectResult|OutDomainsExternal|OutLinksExternal|OutLinksInternal|LastSeen|Title|RedirectTo|CitationFlow|TrustFlow|TrustMetric">
|
211
|
+
# <Row>0|theconnection.se|OK|Found|117646|8599|117646|-1|1|8592|5000|126238|7119|4659|60|1072|6|38|3|57|0|0|False| | |False| |0|0|0| |
|
212
|
+
# Nätverk och större möjligheter till frihet. || The Connection. | |16|4|4</Row>
|
213
|
+
# </DataTable>
|
214
|
+
# </DataTables>
|
215
|
+
#</Result>
|
216
|
+
describe "response with the title column containing the separator (|) inside" do
|
217
|
+
before(:each) do
|
218
|
+
#We need to keep the XML on one line - JRuby goes bonanza otherwise
|
219
|
+
@xml = '<Result Code="OK" ErrorMessage="" FullError=""><GlobalVars FirstBackLinkDate="2007-03-14" IndexBuildDate="2012-11-05 04:42:33" IndexType="0" MostRecentBackLinkDate="2012-10-14" ServerBuild="2012-11-07 12:42:57" ServerName="PWRGURU" ServerVersion="1.0.4694.22888" UniqueIndexID="20121105044233-HISTORICAL"/><DataTables Count="1"><DataTable Name="Results" RowsCount="1" Headers="ItemNum|Item|ResultCode|Status|ExtBackLinks|RefDomains|AnalysisResUnitsCost|ACRank|ItemType|IndexedURLs|GetTopBackLinksAnalysisResUnitsCost|DownloadBacklinksAnalysisResUnitsCost|RefIPs|RefSubNets|RefDomainsEDU|ExtBackLinksEDU|RefDomainsGOV|ExtBackLinksGOV|RefDomainsEDU_Exact|ExtBackLinksEDU_Exact|RefDomainsGOV_Exact|ExtBackLinksGOV_Exact|CrawledFlag|LastCrawlDate|LastCrawlResult|RedirectFlag|FinalRedirectResult|OutDomainsExternal|OutLinksExternal|OutLinksInternal|LastSeen|Title|RedirectTo|CitationFlow|TrustFlow|TrustMetric"><Row>0|theconnection.se|OK|Found|117646|8599|117646|-1|1|8592|5000|126238|7119|4659|60|1072|6|38|3|57|0|0|False| | |False| |0|0|0| | Nätverk och större möjligheter till frihet. || The Connection. | |16|4|4</Row></DataTable></DataTables></Result>'
|
220
|
+
@parsed = ::Nokogiri::XML(@xml, nil, "utf-8")
|
221
|
+
@response = MajesticSeo::Api::ItemInfoResponse.new(@parsed)
|
222
|
+
@table = @response.tables["Results"]
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should be a valid response" do
|
226
|
+
@response.success.should == true
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should not have an error message" do
|
230
|
+
@response.error_message.should == ""
|
231
|
+
end
|
232
|
+
|
233
|
+
it "should have global variables set" do
|
234
|
+
@response.global_variables["most_recent_back_link_date"].should == "2012-10-14"
|
235
|
+
@response.global_variables["index_type"].should == "0"
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should have one returned data table" do
|
239
|
+
@response.tables.size.should == 1
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should have a data table with the name 'Results'" do
|
243
|
+
@table.should_not be_nil
|
244
|
+
end
|
245
|
+
|
246
|
+
it "should have a data table with the name 'Results' containing 1 row" do
|
247
|
+
@table.row_count.should == 1
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should have results for theconnection.se" do
|
251
|
+
row = @response.items[0]
|
252
|
+
|
253
|
+
row.url.should == "theconnection.se"
|
254
|
+
row.type.should == :root_domain
|
255
|
+
row.result_code.should == "OK"
|
256
|
+
row.success.should == true
|
257
|
+
row.status.should == "Found"
|
258
|
+
row.citation_flow.should == 16
|
259
|
+
row.trust_flow.should == 4
|
260
|
+
row.trust_metric.should == 4
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
206
264
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: majestic_seo_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-11-
|
13
|
+
date: 2012-11-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday
|