majestic_seo_api 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,113 @@
|
|
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
|
+
module MajesticSeo
|
34
|
+
module Api
|
35
|
+
class Response
|
36
|
+
attr_accessor :response, :tables, :table_key
|
37
|
+
attr_accessor :code, :error_message, :full_error
|
38
|
+
attr_accessor :global_variables, :success, :items
|
39
|
+
|
40
|
+
# This method returns a new instance of the Response class.
|
41
|
+
# If one of the parameters are not provided, it will default to nil.
|
42
|
+
def initialize(response = nil)
|
43
|
+
@response = response
|
44
|
+
@global_variables = {}
|
45
|
+
@tables = {}
|
46
|
+
@success = false
|
47
|
+
|
48
|
+
parse_response
|
49
|
+
end
|
50
|
+
|
51
|
+
def parse_response
|
52
|
+
if (@response.is_a?(Nokogiri::XML::Document))
|
53
|
+
@response = (@response && @response.root) ? @response.root : nil
|
54
|
+
elsif (@response.is_a?(Faraday::Response))
|
55
|
+
@response = (@response && @response.body && @response.body.root) ? @response.body.root : nil
|
56
|
+
end
|
57
|
+
|
58
|
+
if (@response)
|
59
|
+
@response.attributes.each do |key, attribute|
|
60
|
+
self.send("#{key.underscore}=", attribute.value)
|
61
|
+
end
|
62
|
+
|
63
|
+
@success = @code.downcase.eql?("ok")
|
64
|
+
|
65
|
+
if (success?)
|
66
|
+
parse_global_variables
|
67
|
+
parse_tables
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def success?
|
73
|
+
@success
|
74
|
+
end
|
75
|
+
|
76
|
+
def parse_global_variables
|
77
|
+
vars = @response.at_xpath("//GlobalVars")
|
78
|
+
|
79
|
+
vars.attributes.each do |key, attribute|
|
80
|
+
@global_variables[key.underscore] = attribute.value
|
81
|
+
end if (vars && vars.attributes.any?)
|
82
|
+
end
|
83
|
+
|
84
|
+
def stacktrace
|
85
|
+
@full_error
|
86
|
+
end
|
87
|
+
|
88
|
+
def items
|
89
|
+
if (@items.nil? || @items.empty?)
|
90
|
+
@items = (self.tables && self.tables.has_key?(self.table_key)) ? self.tables[self.table_key].rows : nil
|
91
|
+
end
|
92
|
+
|
93
|
+
return @items
|
94
|
+
end
|
95
|
+
|
96
|
+
def parse_tables
|
97
|
+
tables = @response.xpath("//DataTables/DataTable")
|
98
|
+
|
99
|
+
tables.each do |table|
|
100
|
+
parse_table(table)
|
101
|
+
end if (tables && tables.any?)
|
102
|
+
end
|
103
|
+
|
104
|
+
def parse_table(table)
|
105
|
+
parsed_table = MajesticSeo::Api::DataTable.new(table)
|
106
|
+
@tables[parsed_table.name] = parsed_table
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
@@ -0,0 +1,44 @@
|
|
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
|
+
module MajesticSeo
|
34
|
+
module Api
|
35
|
+
|
36
|
+
class TopBackLinksResponse < Response
|
37
|
+
def initialize(response, table_key = "URL")
|
38
|
+
@table_key = table_key
|
39
|
+
super(response)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module MajesticSeoApi
|
2
|
+
require File.join(File.dirname(__FILE__), 'majestic_seo/railtie') if defined?(Rails)
|
3
|
+
|
4
|
+
if (!String.instance_methods(false).include?(:underscore))
|
5
|
+
require File.join(File.dirname(__FILE__), 'majestic_seo/extensions/string')
|
6
|
+
end
|
7
|
+
|
8
|
+
require File.join(File.dirname(__FILE__), 'majestic_seo/api/logger')
|
9
|
+
|
10
|
+
require File.join(File.dirname(__FILE__), 'majestic_seo/api/response')
|
11
|
+
require File.join(File.dirname(__FILE__), 'majestic_seo/api/item_info_response')
|
12
|
+
require File.join(File.dirname(__FILE__), 'majestic_seo/api/top_back_links_response')
|
13
|
+
require File.join(File.dirname(__FILE__), 'majestic_seo/api/data_table')
|
14
|
+
require File.join(File.dirname(__FILE__), 'majestic_seo/api/item_info')
|
15
|
+
require File.join(File.dirname(__FILE__), 'majestic_seo/api/client')
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "majestic_seo_api"
|
8
|
+
s.version = "0.9.3"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Majestic-12 Ltd", "Sebastian Johnsson"]
|
12
|
+
s.date = "2012-01-29"
|
13
|
+
s.description = "Interface for communicating with Majestic SEO's API"
|
14
|
+
s.email = "sebastian@agiley.se"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
"Gemfile",
|
21
|
+
"LICENSE.txt",
|
22
|
+
"README.markdown",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"lib/generators/majestic_seo/majestic_seo_generator.rb",
|
26
|
+
"lib/generators/templates/majestic_seo.template.yml",
|
27
|
+
"lib/majestic_seo/api/client.rb",
|
28
|
+
"lib/majestic_seo/api/data_table.rb",
|
29
|
+
"lib/majestic_seo/api/item_info.rb",
|
30
|
+
"lib/majestic_seo/api/item_info_response.rb",
|
31
|
+
"lib/majestic_seo/api/logger.rb",
|
32
|
+
"lib/majestic_seo/api/response.rb",
|
33
|
+
"lib/majestic_seo/api/top_back_links_response.rb",
|
34
|
+
"lib/majestic_seo/extensions/string.rb",
|
35
|
+
"lib/majestic_seo/railtie.rb",
|
36
|
+
"lib/majestic_seo_api.rb",
|
37
|
+
"majestic_seo_api.gemspec",
|
38
|
+
"script/get_index_item_info.rb",
|
39
|
+
"script/get_top_backlinks.rb",
|
40
|
+
"script/open_app_get_index_item_info.rb",
|
41
|
+
"spec/majestic_seo/client_spec.rb",
|
42
|
+
"spec/majestic_seo/item_info_response_spec.rb",
|
43
|
+
"spec/majestic_seo/top_back_links_response_spec.rb",
|
44
|
+
"spec/spec_helper.rb"
|
45
|
+
]
|
46
|
+
s.homepage = "http://developer-support.majesticseo.com/connectors/"
|
47
|
+
s.require_paths = ["lib"]
|
48
|
+
s.rubygems_version = "1.8.15"
|
49
|
+
s.summary = "Interface for communicating with Majestic SEO's API"
|
50
|
+
|
51
|
+
if s.respond_to? :specification_version then
|
52
|
+
s.specification_version = 3
|
53
|
+
|
54
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
55
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
56
|
+
s.add_runtime_dependency(%q<faraday>, ["~> 0.7.6"])
|
57
|
+
s.add_runtime_dependency(%q<agiley-faraday_middleware>, ["~> 0.8.3"])
|
58
|
+
s.add_runtime_dependency(%q<jruby-openssl>, ["~> 0.7"])
|
59
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
60
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
61
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
62
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
65
|
+
s.add_dependency(%q<faraday>, ["~> 0.7.6"])
|
66
|
+
s.add_dependency(%q<agiley-faraday_middleware>, ["~> 0.8.3"])
|
67
|
+
s.add_dependency(%q<jruby-openssl>, ["~> 0.7"])
|
68
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
69
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
70
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
71
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
72
|
+
end
|
73
|
+
else
|
74
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
75
|
+
s.add_dependency(%q<faraday>, ["~> 0.7.6"])
|
76
|
+
s.add_dependency(%q<agiley-faraday_middleware>, ["~> 0.8.3"])
|
77
|
+
s.add_dependency(%q<jruby-openssl>, ["~> 0.7"])
|
78
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
79
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
80
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
81
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
@@ -0,0 +1,137 @@
|
|
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 majestic seo api library to the search path
|
40
|
+
Bundler.require if defined?(Bundler)
|
41
|
+
require File.expand_path('../../lib/majestic_seo_api', __FILE__)
|
42
|
+
|
43
|
+
environment = :production
|
44
|
+
|
45
|
+
puts "\n****************************************************************************"
|
46
|
+
|
47
|
+
puts "\nEnvironment: #{environment}"
|
48
|
+
|
49
|
+
if (environment.eql?(:production))
|
50
|
+
puts "\nThis program is hard-wired to the Enterprise API."
|
51
|
+
|
52
|
+
puts "\nIf you do not have access to the Enterprise API, " +
|
53
|
+
"change the environment to: \n:sandbox."
|
54
|
+
elsif (environment.eql?(:sandbox))
|
55
|
+
puts "\nThis program is hard-wired to the Developer API " +
|
56
|
+
"and hence the subset of data \nreturned will be substantially " +
|
57
|
+
"smaller than that which will be returned from \neither the " +
|
58
|
+
"Enterprise API or the Majestic SEO website."
|
59
|
+
|
60
|
+
puts "\nTo make this program use the Enterprise API, change " +
|
61
|
+
"the environment to: \n:production."
|
62
|
+
end
|
63
|
+
|
64
|
+
puts "\n***********************************************************" +
|
65
|
+
"*****************";
|
66
|
+
|
67
|
+
puts "\n\nThis example program will return key information about \"index items\"." +
|
68
|
+
"\n\nThe following must be provided in order to run this program: " +
|
69
|
+
"\n1. API key \n2. List of items to query" +
|
70
|
+
"\n\nPlease enter your API key:\n"
|
71
|
+
|
72
|
+
api_key = gets.chomp
|
73
|
+
|
74
|
+
puts "\nPlease enter the list of items you wish to query seperated by " +
|
75
|
+
"commas: \n(e.g. majesticseo.com, majestic12.co.uk)\n"
|
76
|
+
|
77
|
+
items_to_query = gets.chomp
|
78
|
+
items = items_to_query.split(/,\s?/)
|
79
|
+
|
80
|
+
client = MajesticSeo::Api::Client.new(api_key, environment)
|
81
|
+
response = client.get_index_item_info(items, {:data_source => :fresh, :timeout => 5})
|
82
|
+
|
83
|
+
if (response && response.success)
|
84
|
+
response.items.each_with_index do |item, index|
|
85
|
+
puts "\n Result: #{index+1}: \n"
|
86
|
+
|
87
|
+
instance_variables = item.instance_variables
|
88
|
+
instance_variables.delete(:@response)
|
89
|
+
instance_variables.delete(:@mappings)
|
90
|
+
|
91
|
+
instance_variables.each do |var|
|
92
|
+
puts " #{var.to_s.gsub("@", "")} ... #{item.instance_variable_get(var)}"
|
93
|
+
end
|
94
|
+
|
95
|
+
puts "\n"
|
96
|
+
end if (response.items && response.items.any?)
|
97
|
+
|
98
|
+
if (environment.eql?(:sandbox))
|
99
|
+
puts "\n\n***********************************************************" +
|
100
|
+
"*****************"
|
101
|
+
|
102
|
+
puts "\nEnvironment: #{environment}"
|
103
|
+
|
104
|
+
puts"\nThis program is hard-wired to the Developer API " +
|
105
|
+
"and hence the subset of data \nreturned will be substantially " +
|
106
|
+
"smaller than that which will be returned from \neither the " +
|
107
|
+
"Enterprise API or the Majestic SEO website."
|
108
|
+
|
109
|
+
puts "\nTo make this program use the Enterprise API, change " +
|
110
|
+
"the environment to: \n:production."
|
111
|
+
|
112
|
+
puts "\n***********************************************************" +
|
113
|
+
"*****************"
|
114
|
+
end
|
115
|
+
|
116
|
+
else
|
117
|
+
puts "\nERROR MESSAGE:"
|
118
|
+
puts response.error_message
|
119
|
+
|
120
|
+
puts "\n\n***********************************************************" +
|
121
|
+
"*****************"
|
122
|
+
|
123
|
+
puts "\nDebugging Info:"
|
124
|
+
puts "\n Environment: \t#{environment}"
|
125
|
+
puts " API Key: \t#{api_key}"
|
126
|
+
|
127
|
+
if(environment.eql?(:production))
|
128
|
+
puts "\n Is this API Key valid for this Endpoint?"
|
129
|
+
|
130
|
+
puts "\n This program is hard-wired to the Enterprise API."
|
131
|
+
|
132
|
+
puts "\n If you do not have access to the Enterprise API, " +
|
133
|
+
"change the environment to: \n :sandbox."
|
134
|
+
end
|
135
|
+
|
136
|
+
puts "\n****************************************************************************"
|
137
|
+
end
|
@@ -0,0 +1,140 @@
|
|
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 GetTopBackLinks 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 the top backlinks for any URL, domain " +
|
70
|
+
"\nor subdomain." +
|
71
|
+
"\n\nThe following must be provided in order to run this program: " +
|
72
|
+
"\n1. API key, \n2. A URL, domain or subdomain to query" +
|
73
|
+
"\n\nPlease enter your API key:\n";
|
74
|
+
|
75
|
+
api_key = gets.chomp;
|
76
|
+
|
77
|
+
puts "\nPlease enter a URL, domain or subdomain to query:\n";
|
78
|
+
|
79
|
+
item_to_query = gets.chomp;
|
80
|
+
|
81
|
+
# set up parameters
|
82
|
+
parameters = Hash.new;
|
83
|
+
parameters["MaxSourceURLs"] = "10";
|
84
|
+
parameters["URL"] = item_to_query;
|
85
|
+
parameters["GetUrlData"] = "1";
|
86
|
+
parameters["MaxSourceURLsPerRefDomain"] = "1";
|
87
|
+
parameters["datasource"] = "fresh";
|
88
|
+
|
89
|
+
api_service = ApiService.new(api_key, endpoint);
|
90
|
+
response = api_service.execute_command('GetTopBackLinks', parameters);
|
91
|
+
|
92
|
+
# check the response code
|
93
|
+
if(response.is_ok)
|
94
|
+
# print the URL table
|
95
|
+
results = response.table_for_name('URL');
|
96
|
+
results.rows.each do |row|
|
97
|
+
puts "\nURL: " + row['SourceURL']
|
98
|
+
puts "ACRank: " + row['ACRank']
|
99
|
+
end
|
100
|
+
|
101
|
+
if("http://developer.majesticseo.com/api_command" == endpoint)
|
102
|
+
puts "\n\n***********************************************************" +
|
103
|
+
"*****************";
|
104
|
+
|
105
|
+
puts "\nEndpoint: #{endpoint}";
|
106
|
+
|
107
|
+
puts"\nThis program is hard-wired to the Developer API " +
|
108
|
+
"and hence the subset of data \nreturned will be substantially " +
|
109
|
+
"smaller than that which will be returned from \neither the " +
|
110
|
+
"Enterprise API or the Majestic SEO website.";
|
111
|
+
|
112
|
+
puts "\nTo make this program use the Enterprise API, change " +
|
113
|
+
"the endpoint to: \nhttp://enterprise.majesticseo.com/api_command.";
|
114
|
+
|
115
|
+
puts "\n***********************************************************" +
|
116
|
+
"*****************";
|
117
|
+
end
|
118
|
+
else
|
119
|
+
puts "\nERROR MESSAGE:";
|
120
|
+
puts response.error_message;
|
121
|
+
|
122
|
+
puts "\n\n***********************************************************" +
|
123
|
+
"*****************";
|
124
|
+
|
125
|
+
puts "\nDebugging Info:";
|
126
|
+
puts "\n Endpoint: \t#{endpoint}";
|
127
|
+
puts " API Key: \t#{api_key}";
|
128
|
+
|
129
|
+
if("http://enterprise.majesticseo.com/api_command" == endpoint)
|
130
|
+
puts "\n Is this API Key valid for this Endpoint?";
|
131
|
+
|
132
|
+
puts "\n This program is hard-wired to the Enterprise API.";
|
133
|
+
|
134
|
+
puts "\n If you do not have access to the Enterprise API, " +
|
135
|
+
"change the endpoint to: \n http://developer.majesticseo.com/api_command.";
|
136
|
+
end
|
137
|
+
|
138
|
+
puts "\n***********************************************************" +
|
139
|
+
"*****************";
|
140
|
+
end
|