majestic_seo_api 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -62,26 +62,40 @@ module MajesticSeo
|
|
62
62
|
|
63
63
|
def parse_row(row)
|
64
64
|
if (row && row.content)
|
65
|
-
row
|
66
|
-
row_hash
|
67
|
-
splitted_row
|
65
|
+
row = row.content
|
66
|
+
row_hash = {}
|
67
|
+
splitted_row = split(row, true)
|
68
|
+
splitted_row = adjust_for_invalid_title(splitted_row)
|
68
69
|
|
69
70
|
@headers.each_with_index do |header, index|
|
70
71
|
value = splitted_row[index].strip
|
71
72
|
value = (value && value != "") ? value : nil
|
72
73
|
|
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
|
-
|
79
74
|
row_hash[header] = value
|
80
75
|
end
|
81
76
|
|
82
77
|
@rows << row_hash if (row_hash && !row_hash.empty?)
|
83
78
|
end
|
84
79
|
end
|
80
|
+
|
81
|
+
def adjust_for_invalid_title(rows)
|
82
|
+
if (rows.size > @headers.size)
|
83
|
+
difference = rows.size - @headers.size
|
84
|
+
index = @headers.index("Title")
|
85
|
+
|
86
|
+
title = rows[index]
|
87
|
+
remaining_title = ""
|
88
|
+
|
89
|
+
1.upto(difference) do |diff_index|
|
90
|
+
remaining_title += rows.delete_at(index+1)
|
91
|
+
end
|
92
|
+
|
93
|
+
title += remaining_title
|
94
|
+
rows[index] = title
|
95
|
+
end
|
96
|
+
|
97
|
+
return rows
|
98
|
+
end
|
85
99
|
|
86
100
|
def split(text, remove_excess_separators = false)
|
87
101
|
text = text.gsub(/\|{2,}/i, "|") if remove_excess_separators
|
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.3'
|
7
7
|
|
8
8
|
s.homepage = "http://developer-support.majesticseo.com/connectors/"
|
9
9
|
s.email = "sebastian@agiley.se"
|
@@ -261,4 +261,61 @@ describe MajesticSeo::Api::ItemInfoResponse do
|
|
261
261
|
end
|
262
262
|
end
|
263
263
|
|
264
|
+
#Example XML:
|
265
|
+
#<Result Code="OK" ErrorMessage="" FullError="">
|
266
|
+
# <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"/>
|
267
|
+
# <DataTables Count="1">
|
268
|
+
# <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">
|
269
|
+
# <Row>0|simplygreat.se|OK|Found|1577|31|1577|-1|1|276|5000|25000|29|29|0|0|0|0|0|0|0|0|False| | |False| |0|0|0| |Henrik Nilsson || Designer, Strateg || henrik@simplygreat.se || 0730 - 248 757| |9|3|3</Row>
|
270
|
+
# </DataTable>
|
271
|
+
# </DataTables>
|
272
|
+
#</Result>
|
273
|
+
describe "response with the title column containing multiple separators (|) inside" do
|
274
|
+
before(:each) do
|
275
|
+
#We need to keep the XML on one line - JRuby goes bonanza otherwise
|
276
|
+
@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|simplygreat.se|OK|Found|1577|31|1577|-1|1|276|5000|25000|29|29|0|0|0|0|0|0|0|0|False| | |False| |0|0|0| |Henrik Nilsson || Designer, Strateg || henrik@simplygreat.se || 0730 - 248 757| |9|3|3</Row></DataTable></DataTables></Result>'
|
277
|
+
@parsed = ::Nokogiri::XML(@xml, nil, "utf-8")
|
278
|
+
@response = MajesticSeo::Api::ItemInfoResponse.new(@parsed)
|
279
|
+
@table = @response.tables["Results"]
|
280
|
+
end
|
281
|
+
|
282
|
+
it "should be a valid response" do
|
283
|
+
@response.success.should == true
|
284
|
+
end
|
285
|
+
|
286
|
+
it "should not have an error message" do
|
287
|
+
@response.error_message.should == ""
|
288
|
+
end
|
289
|
+
|
290
|
+
it "should have global variables set" do
|
291
|
+
@response.global_variables["most_recent_back_link_date"].should == "2012-10-14"
|
292
|
+
@response.global_variables["index_type"].should == "0"
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should have one returned data table" do
|
296
|
+
@response.tables.size.should == 1
|
297
|
+
end
|
298
|
+
|
299
|
+
it "should have a data table with the name 'Results'" do
|
300
|
+
@table.should_not be_nil
|
301
|
+
end
|
302
|
+
|
303
|
+
it "should have a data table with the name 'Results' containing 1 row" do
|
304
|
+
@table.row_count.should == 1
|
305
|
+
end
|
306
|
+
|
307
|
+
it "should have results for simplygreat.se" do
|
308
|
+
row = @response.items[0]
|
309
|
+
|
310
|
+
row.url.should == "simplygreat.se"
|
311
|
+
row.type.should == :root_domain
|
312
|
+
row.result_code.should == "OK"
|
313
|
+
row.success.should == true
|
314
|
+
row.status.should == "Found"
|
315
|
+
row.citation_flow.should == 9
|
316
|
+
row.trust_flow.should == 3
|
317
|
+
row.trust_metric.should == 3
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
264
321
|
end
|