majestic_seo_api 1.3.1 → 1.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 342c0fdbf0d19ed7d9661d5b1ca52c60520a4ef1
4
- data.tar.gz: 74fad8728d5513457dac6994d89d533c5bc2bc6e
3
+ metadata.gz: 6291d530263ba1b47a87071630df73b58892bd73
4
+ data.tar.gz: 939767ba9245473fe9b7815b327f5832e259f961
5
5
  SHA512:
6
- metadata.gz: 31411ee8fc70389765a348df20f97b60909dcc6f5819827ef1bf4a92b4e36b2dec5151b7e248e417f0a5823a6231900d592b869d55aac2fc328427846084c577
7
- data.tar.gz: ff049c7d3533446d7c80113ce613672cc8d357119d5f0fd09fce5489703b03a3edfbc2aae249990f7c53dfc028744f767924f5a19b001623cb267d04efb36ac1
6
+ metadata.gz: 77b3d1b2ccdb47f58de18a91742ea21147bf6478d42902484ea4d2edaa57ddfdc11b72e10b916c8ffa105601d18fa5ac9462cb68d631aa3d632fb7deafb53a0a
7
+ data.tar.gz: 0b3c130fb3841a133c3794685868820c09284d46c7c360783eec1c7b34cecc55cda353118e6a66f863c86809f94cb567dc067c580bfded412f9b797b7de43fa8
@@ -0,0 +1,38 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## RUBYMINE
17
+ .idea
18
+
19
+ ## PROJECT::GENERAL
20
+ coverage
21
+ rdoc
22
+ pkg/*
23
+
24
+ ## BUNDLER
25
+ *.gem
26
+ .bundle
27
+ doc
28
+ log
29
+ Gemfile.lock
30
+ .rvmrc
31
+ .rbenv*
32
+
33
+ ## PROJECT::SPECIFIC
34
+ .rbx
35
+
36
+ ## PROJECT::SPECIFIC
37
+ lib/generators/templates/majestic_seo.yml
38
+ spec/support/majestic_seo.yml
@@ -0,0 +1 @@
1
+ 2.4.2
data/Gemfile CHANGED
@@ -1,8 +1,6 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
- platforms :jruby do
4
- gem "jruby-openssl", ">= 0.9"
5
- end
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
6
4
 
5
+ # Specify your gem's dependencies in scrapely.gemspec
7
6
  gemspec
8
-
@@ -1,50 +1,21 @@
1
-
2
- Version 0.9.3
3
-
4
- Copyright (c) 2011, Majestic-12 Ltd
5
-
6
- All rights reserved.
7
-
8
-
9
-
10
- Redistribution and use in source and binary forms, with or without
11
-
12
- modification, are permitted provided that the following conditions are met:
13
-
14
- * Redistributions of source code must retain the above copyright
15
-
16
- notice, this list of conditions and the following disclaimer.
17
-
18
- * Redistributions in binary form must reproduce the above copyright
19
-
20
- notice, this list of conditions and the following disclaimer in the
21
-
22
- documentation and/or other materials provided with the distribution.
23
-
24
- * Neither the name of the Majestic-12 Ltd nor the
25
-
26
- names of its contributors may be used to endorse or promote products
27
-
28
- derived from this software without specific prior written permission.
29
-
30
-
31
-
32
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
33
-
34
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
35
-
36
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37
-
38
- DISCLAIMED. IN NO EVENT SHALL Majestic-12 Ltd BE LIABLE FOR ANY
39
-
40
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
41
-
42
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43
-
44
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45
-
46
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
47
-
48
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
49
-
50
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Sebastian
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -1,74 +1,19 @@
1
- # Majestic SEO Ruby API Client #
1
+ # Majestic Ruby API Client #
2
2
 
3
- **This is currently under heavy development (first released 2012-01-27). Get back to me if you run into any bugs.**
4
-
5
- This is a Ruby Api client/wrapper/connector intended to be used with [Majestic SEO's awesome API](http://developer-support.majesticseo.com/).
6
-
7
- Majestic SEO currently offers a client/connector over at [Connector Downloads](http://developer-support.majesticseo.com/connectors/downloads/) but this connector wasn't suitable for me because:
8
-
9
- * It wasn't gemified (thus requiring a bunch of hacking to incorporate it into every respective Rails-app)
10
- * Didn't have a config file with environment specific client settings (api key, api environment). I need to be able to use different api environments depending on the app environment
11
- * **Didn't work with JRuby** - this gem does (or well - on 1.6.6-head and 1.7-head).
12
- * Lacked test/spec coverage. The current test coverage isn't the best, but it's still better than nothing.
13
-
14
- It is based on the Majestic SEO connector but has pretty much been rewritten from scratch.
15
-
16
- The original script/test-files included now reside in script/. All of them haven't been completely upgraded yet, but they will be upgraded eventually.
3
+ Client intended to be used with [Majestic's API](http://developer-support.majesticseo.com/).
17
4
 
18
5
  ## Installation ##
19
6
  ```
20
7
  gem install majestic_seo_api
21
8
  ```
22
9
 
23
- Using Gemfile:
24
-
10
+ ## Configuration ##
25
11
  ```
26
- gem "faraday_middleware", :git => 'git://github.com/Agiley/faraday_middleware.git'
27
- gem "majestic_seo_api"
12
+ MajesticSeoApi.configure do |config|
13
+ config.environment = :production # The environment to use, valid values: :sandbox, :production
14
+ config.api_key = 'api_key' # Your API key provided by Majestic
15
+ config.verbose = false # Set to true to enable Faraday's logging middleware to get more information
16
+ end
28
17
  ```
29
18
 
30
- Generate config file:
31
-
32
- ```
33
- rails generate majestic_seo
34
- ```
35
-
36
- ## Tested on ##
37
- The specs pass on:
38
-
39
- * Ruby 1.9.2
40
- * Ruby 1.9.3
41
- * JRuby 1.6.6-head
42
- * JRuby 1.7-head
43
-
44
- *JRuby 1.6.5/1.6.5.1 does not work :(*
45
-
46
- ## License ##
47
- Original Majestic SEO License:
48
-
49
- ---------
50
-
51
- Copyright (c) 2011, Majestic-12 Ltd
52
-
53
- All rights reserved.
54
-
55
- Redistribution and use in source and binary forms, with or without
56
- modification, are permitted provided that the following conditions are met:
57
-
58
- * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
59
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
60
- * Neither the name of the Majestic-12 Ltd nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
61
-
62
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
63
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
64
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
65
- DISCLAIMED. IN NO EVENT SHALL Majestic-12 Ltd BE LIABLE FOR ANY
66
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
67
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
68
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
69
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
70
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
71
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
72
-
73
- ---------
74
-
19
+ If you're using Rails, create an initializer in config/initializers/majestic.rb to configure the client globally in your app.
data/Rakefile CHANGED
@@ -1,87 +1,6 @@
1
- ## helper functions
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
2
3
 
3
- def name
4
- @name ||= Dir['*.gemspec'].first.split('.').first
5
- end
6
-
7
- def version
8
- line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
9
- line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
10
- end
11
-
12
- def gemspec_file
13
- "#{name}.gemspec"
14
- end
15
-
16
- def gem_file
17
- "#{name}-#{version}.gem"
18
- end
19
-
20
- def replace_header(head, header_name)
21
- head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
22
- end
23
-
24
- begin
25
- # Rspec 2.0
26
- require 'rspec/core/rake_task'
27
-
28
- desc 'Default: run specs'
29
- task :default => :spec
30
- RSpec::Core::RakeTask.new do |t|
31
- t.pattern = "spec/**/*_spec.rb"
32
- end
33
-
34
- RSpec::Core::RakeTask.new('rcov') do |t|
35
- t.pattern = "spec/**/*_spec.rb"
36
- t.rcov = true
37
- t.rcov_opts = ['--exclude', 'spec']
38
- end
39
-
40
- rescue LoadError
41
- puts "Rspec not available. Install it with: gem install rspec"
42
- end
43
-
44
- ## release management tasks
45
-
46
- desc "Commit, create tag v#{version} and build and push #{gem_file} to Rubygems"
47
- task :release => :build do
48
- sh "git commit --allow-empty -a -m 'Release #{version}'"
49
- sh "git tag v#{version}"
50
- sh "git push"
51
- sh "git push origin v#{version}"
52
- sh "gem push pkg/#{gem_file}"
53
- end
54
-
55
- desc "Build #{gem_file} into the pkg directory"
56
- task :build => :gemspec do
57
- sh "mkdir -p pkg"
58
- sh "gem build #{gemspec_file}"
59
- sh "mv #{gem_file} pkg"
60
- end
61
-
62
- desc "Generate #{gemspec_file}"
63
- task :gemspec do
64
- # read spec file and split out manifest section
65
- spec = File.read(gemspec_file)
66
- head, manifest, tail = spec.split(" # = MANIFEST =\n")
67
-
68
- # replace name version and date
69
- replace_header(head, :name)
70
- replace_header(head, :version)
71
-
72
- # determine file list from git ls-files
73
- files = `git ls-files`.
74
- split("\n").
75
- sort.
76
- reject { |file| file =~ /^\./ }.
77
- reject { |file| file =~ /^(rdoc|pkg)/ }.
78
- map { |file| " #{file}" }.
79
- join("\n")
80
-
81
- # piece file back together and write
82
- manifest = " s.files = %w[\n#{files}\n ]\n"
83
- spec = [head, manifest, tail].join(" # = MANIFEST =\n")
84
- File.open(gemspec_file, 'w') { |io| io.write(spec) }
85
- puts "Updated #{gemspec_file}"
86
- end
4
+ RSpec::Core::RakeTask.new(:spec)
87
5
 
