majestic_seo_api 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +13 -0
- data/LICENSE.txt +50 -0
- data/README.markdown +69 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/lib/generators/majestic_seo/majestic_seo_generator.rb +18 -0
- data/lib/generators/templates/majestic_seo.template.yml +13 -0
- data/lib/majestic_seo/api/client.rb +151 -0
- data/lib/majestic_seo/api/data_table.rb +90 -0
- data/lib/majestic_seo/api/item_info.rb +126 -0
- data/lib/majestic_seo/api/item_info_response.rb +58 -0
- data/lib/majestic_seo/api/logger.rb +11 -0
- data/lib/majestic_seo/api/response.rb +113 -0
- data/lib/majestic_seo/api/top_back_links_response.rb +44 -0
- data/lib/majestic_seo/extensions/string.rb +10 -0
- data/lib/majestic_seo/railtie.rb +12 -0
- data/lib/majestic_seo_api.rb +17 -0
- data/majestic_seo_api.gemspec +84 -0
- data/script/get_index_item_info.rb +137 -0
- data/script/get_top_backlinks.rb +140 -0
- data/script/open_app_get_index_item_info.rb +156 -0
- data/spec/majestic_seo/client_spec.rb +68 -0
- data/spec/majestic_seo/item_info_response_spec.rb +136 -0
- data/spec/majestic_seo/top_back_links_response_spec.rb +31 -0
- data/spec/spec_helper.rb +26 -0
- metadata +160 -0
@@ -0,0 +1,156 @@
|
|
1
|
+
|
2
|
+
=begin
|
3
|
+
|
4
|
+
Version 0.9.3
|
5
|
+
|
6
|
+
Copyright (c) 2011, Majestic-12 Ltd
|
7
|
+
All rights reserved.
|
8
|
+
|
9
|
+
Redistribution and use in source and binary forms, with or without
|
10
|
+
modification, are permitted provided that the following conditions are met:
|
11
|
+
1. Redistributions of source code must retain the above copyright
|
12
|
+
notice, this list of conditions and the following disclaimer.
|
13
|
+
2. Redistributions in binary form must reproduce the above copyright
|
14
|
+
notice, this list of conditions and the following disclaimer in the
|
15
|
+
documentation and/or other materials provided with the distribution.
|
16
|
+
3. Neither the name of the Majestic-12 Ltd nor the
|
17
|
+
names of its contributors may be used to endorse or promote products
|
18
|
+
derived from this software without specific prior written permission.
|
19
|
+
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL Majestic-12 Ltd BE LIABLE FOR ANY
|
24
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
27
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
|
31
|
+
=end
|
32
|
+
|
33
|
+
# NOTE: The code below is specifically for the GetIndexItemInfo API command
|
34
|
+
# For other API commands, the arguments required may differ.
|
35
|
+
# Please refer to the Majestic SEO Developer Wiki for more information
|
36
|
+
# regarding other API commands and their arguments.
|
37
|
+
|
38
|
+
|
39
|
+
# add the majesticseo-external-rpc library to the search path
|
40
|
+
$: << File.expand_path(File.dirname(__FILE__));
|
41
|
+
|
42
|
+
require 'majesticseo-external-rpc/api_service'
|
43
|
+
|
44
|
+
endpoint = "http://enterprise.majesticseo.com/api_command";
|
45
|
+
|
46
|
+
puts "\n***********************************************************" +
|
47
|
+
"*****************";
|
48
|
+
|
49
|
+
puts "\nEndpoint: #{endpoint}";
|
50
|
+
|
51
|
+
if("http://enterprise.majesticseo.com/api_command" == endpoint)
|
52
|
+
puts "\nThis program is hard-wired to the Enterprise API.";
|
53
|
+
|
54
|
+
puts "\nIf you do not have access to the Enterprise API, " +
|
55
|
+
"change the endpoint to: \nhttp://developer.majesticseo.com/api_command.";
|
56
|
+
else
|
57
|
+
puts "\nThis program is hard-wired to the Developer API " +
|
58
|
+
"and hence the subset of data \nreturned will be substantially " +
|
59
|
+
"smaller than that which will be returned from \neither the " +
|
60
|
+
"Enterprise API or the Majestic SEO website.";
|
61
|
+
|
62
|
+
puts "\nTo make this program use the Enterprise API, change " +
|
63
|
+
"the endpoint to: \nhttp://enterprise.majesticseo.com/api_command.";
|
64
|
+
end
|
65
|
+
|
66
|
+
puts "\n***********************************************************" +
|
67
|
+
"*****************";
|
68
|
+
|
69
|
+
puts "\n\nThis example program will return key information about \"index items\"." +
|
70
|
+
"\n\nThe following must be provided in order to run this program: " +
|
71
|
+
"\n1. OpenApp \"private key\"\n2. Access Token\n3. List of items to query" +
|
72
|
+
"\n\nPlease enter a valid OpenApp \"private key\":\n";
|
73
|
+
|
74
|
+
private_key = gets.chomp;
|
75
|
+
|
76
|
+
puts "\nEnter your user access token:\n";
|
77
|
+
|
78
|
+
access_token = gets.chomp;
|
79
|
+
|
80
|
+
puts "\nPlease enter the list of items you wish to query seperated by " +
|
81
|
+
"commas: \n(e.g. majesticseo.com, majestic12.co.uk)\n";
|
82
|
+
|
83
|
+
items_to_query = gets.chomp;
|
84
|
+
items = items_to_query.split(/, /);
|
85
|
+
|
86
|
+
# create a hash from the resulting array with the key being
|
87
|
+
# "item0 => first item to query, item1 => second item to query" etc
|
88
|
+
items_hash = Hash.new;
|
89
|
+
0.upto(items.length-1) do |i|
|
90
|
+
items_hash["item" + i.to_s] = items[i];
|
91
|
+
end
|
92
|
+
|
93
|
+
# add the total number of items to the hash with the key being "items"
|
94
|
+
items_hash['items'] = items.length.to_s;
|
95
|
+
items_hash['datasource'] = 'fresh';
|
96
|
+
|
97
|
+
api_service = ApiService.new(private_key, endpoint);
|
98
|
+
response = api_service.execute_openapp_request('GetIndexItemInfo', items_hash, access_token);
|
99
|
+
|
100
|
+
# check the response code
|
101
|
+
if(response.is_ok)
|
102
|
+
# print the results table
|
103
|
+
results = response.table_for_name('Results');
|
104
|
+
results.rows.each do |row|
|
105
|
+
item = row['Item'];
|
106
|
+
puts "\n<#{item}>\n";
|
107
|
+
|
108
|
+
row.keys.sort.each do |key|
|
109
|
+
unless(key.eql?('Item'))
|
110
|
+
value = row[key];
|
111
|
+
puts " #{key} ... #{value}\n";
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
if("http://developer.majesticseo.com/api_command" == endpoint)
|
117
|
+
puts "\n\n***********************************************************" +
|
118
|
+
"*****************";
|
119
|
+
|
120
|
+
puts "\nEndpoint: #{endpoint}";
|
121
|
+
|
122
|
+
puts"\nThis program is hard-wired to the Developer API " +
|
123
|
+
"and hence the subset of data \nreturned will be substantially " +
|
124
|
+
"smaller than that which will be returned from \neither the " +
|
125
|
+
"Enterprise API or the Majestic SEO website.";
|
126
|
+
|
127
|
+
puts "\nTo make this program use the Enterprise API, change " +
|
128
|
+
"the endpoint to: \nhttp://enterprise.majesticseo.com/api_command.";
|
129
|
+
|
130
|
+
puts "\n***********************************************************" +
|
131
|
+
"*****************";
|
132
|
+
end
|
133
|
+
else
|
134
|
+
puts "\nERROR MESSAGE:";
|
135
|
+
puts response.error_message;
|
136
|
+
|
137
|
+
puts "\n\n***********************************************************" +
|
138
|
+
"*****************";
|
139
|
+
|
140
|
+
puts "\nDebugging Info:\n";
|
141
|
+
puts "Endpoint:\t#{endpoint}\n";
|
142
|
+
puts "OpenApp \"private key\":\t#{private_key}\n";
|
143
|
+
puts "Access token:\t#{access_token}\n";
|
144
|
+
|
145
|
+
if("http://enterprise.majesticseo.com/api_command" == endpoint)
|
146
|
+
puts "\n Is this API Key valid for this Endpoint?";
|
147
|
+
|
148
|
+
puts "\n This program is hard-wired to the Enterprise API.";
|
149
|
+
|
150
|
+
puts "\n If you do not have access to the Enterprise API, " +
|
151
|
+
"change the endpoint to: \n http://developer.majesticseo.com/api_command.";
|
152
|
+
end
|
153
|
+
|
154
|
+
puts "\n***********************************************************" +
|
155
|
+
"*****************";
|
156
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Majestic Seo Api Client" do
|
4
|
+
describe "initialization settings" do
|
5
|
+
|
6
|
+
describe "with defaults" do
|
7
|
+
before(:each) do
|
8
|
+
config = {"environment" => "sandbox", "api_key" => "api_key"}
|
9
|
+
MajesticSeo::Api::Client.any_instance.expects(:config).at_least_once.returns(config)
|
10
|
+
@client = MajesticSeo::Api::Client.new
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should contain a key" do
|
14
|
+
@client.api_key.should == "api_key"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have the environment set to sandbox" do
|
18
|
+
@client.environment.should == :sandbox
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#get_index_item_info" do
|
24
|
+
it "should send a correct request" do
|
25
|
+
client = MajesticSeo::Api::Client.new
|
26
|
+
|
27
|
+
urls = ["google.com", "yahoo.com"]
|
28
|
+
options = {:timeout => 5}
|
29
|
+
|
30
|
+
expecting = {"datasource" => "historic",
|
31
|
+
"items" => 2,
|
32
|
+
"item0" => "google.com",
|
33
|
+
"item1" => "yahoo.com",
|
34
|
+
"app_api_key" => client.api_key,
|
35
|
+
"cmd" => "GetIndexItemInfo"}
|
36
|
+
|
37
|
+
client.expects(:execute_request).with(expecting, options[:timeout])
|
38
|
+
response = client.get_index_item_info(urls, options)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#get_top_back_links" do
|
43
|
+
it "should send a correct request" do
|
44
|
+
client = MajesticSeo::Api::Client.new
|
45
|
+
|
46
|
+
url = "google.com"
|
47
|
+
options = {:timeout => 5}
|
48
|
+
|
49
|
+
expecting = {"datasource" => "historic",
|
50
|
+
"URL" => "google.com",
|
51
|
+
"MaxSourceURLs" => 100,
|
52
|
+
"ShowDomainInfo" => 0,
|
53
|
+
"GetUrlData" => 1,
|
54
|
+
"GetSubDomainData" => 0,
|
55
|
+
"GetRootDomainData" => 0,
|
56
|
+
"MaxSourceURLsPerRefDomain" => -1,
|
57
|
+
"DebugForceQueue" => 0,
|
58
|
+
"app_api_key" => client.api_key,
|
59
|
+
"cmd" => "GetTopBackLinks"}
|
60
|
+
|
61
|
+
client.expects(:execute_request).with(expecting, options[:timeout])
|
62
|
+
response = client.get_top_back_links(url, options)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
@@ -0,0 +1,136 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
3
|
+
|
4
|
+
describe MajesticSeo::Api::ItemInfoResponse do
|
5
|
+
|
6
|
+
#Example XML:
|
7
|
+
#<?xml version="1.0" encoding="utf-8"?>
|
8
|
+
#<Result Code="OK" ErrorMessage="" FullError="">
|
9
|
+
# <GlobalVars FirstBackLinkDate="2006-06-06" IndexBuildDate="04/01/2012 09:14:02" IndexType="0" MostRecentBackLinkDate="2011-12-18" RecentBackLinksFromDate="2011-09-19" ServerBuild="2011-11-07 13:20:36" ServerName="PWRGURU" ServerVersion="1.0.4328.24018"/>
|
10
|
+
# <DataTables Count="1">
|
11
|
+
# <DataTable Name="Results" RowsCount="2" Headers="ItemNum|Item|ResultCode|Status|ExtBackLinks|RefDomains|AnalysisResUnitsCost|ACRank|ItemType|IndexedURLs|GetTopBackLinksAnalysisResUnitsCost|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">
|
12
|
+
# <Row>0|google.com|OK|Found|33536625553|15560001|33536625553|-1|1|5087871285|5000|2135470|363423|31636|147893369|22859|39850401|5833|43625720|6237|6983793|False| | |False| |0|0|0| | |http://www.google.nl</Row>
|
13
|
+
# <Row>1|yahoo.com|OK|Found|16814018765|8374570|16814018765|-1|1|3845667299|5000|1345597|266044|17992|24506182|10441|12766565|4284|5810404|1217|1338346|False| | |False| |0|0|0| | |http://pl.yahoo.com/?p=us</Row>
|
14
|
+
# </DataTable>
|
15
|
+
# </DataTables>
|
16
|
+
#</Result>
|
17
|
+
|
18
|
+
describe "successful ASCII response from MajesticSeo" do
|
19
|
+
before(:each) do
|
20
|
+
#We need to keep the XML on one line - JRuby goes bonanza otherwise
|
21
|
+
@xml = '<?xml version="1.0" encoding="utf-8"?><Result Code="OK" ErrorMessage="" FullError=""><GlobalVars FirstBackLinkDate="2006-06-06" IndexBuildDate="04/01/2012 09:14:02" IndexType="0" MostRecentBackLinkDate="2011-12-18" RecentBackLinksFromDate="2011-09-19" ServerBuild="2011-11-07 13:20:36" ServerName="PWRGURU" ServerVersion="1.0.4328.24018"/><DataTables Count="1"><DataTable Name="Results" RowsCount="2" Headers="ItemNum|Item|ResultCode|Status|ExtBackLinks|RefDomains|AnalysisResUnitsCost|ACRank|ItemType|IndexedURLs|GetTopBackLinksAnalysisResUnitsCost|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"><Row>0|google.com|OK|Found|33536625553|15560001|33536625553|-1|1|5087871285|5000|2135470|363423|31636|147893369|22859|39850401|5833|43625720|6237|6983793|False| | |False| |0|0|0| | |http://www.google.nl</Row><Row>1|yahoo.com|OK|Found|16814018765|8374570|16814018765|-1|1|3845667299|5000|1345597|266044|17992|24506182|10441|12766565|4284|5810404|1217|1338346|False| | |False| |0|0|0| | |http://pl.yahoo.com/?p=us</Row></DataTable></DataTables></Result>'
|
22
|
+
@parsed = ::Nokogiri::XML(@xml, nil, "utf-8")
|
23
|
+
@response = MajesticSeo::Api::ItemInfoResponse.new(@parsed)
|
24
|
+
@table = @response.tables["Results"]
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should be a valid response" do
|
28
|
+
@response.success.should == true
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should not have an error message" do
|
32
|
+
@response.error_message.should == ""
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should have global variables set" do
|
36
|
+
@response.global_variables["most_recent_back_link_date"].should == "2011-12-18"
|
37
|
+
@response.global_variables["index_type"].should == "0"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should have one returned data table" do
|
41
|
+
@response.tables.size.should == 1
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should have a data table with the name 'Results'" do
|
45
|
+
@table.should_not be_nil
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should have a data table with the name 'Results' containing 2 rows" do
|
49
|
+
@table.row_count.should == 2
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should have results for google.com" do
|
53
|
+
google_row = @response.items[0]
|
54
|
+
|
55
|
+
google_row.url.should == "google.com"
|
56
|
+
google_row.type.should == :root_domain
|
57
|
+
google_row.result_code.should == "OK"
|
58
|
+
google_row.success.should == true
|
59
|
+
google_row.status.should == "Found"
|
60
|
+
google_row.external_backlinks.should == 33536625553
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should have results for yahoo.com" do
|
64
|
+
yahoo_row = @response.items[1]
|
65
|
+
|
66
|
+
yahoo_row.url.should == "yahoo.com"
|
67
|
+
yahoo_row.type.should == :root_domain
|
68
|
+
yahoo_row.result_code.should == "OK"
|
69
|
+
yahoo_row.success.should == true
|
70
|
+
yahoo_row.status.should == "Found"
|
71
|
+
yahoo_row.indexed_urls.should == 3845667299
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
#Example XML:
|
77
|
+
#<?xml version="1.0" encoding="utf-8"?>
|
78
|
+
#<Result Code="OK" ErrorMessage="" FullError="">
|
79
|
+
# <GlobalVars FirstBackLinkDate="2006-06-06" IndexBuildDate="04/01/2012 09:14:02" IndexType="0" MostRecentBackLinkDate="2011-12-18" RecentBackLinksFromDate="2011-09-19" ServerBuild="2011-11-07 13:20:36" ServerName="PWRGURU" ServerVersion="1.0.4328.24018"/>
|
80
|
+
# <DataTables Count="1">
|
81
|
+
# <DataTable Name="Results" RowsCount="1" Headers="ItemNum|Item|ResultCode|Status|ExtBackLinks|RefDomains|AnalysisResUnitsCost|ACRank|ItemType|IndexedURLs|GetTopBackLinksAnalysisResUnitsCost|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">
|
82
|
+
# <Row>0|aftonbladet.se|OK|Found|54063780|128804|54063780|-1|1|5658886|5000|43589|23882|279|2396|35|179|120|496|4|13|False| | |False| |0|0|0| | Aftonbladet: Sveriges nyhetskälla och mötesplats |http://www.aftonbladet.se</Row>
|
83
|
+
# </DataTable>
|
84
|
+
# </DataTables>
|
85
|
+
#</Result>
|
86
|
+
|
87
|
+
describe "successful utf-8 response from MajesticSeo" do
|
88
|
+
before(:each) do
|
89
|
+
#We need to keep the XML on one line - JRuby goes bonanza otherwise
|
90
|
+
@xml = '<?xml version="1.0" encoding="utf-8"?><Result Code="OK" ErrorMessage="" FullError=""><GlobalVars FirstBackLinkDate="2006-06-06" IndexBuildDate="04/01/2012 09:14:02" IndexType="0" MostRecentBackLinkDate="2011-12-18" RecentBackLinksFromDate="2011-09-19" ServerBuild="2011-11-07 13:20:36" ServerName="PWRGURU" ServerVersion="1.0.4328.24018"/><DataTables Count="1"><DataTable Name="Results" RowsCount="1" Headers="ItemNum|Item|ResultCode|Status|ExtBackLinks|RefDomains|AnalysisResUnitsCost|ACRank|ItemType|IndexedURLs|GetTopBackLinksAnalysisResUnitsCost|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"><Row>0|aftonbladet.se|OK|Found|54063780|128804|54063780|-1|1|5658886|5000|43589|23882|279|2396|35|179|120|496|4|13|False| | |False| |0|0|0| | Aftonbladet: Sveriges nyhetskälla och mötesplats |http://www.aftonbladet.se</Row></DataTable></DataTables></Result>'
|
91
|
+
@parsed = ::Nokogiri::XML(@xml, nil, "utf-8")
|
92
|
+
@response = MajesticSeo::Api::ItemInfoResponse.new(@parsed)
|
93
|
+
@table = @response.tables["Results"]
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should be a valid response" do
|
97
|
+
@response.success.should == true
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should not have an error message" do
|
101
|
+
@response.error_message.should == ""
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should have global variables set" do
|
105
|
+
@response.global_variables["most_recent_back_link_date"].should == "2011-12-18"
|
106
|
+
@response.global_variables["index_type"].should == "0"
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should have one returned data table" do
|
110
|
+
@response.tables.size.should == 1
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should have a data table with the name 'Results'" do
|
114
|
+
@table.should_not be_nil
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should have a data table with the name 'Results' containing 2 rows" do
|
118
|
+
@table.row_count.should == 1
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should have results for aftonbladet.se" do
|
122
|
+
row = @response.items[0]
|
123
|
+
|
124
|
+
row.url.should == "aftonbladet.se"
|
125
|
+
row.title.should == "Aftonbladet: Sveriges nyhetskälla och mötesplats"
|
126
|
+
row.type.should == :root_domain
|
127
|
+
row.result_code.should == "OK"
|
128
|
+
row.success.should == true
|
129
|
+
row.status.should == "Found"
|
130
|
+
row.external_backlinks.should == 54063780
|
131
|
+
row.referring_domains.should == 128804
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe MajesticSeo::Api::TopBackLinksResponse do
|
4
|
+
|
5
|
+
describe "invalid response from MajesticSeo" do
|
6
|
+
before(:each) do
|
7
|
+
@xml = '<?xml version="1.0" encoding="utf-8"?><Result Code="FailedRequestViaAPI" ErrorMessage="API Key does not appear to be correct: API_KEY - 'api_key'" FullError="Majestic12.SearchIndexReportResponse+ResponseException: API Key does not appear to be correct: API_KEY - 'api_key' at Majestic12.SearchIndexReportManager.Authenticate(SearchIndexReportRequest oReq) in W:\VersionFiles\WorldSource\MJ12searchLib\SearchIndexReportManager.cs:line 2411 at Majestic12.SearchIndexReportManager.RunReport(SearchConfig oConfig, SearchIndex oSI, SearchIndexReportRequest oReq, Boolean bAvoidQueueing, SearchIndexReportResponse& oRes) in W:\VersionFiles\WorldSource\MJ12searchLib\SearchIndexReportManager.cs:line 2071"><GlobalVars/></Result>'
|
8
|
+
@parsed = ::Nokogiri::XML(@xml, nil, "utf-8")
|
9
|
+
@response = MajesticSeo::Api::TopBackLinksResponse.new(@parsed)
|
10
|
+
@table = @response.tables["URL"]
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should be an invalid response" do
|
14
|
+
@response.success.should == false
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have an error message" do
|
18
|
+
@response.error_message.should == "API Key does not appear to be correct: API_KEY - 'api_key'"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should have a stacktrace" do
|
22
|
+
@response.stacktrace.should_not == ""
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should have no data tables" do
|
26
|
+
@response.tables.size.should == 0
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
$LOAD_PATH << "." unless $LOAD_PATH.include?(".")
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "rubygems"
|
5
|
+
require "bundler"
|
6
|
+
|
7
|
+
if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.5")
|
8
|
+
raise RuntimeError, "Your bundler version is too old." +
|
9
|
+
"Run `gem install bundler` to upgrade."
|
10
|
+
end
|
11
|
+
|
12
|
+
# Set up load paths for all bundled gems
|
13
|
+
Bundler.setup
|
14
|
+
rescue Bundler::GemNotFound
|
15
|
+
raise RuntimeError, "Bundler couldn't find some gems." +
|
16
|
+
"Did you run \`bundlee install\`?"
|
17
|
+
end
|
18
|
+
|
19
|
+
#require "active_record"
|
20
|
+
Bundler.require
|
21
|
+
|
22
|
+
require File.expand_path('../../lib/majestic_seo_api', __FILE__)
|
23
|
+
|
24
|
+
RSpec.configure do |config|
|
25
|
+
config.mock_with :mocha
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: majestic_seo_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.3
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Majestic-12 Ltd
|
9
|
+
- Sebastian Johnsson
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-01-29 00:00:00.000000000Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: nokogiri
|
17
|
+
requirement: &70358841889560 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *70358841889560
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: faraday
|
28
|
+
requirement: &70358841889080 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.7.6
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *70358841889080
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: agiley-faraday_middleware
|
39
|
+
requirement: &70358841888600 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 0.8.3
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *70358841888600
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: jruby-openssl
|
50
|
+
requirement: &70358841888120 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0.7'
|
56
|
+
type: :runtime
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *70358841888120
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: bundler
|
61
|
+
requirement: &70358841887640 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *70358841887640
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: jeweler
|
72
|
+
requirement: &70358841887160 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *70358841887160
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rspec
|
83
|
+
requirement: &70358841886680 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: *70358841886680
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: mocha
|
94
|
+
requirement: &70358841886200 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
type: :development
|
101
|
+
prerelease: false
|
102
|
+
version_requirements: *70358841886200
|
103
|
+
description: Interface for communicating with Majestic SEO's API
|
104
|
+
email: sebastian@agiley.se
|
105
|
+
executables: []
|
106
|
+
extensions: []
|
107
|
+
extra_rdoc_files:
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.markdown
|
110
|
+
files:
|
111
|
+
- Gemfile
|
112
|
+
- LICENSE.txt
|
113
|
+
- README.markdown
|
114
|
+
- Rakefile
|
115
|
+
- VERSION
|
116
|
+
- lib/generators/majestic_seo/majestic_seo_generator.rb
|
117
|
+
- lib/generators/templates/majestic_seo.template.yml
|
118
|
+
- lib/majestic_seo/api/client.rb
|
119
|
+
- lib/majestic_seo/api/data_table.rb
|
120
|
+
- lib/majestic_seo/api/item_info.rb
|
121
|
+
- lib/majestic_seo/api/item_info_response.rb
|
122
|
+
- lib/majestic_seo/api/logger.rb
|
123
|
+
- lib/majestic_seo/api/response.rb
|
124
|
+
- lib/majestic_seo/api/top_back_links_response.rb
|
125
|
+
- lib/majestic_seo/extensions/string.rb
|
126
|
+
- lib/majestic_seo/railtie.rb
|
127
|
+
- lib/majestic_seo_api.rb
|
128
|
+
- majestic_seo_api.gemspec
|
129
|
+
- script/get_index_item_info.rb
|
130
|
+
- script/get_top_backlinks.rb
|
131
|
+
- script/open_app_get_index_item_info.rb
|
132
|
+
- spec/majestic_seo/client_spec.rb
|
133
|
+
- spec/majestic_seo/item_info_response_spec.rb
|
134
|
+
- spec/majestic_seo/top_back_links_response_spec.rb
|
135
|
+
- spec/spec_helper.rb
|
136
|
+
homepage: http://developer-support.majesticseo.com/connectors/
|
137
|
+
licenses: []
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
none: false
|
144
|
+
requirements:
|
145
|
+
- - ! '>='
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
+
none: false
|
150
|
+
requirements:
|
151
|
+
- - ! '>='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
requirements: []
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 1.8.15
|
157
|
+
signing_key:
|
158
|
+
specification_version: 3
|
159
|
+
summary: Interface for communicating with Majestic SEO's API
|
160
|
+
test_files: []
|