majesticseo 1.0.1
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/History.txt +6 -0
- data/Manifest.txt +13 -0
- data/PostInstall.txt +4 -0
- data/README.rdoc +57 -0
- data/Rakefile +17 -0
- data/lib/majesticseo.rb +51 -0
- data/lib/majesticseo/client.rb +72 -0
- data/lib/majesticseo/data_table.rb +31 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/test/test_helper.rb +3 -0
- data/test/test_majesticseo.rb +15 -0
- metadata +147 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
PostInstall.txt
|
4
|
+
README.rdoc
|
5
|
+
Rakefile
|
6
|
+
lib/majesticseo.rb
|
7
|
+
lib/majesticseo/client.rb
|
8
|
+
lib/majesticseo/data_table.rb
|
9
|
+
script/console
|
10
|
+
script/destroy
|
11
|
+
script/generate
|
12
|
+
test/test_helper.rb
|
13
|
+
test/test_majesticseo.rb
|
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
= majesticseo
|
2
|
+
|
3
|
+
* http://github.com/Achillefs/majesticseo
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
A ruby-friendly interface to the Majestic SEO API.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* Data structures are returned as ruby objects. Majestic SEO responses are parsed into corresponding objects, allowing developers to access them as they would access any ruby object.
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
maj = Majesticseo::Client.new(:app_api_key => "BLAH")
|
16
|
+
maj.get_subscription_info
|
17
|
+
# GlobalVars works as an array or object
|
18
|
+
if maj.success?
|
19
|
+
puts maj.global_vars.max_bulk_backlinks_check
|
20
|
+
else
|
21
|
+
puts maj.response
|
22
|
+
puts maj.error_message
|
23
|
+
end
|
24
|
+
|
25
|
+
== REQUIREMENTS:
|
26
|
+
|
27
|
+
* activesupport >= 2.0.2
|
28
|
+
* nokogiri >= 1.4.0
|
29
|
+
|
30
|
+
== INSTALL:
|
31
|
+
|
32
|
+
* sudo gem install majesticseo --no-ri --no-rdoc
|
33
|
+
|
34
|
+
== LICENSE:
|
35
|
+
|
36
|
+
(The MIT License)
|
37
|
+
|
38
|
+
Copyright (c) 2011 Achilles Charmpilas, Humbucker Ltd
|
39
|
+
|
40
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
41
|
+
a copy of this software and associated documentation files (the
|
42
|
+
'Software'), to deal in the Software without restriction, including
|
43
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
44
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
45
|
+
permit persons to whom the Software is furnished to do so, subject to
|
46
|
+
the following conditions:
|
47
|
+
|
48
|
+
The above copyright notice and this permission notice shall be
|
49
|
+
included in all copies or substantial portions of the Software.
|
50
|
+
|
51
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
52
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
53
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
54
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
55
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
56
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
57
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'hoe', '>= 2.1.0'
|
3
|
+
require 'hoe'
|
4
|
+
require 'fileutils'
|
5
|
+
require './lib/majesticseo'
|
6
|
+
|
7
|
+
Hoe.plugin :newgem
|
8
|
+
$hoe = Hoe.spec 'majesticseo' do
|
9
|
+
self.developer 'Achilles Charmpilas', 'ac@humbuckercode.co.uk'
|
10
|
+
self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
11
|
+
self.rubyforge_name = self.name # TODO this is default value
|
12
|
+
self.extra_deps = [['activesupport','>= 2.0.2'], ['nokogiri','>= 1.4.0']]
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
require 'newgem/tasks'
|
17
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
data/lib/majesticseo.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
=begin rdoc
|
5
|
+
This module implements a ruby-friendly interface to the Majestic SEO developer API.
|
6
|
+
=end
|
7
|
+
require "active_support"
|
8
|
+
require "nokogiri"
|
9
|
+
require "open-uri"
|
10
|
+
require "ostruct"
|
11
|
+
|
12
|
+
module Majesticseo
|
13
|
+
VERSION = '1.0.1'
|
14
|
+
class NoMethodError < ArgumentError; end
|
15
|
+
class InvalidAPIKey < ArgumentError; end
|
16
|
+
=begin rdoc
|
17
|
+
Very simple ostruct-based data struct
|
18
|
+
=end
|
19
|
+
class Structure < OpenStruct
|
20
|
+
def [] key
|
21
|
+
send(key.underscore)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
=begin rdoc
|
26
|
+
Structure respresenting one data row. Can be accessed either as a Ruby object, or as an array.
|
27
|
+
Object methods are underscored versions of the actual array element keys.
|
28
|
+
=Example
|
29
|
+
maj = Majesticseo::Client.new(:app_api_key => "APPKEYHASH")
|
30
|
+
maj.get_subscription_info
|
31
|
+
puts maj.data_tables.first.rows.first["IndexItemInfoResUnits"]
|
32
|
+
=> 99992
|
33
|
+
puts maj.data_tables.first.rows.first.index_item_info_res_units
|
34
|
+
=> 99992
|
35
|
+
=end
|
36
|
+
class Row < Majesticseo::Structure; end
|
37
|
+
|
38
|
+
=begin rdoc
|
39
|
+
Structure respresenting a response global vers element. Can be accessed either as a Ruby object, or as an array.
|
40
|
+
Object methods are underscored versions of the actual array element keys.
|
41
|
+
=Example
|
42
|
+
maj = Majesticseo::Client.new(:app_api_key => "APPKEYHASH")
|
43
|
+
maj.get_subscription_info
|
44
|
+
puts maj.global_vars["MaxBulkBacklinksCheck"]
|
45
|
+
=> 120
|
46
|
+
puts maj.global_vars.max_bulk_backlinks_check
|
47
|
+
=> 120
|
48
|
+
=end
|
49
|
+
class GlobalVars < Majesticseo::Structure; end
|
50
|
+
end
|
51
|
+
%W[data_table client].each { |r| require "#{File.dirname(__FILE__)}/majesticseo/#{r}" }
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Majesticseo
|
2
|
+
=begin rdoc
|
3
|
+
Please refer to the Majesticseo developer documentation for information regarding API methods: http://developer-support.Majesticseo.com/
|
4
|
+
|
5
|
+
=Example
|
6
|
+
maj = Majesticseo::Client.new(:app_api_key => "BLAH")
|
7
|
+
maj.get_subscription_info
|
8
|
+
if maj.success?
|
9
|
+
puts maj.global_vars.max_bulk_backlinks_check
|
10
|
+
=> 120
|
11
|
+
puts maj.data_tables.first.rows.first.index_item_info_res_units
|
12
|
+
=> 99992
|
13
|
+
else
|
14
|
+
puts maj.response
|
15
|
+
puts maj.error_message
|
16
|
+
end
|
17
|
+
=end
|
18
|
+
class Client
|
19
|
+
attr_reader :app_api_key, :env, :uri, :response
|
20
|
+
attr_accessor :code, :error_message, :full_error, :data_tables, :global_vars
|
21
|
+
=begin rdoc
|
22
|
+
Initialize a Majestic SEO aPI client passing the following options:
|
23
|
+
app_api_key: You Majesticseo API key, found at: https://www.Majesticseo.com/account/api
|
24
|
+
enviroment (optional): Default to RAILS_ENV, RACK_ENV or default. Determines whether the client uses the sandbox or production API server
|
25
|
+
=end
|
26
|
+
def initialize(opts = {})
|
27
|
+
@app_api_key = opts.delete(:app_api_key)
|
28
|
+
|
29
|
+
raise Majesticseo::InvalidAPIKey.new("API key needs to be a valid Majestic SEO API key. See: https://www.Majesticseo.com/account/api") if @app_api_key.blank?
|
30
|
+
|
31
|
+
if opts[:enviroment]
|
32
|
+
@env = opts.delete(:enviroment)
|
33
|
+
elsif defined?(RAILS_ENV)
|
34
|
+
@env = RAILS_ENV
|
35
|
+
elsif defined?(RACK_ENV)
|
36
|
+
@env = RACK_ENV
|
37
|
+
else
|
38
|
+
@env = "development"
|
39
|
+
end
|
40
|
+
@response = nil
|
41
|
+
@data_tables = []
|
42
|
+
@global_vars = nil
|
43
|
+
@uri = URI.parse("http://#{@env == "production" ? "enterprise" : "developer"}.Majesticseo.com/api_command")
|
44
|
+
puts "Started Majesticseo::Client in #{env} mode"
|
45
|
+
end
|
46
|
+
|
47
|
+
def call method, params
|
48
|
+
params = {} unless params.is_a? Hash
|
49
|
+
request_uri = uri.clone
|
50
|
+
request_uri.query = params.merge({:app_api_key => app_api_key, :cmd => method}).to_param
|
51
|
+
@response = Nokogiri::XML(open(request_uri))
|
52
|
+
|
53
|
+
# Set response and global variable attributes
|
54
|
+
response.at("Result").keys.each { |a| send("#{a.underscore}=".to_sym,response.at("Result").attr(a)) } if response.at("Result")
|
55
|
+
@global_vars = GlobalVars.new
|
56
|
+
response.at("GlobalVars").keys.each { |a| @global_vars.send("#{a.underscore}=".to_sym,response.at("GlobalVars").attr(a)) } if response.at("GlobalVars")
|
57
|
+
parse_data if success?
|
58
|
+
end
|
59
|
+
|
60
|
+
def method_missing(m, *args)
|
61
|
+
call(m.to_s.camelize, args[0])
|
62
|
+
end
|
63
|
+
|
64
|
+
def parse_data
|
65
|
+
@data_tables = @response.search("DataTable").collect { |table| DataTable.create_from_xml(table) }
|
66
|
+
end
|
67
|
+
|
68
|
+
def success?
|
69
|
+
code == "OK" and error_message == ""
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Majesticseo
|
2
|
+
class DataTable
|
3
|
+
attr_accessor :name, :rows, :rows_count
|
4
|
+
|
5
|
+
def self.create_from_xml xml
|
6
|
+
table = DataTable.new
|
7
|
+
table.headers = xml.attr("Headers")
|
8
|
+
table.name = xml.attr("Name")
|
9
|
+
table.rows_count = xml.attr("RowsCount").to_i
|
10
|
+
table.rows = xml.search("Row").map do |r|
|
11
|
+
row = Row.new
|
12
|
+
data = r.content.split("|")
|
13
|
+
table.headers.each_index { |i| row.send("#{table.headers[i].underscore}=",data[i])}
|
14
|
+
row
|
15
|
+
end
|
16
|
+
table
|
17
|
+
end
|
18
|
+
|
19
|
+
def headers= headers
|
20
|
+
if headers.is_a? String
|
21
|
+
@headers = headers.split("|")
|
22
|
+
else
|
23
|
+
@headers = headers
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def headers
|
28
|
+
@headers ? @headers : []
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/majesticseo.rb'}"
|
9
|
+
puts "Loading majesticseo gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestMajesticseo < Test::Unit::TestCase
|
4
|
+
def test_cannot_initialize_client_without_api_key
|
5
|
+
assert_raise Majesticseo::InvalidAPIKey do
|
6
|
+
Majesticseo::Client.new
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_cannot_initialize_client_with_empty_api_key
|
11
|
+
assert_raise Majesticseo::InvalidAPIKey do
|
12
|
+
Majesticseo::Client.new(:app_api_key => "")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: majesticseo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Achilles Charmpilas
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-09 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: activesupport
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 11
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 0
|
33
|
+
- 2
|
34
|
+
version: 2.0.2
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: nokogiri
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 7
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 4
|
49
|
+
- 0
|
50
|
+
version: 1.4.0
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rubyforge
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 7
|
62
|
+
segments:
|
63
|
+
- 2
|
64
|
+
- 0
|
65
|
+
- 4
|
66
|
+
version: 2.0.4
|
67
|
+
type: :development
|
68
|
+
version_requirements: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: hoe
|
71
|
+
prerelease: false
|
72
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 19
|
78
|
+
segments:
|
79
|
+
- 2
|
80
|
+
- 6
|
81
|
+
- 2
|
82
|
+
version: 2.6.2
|
83
|
+
type: :development
|
84
|
+
version_requirements: *id004
|
85
|
+
description: A ruby-friendly interface to the Majestic SEO API.
|
86
|
+
email:
|
87
|
+
- ac@humbuckercode.co.uk
|
88
|
+
executables: []
|
89
|
+
|
90
|
+
extensions: []
|
91
|
+
|
92
|
+
extra_rdoc_files:
|
93
|
+
- History.txt
|
94
|
+
- Manifest.txt
|
95
|
+
- PostInstall.txt
|
96
|
+
files:
|
97
|
+
- History.txt
|
98
|
+
- Manifest.txt
|
99
|
+
- PostInstall.txt
|
100
|
+
- README.rdoc
|
101
|
+
- Rakefile
|
102
|
+
- lib/majesticseo.rb
|
103
|
+
- lib/majesticseo/client.rb
|
104
|
+
- lib/majesticseo/data_table.rb
|
105
|
+
- script/console
|
106
|
+
- script/destroy
|
107
|
+
- script/generate
|
108
|
+
- test/test_helper.rb
|
109
|
+
- test/test_majesticseo.rb
|
110
|
+
has_rdoc: true
|
111
|
+
homepage: http://github.com/Achillefs/majesticseo
|
112
|
+
licenses: []
|
113
|
+
|
114
|
+
post_install_message: PostInstall.txt
|
115
|
+
rdoc_options:
|
116
|
+
- --main
|
117
|
+
- README.rdoc
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
hash: 3
|
126
|
+
segments:
|
127
|
+
- 0
|
128
|
+
version: "0"
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
hash: 3
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
version: "0"
|
138
|
+
requirements: []
|
139
|
+
|
140
|
+
rubyforge_project: majesticseo
|
141
|
+
rubygems_version: 1.4.2
|
142
|
+
signing_key:
|
143
|
+
specification_version: 3
|
144
|
+
summary: A ruby-friendly interface to the Majestic SEO API.
|
145
|
+
test_files:
|
146
|
+
- test/test_helper.rb
|
147
|
+
- test/test_majesticseo.rb
|