6
+ task :default => :spec
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "majestic_seo_api"
5
+ require "yaml"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ cfg_path = File.join(File.dirname(__FILE__), "../spec/support/majestic_seo.yml")
15
+
16
+ if File.exists?(cfg_path)
17
+ yaml = YAML.load_file(cfg_path)["development"]
18
+
19
+ MajesticSeoApi.configure do |config|
20
+ config.environment = yaml.fetch("environment", :sandbox)
21
+ config.api_key = yaml.fetch("api_key", nil)
22
+ config.verbose = true
23
+ end
24
+ end
25
+
26
+ require "irb"
27
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -1,70 +1,17 @@
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
- require 'uri'
34
- require 'cgi'
35
- require 'rubygems'
36
- require 'faraday_middleware'
37
-
38
1
  module MajesticSeo
39
2
  module Api
40
3
 
41
4
  class Client
42
- attr_accessor :connection, :api_url, :config, :api_key, :environment, :verbose
5
+ attr_accessor :connection, :api_url
43
6
  include MajesticSeo::Api::Logger
44
7
 
45
- def initialize(options = {})
46
- set_config
47
-
48
- @api_key = options.fetch(:api_key, self.config.fetch("api_key", nil))
49
- @environment = options.fetch(:environment, self.config.fetch("environment", :sandbox)).to_sym
50
- @verbose = options.fetch(:verbose, false)
51
-
8
+ def initialize
52
9
  set_api_url
53
10
  set_connection
54
11
  end
55
-
56
- def set_config
57
- env = (defined?(Rails) && Rails.respond_to?(:env)) ? Rails.env : (ENV["RACK_ENV"] || 'development')
58
-
59
- self.config = YAML.load_file(File.join(Rails.root, "config/majestic_seo.yml"))[env] rescue nil
60
- self.config ||= YAML.load_file(File.join(File.dirname(__FILE__), "../../generators/templates/majestic_seo.yml"))[env] rescue nil
61
- self.config ||= YAML.load_file(File.join(File.dirname(__FILE__), "../../generators/templates/majestic_seo.template.yml"))[env] rescue nil
62
- self.config ||= {}
63
- end
64
12
 
65
- #TODO: Switch to the JSON API
66
- def set_api_url(format = :xml)
67
- @api_url = case @environment.to_sym
13
+ def set_api_url(format = :json)
14
+ self.api_url = case ::MajesticSeoApi.configuration.environment.to_sym
68
15
  when :sandbox then "http://developer.majestic.com/api/#{format}"
69
16
  when :production then "http://api.majestic.com/api/#{format}"
70
17
  else
@@ -73,11 +20,12 @@ module MajesticSeo
73
20
  end
74
21
 
75
22
  def set_connection
76
- @connection = Faraday.new(url: @api_url, ssl: {verify: false}) do |builder|
77
- builder.request :url_encoded
78
- builder.request :retry
79
- builder.response :logger if (@verbose)
80
- builder.adapter :net_http
23
+ self.connection = Faraday.new(url: self.api_url, ssl: {verify: false}) do |builder|
24
+ builder.request :url_encoded
25
+ builder.request :retry
26
+ builder.response :json
27
+ builder.response :logger if ::MajesticSeoApi.configuration.verbose
28
+ builder.adapter :net_http
81
29
  end
82
30
  end
83
31
 
@@ -97,6 +45,8 @@ module MajesticSeo
97
45
  end
98
46
 
99
47
  def get_top_back_links(url, parameters = {}, options = {})
48
+ raise "Not implemented yet!"
49
+
100
50
  request_parameters = {}
101
51
  request_parameters['datasource'] = parameters.fetch(:data_source, "historic")
102
52
  request_parameters['URL'] = url
@@ -108,10 +58,10 @@ module MajesticSeo
108
58
  request_parameters["MaxSourceURLsPerRefDomain"] = parameters.fetch(:max_source_urls_per_ref_domain, -1)
109
59
  request_parameters["DebugForceQueue"] = parameters.fetch(:debug_force_queue, 0)
110
60
 
111
- response = self.execute_command("GetTopBackLinks", request_parameters, options)
112
- response = MajesticSeo::Api::TopBackLinksResponse.new(response)
61
+ #response = self.execute_command("GetTopBackLinks", request_parameters, options)
62
+ #response = MajesticSeo::Api::TopBackLinksResponse.new(response)
113
63
 
114
- return response
64
+ #return response
115
65
  end
116
66
 
117
67
  # This method will execute the specified command as an api request.
@@ -119,7 +69,7 @@ module MajesticSeo
119
69
  # 'parameters' a hash containing the command parameters.
120
70
  # 'timeout' specifies the amount of time to wait before aborting the transaction. This defaults to 5 seconds.
121
71
  def execute_command(name, parameters = {}, options = {})
122
- request_parameters = parameters.merge({"app_api_key" => @api_key, "cmd" => name})
72
+ request_parameters = parameters.merge({"app_api_key" => ::MajesticSeoApi.configuration.api_key, "cmd" => name})
123
73
  self.execute_request(request_parameters, options)
124
74
  end
125
75
 
@@ -129,7 +79,7 @@ module MajesticSeo
129
79
  # 'access_token' the token provided by the user to access their resources.
130
80
  # 'timeout' specifies the amount of time to wait before aborting the transaction. This defaults to 5 seconds.
131
81
  def execute_open_app_request(command_name, access_token, parameters = {}, options = {})
132
- request_parameters = parameters.merge({"accesstoken" => access_token, "cmd" => command_name, "privatekey" => @api_key})
82
+ request_parameters = parameters.merge({"accesstoken" => access_token, "cmd" => command_name, "privatekey" => ::MajesticSeoApi.configuration.api_key})
133
83
  self.execute_request(request_parameters, options)
134
84
  end
135
85
 
@@ -143,14 +93,14 @@ module MajesticSeo
143
93
  begin
144
94
  log(:info, "[MajesticSeo::Api::Client] - Sending API Request to Majestic SEO. Parameters: #{parameters.inspect}. Options: #{options.inspect}")
145
95
 
146
- response = @connection.get do |request|
147
- request.params = parameters if (!parameters.empty?)
148
- request.options = options if (!options.empty?)
96
+ response = self.connection.get do |request|
97
+ request.params = parameters if !parameters.empty?
98
+ request.options = options if !options.empty?
149
99
  request.options[:timeout] = timeout
150
100
  request.options[:open_timeout] = open_timeout
151
101
  end
152
102
 
153
- rescue StandardError => e
103
+ rescue Faraday::Error => e
154
104
  log(:error, "[MajesticSeo::Api::Client] - Error occurred while trying to perform API-call with parameters: #{parameters.inspect}. Error Class: #{e.class.name}. Error Message: #{e.message}. Stacktrace: #{e.backtrace.join("\n")}")
155
105
  retries -= 1
156
106
 
@@ -167,4 +117,4 @@ module MajesticSeo
167
117
  end
168
118
 
169
119
  end
170
- end
120
+ end