Class: Linkscape::Client
- Inherits:
-
Object
- Object
- Linkscape::Client
- Defined in:
- lib/linkscape/client.rb
Instance Method Summary collapse
- #allLinks(*args) ⇒ Object
- #anchorMetrics(*args) ⇒ Object
-
#initialize(*args) ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ Object
- #mozRank(*args) ⇒ Object
- #status(*args) ⇒ Object
- #topLinks(*args) ⇒ Object
- #topPages(*args) ⇒ Object
- #urlMetrics(*args) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Client
Returns a new instance of Client.
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/linkscape/client.rb', line 3 def initialize(*args) = Hash === args.last ? args.pop : {} @accessID = args.first ? args.shift : ([:id] || [:ID] || [:accessID]) @secretKey = args.first ? args.shift : ([:secret] || [:secretKey] || [:key]) @options = { :apiHost => 'lsapi.seomoz.com', :apiRoot => 'linkscape', :accessID => @accessID, :secretKey => @secretKey }.merge() end |
Instance Method Details
#allLinks(*args) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/linkscape/client.rb', line 79 def allLinks(*args) = Hash === args.last ? args.pop.symbolize_keys : {} url = args.first ? args.shift : [:url] scope = args.length >= 2 ? "#{args.shift}_to_#{args.shift}" : (args.first ? args.shift : [:scope]) sortOrder = (args.first ? args.shift : ([:sort] || [:sortOrder] || 'domains_linking_page')).to_sym filters = args.first ? args.shift : ([:filters] || [:filter] || '') raise MissingArgument, "allLinks requires a scope ([page, domain] to [page, subdomain, domain]) and a url." unless scope and url raise InvalidArgument, "allLinks scope must be valid ([page, domain] to [page, subdomain, domain])" unless scope.to_s =~ /^(page|domain)_to_(page|subdomain|domain)$/ raise InvalidArgument, "allLinks sort order must be valid (domain_authority, page_authority, domains_linking_page, domains_linking_domain)" unless [:domain_authority, :page_authority, :domains_linking_page, :domains_linking_domain].include? sortOrder if String === filters filters = filters.downcase.split(/[,\s\+]+/).sort.collect(&:to_sym) elsif Hash === filters filters = filters.keys.collect{|k|k.to_s.downcase}.sort.collect(&:to_sym) elsif Array === filters filters = filters.collect{|k|k.to_s.downcase}.sort.collect(&:to_sym) elsif Symbol === filters filters = [filters] else raise InvalidArgument, "allLinks filters must be a string, hash, or array" end raise InvalidArgument, "allLinks filters must be from the set (:internal, :external, :redir301, :follow, :nofollow)" unless (filters - [:internal, :external, :redir301, :follow, :nofollow]).empty? [:url] = url [:api] = 'links' [:query] = { 'SourceCols' => translateBitfield([:sourcecols], [:sourcecolumns], [:urlcols], :type => :url), 'TargetCols' => translateBitfield([:targetcols], [:targetcolumns], [:urlcols], :type => :url), 'LinkCols' => translateBitfield([:cols], [:columns], [:linkcols], :type => :link), 'Scope' => scope, 'Filter' => filters.join(' ').gsub(/redir/, ''), 'Sort' => sortOrder.to_s, } raise MissingArgument, "allLinks requires a list of columns for Source, Target, and/or Link." unless [:query]['SourceCols'].nonzero? or [:query]['TargetCols'].nonzero? or [:query]['LinkCols'].nonzero? Linkscape::Request.run(@options.merge()) end |
#anchorMetrics(*args) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/linkscape/client.rb', line 144 def anchorMetrics(*args) = Hash === args.last ? args.pop.symbolize_keys : {} url = args.first ? args.shift : [:url] scope = args.length >= 2 ? "#{args.shift}_to_#{args.shift}" : (args.first ? args.shift : [:scope]) filters = args.first ? args.shift : ([:filters] || [:filter] || '') sortOrder = (args.first ? args.shift : ([:sort] || [:sortOrder] || 'domains_linking_page')).to_sym raise InvalidArgument, "anchorMetrics scope must be valid ([phrase, term] to [page, subdomain, domain])" unless scope.to_s =~ /^(phrase|term)_to_(page|subdomain|domain)$/ raise InvalidArgument, "anchorMetrics sort order must be valid (domain_authority, page_authority, domains_linking_page, domains_linking_domain)" unless [:domain_authority, :page_authority, :domains_linking_page, :domains_linking_domain].include? sortOrder if String === filters filters = filters.downcase.split(/[,\s\+]+/).sort.collect(&:to_sym) elsif Hash === filters filters = filters.keys.collect{|k|k.to_s.downcase}.sort.collect(&:to_sym) elsif Array === filters filters = filters.collect{|k|k.to_s.downcase}.sort.collect(&:to_sym) elsif Symbol === filters filters = [filters] else raise InvalidArgument, "anchorMetrics filters must be a string, hash, or array" end raise InvalidArgument, "anchorMetrics filters must be from the set (:internal, :external)" unless (filters - [:internal, :external]).empty? [:url] = url [:api] = 'anchor-text' [:query] = { 'Cols' => translateBitfield([:cols], [:columns], [:anchorcols], :type => :anchors), 'Scope' => scope, 'Filter' => filters.join(' ').gsub(/redir/, ''), 'Sort' => sortOrder.to_s, } # raise MissingArgument, "anchorMetrics requires a list of columns to return." unless options[:query]['Cols'].nonzero? Linkscape::Request.run(@options.merge()) end |
#inspect ⇒ Object
185 186 187 |
# File 'lib/linkscape/client.rb', line 185 def inspect %Q[#<#{self.class}:#{"0x%x" % self.object_id} api="#{@options[:apiHost]}/#{@options[:apiRoot]}" accessID="#{@options[:accessID]}">] end |
#mozRank(*args) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/linkscape/client.rb', line 18 def mozRank(*args) = Hash === args.last ? args.pop.symbolize_keys : {} url = args.first ? args.shift : [:url] raise MissingArgument, "mozRank requires a url." unless url [:url] = url [:api] = 'mozrank' Linkscape::Request.run(@options.merge()) end |
#status(*args) ⇒ Object
137 138 139 140 141 |
# File 'lib/linkscape/client.rb', line 137 def status(*args) = Hash === args.last ? args.pop.symbolize_keys : {} [:api] = 'status' Linkscape::Request.run(@options.merge()) end |
#topLinks(*args) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/linkscape/client.rb', line 50 def topLinks(*args) = Hash === args.last ? args.pop.symbolize_keys : {} url = args.first ? args.shift : [:url] whichSet = (args.first ? args.shift : ([:set] || 'none')).to_sym raise MissingArgument, "topLinks requires a set (:page, :subdomain, :domain) and a url." unless whichSet and url [:url] = url [:api] = { :page => 'page-linklist', :subdomain => 'subdomain-linklist', :domain => 'rootdomain-linklist', }[whichSet] raise InvalidArgument, "topLinks set must be one of :page, :subdomain, :domain" unless [:api] [:query] = { 'SourceCols' => translateBitfield([:sourcecols], [:sourcecolumns], [:urlcols], :type => :url), 'TargetCols' => translateBitfield([:targetcols], [:targetcolumns], [:urlcols], :type => :url), 'LinkCols' => translateBitfield([:cols], [:columns], [:linkcols], :type => :link), } raise MissingArgument, "topLinks requires a list of columns for Source, Target, and/or Link." unless [:query]['SourceCols'].nonzero? or [:query]['TargetCols'].nonzero? or [:query]['LinkCols'].nonzero? Linkscape::Request.run(@options.merge()) end |
#topPages(*args) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/linkscape/client.rb', line 121 def topPages(*args) = Hash === args.last ? args.pop.symbolize_keys : {} url = args.first ? args.shift : [:url] [:url] = url [:api] = 'top-pages' [:query] = { 'Cols' => translateBitfield([:cols], [:columns], [:sourcecols], [:sourcecolumns], [:urlcols], :type => :url), } raise MissingArgument, "topPages requires a list of columns to return." unless [:query]['Cols'].nonzero? Linkscape::Request.run(@options.merge()) end |
#urlMetrics(*args) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/linkscape/client.rb', line 31 def urlMetrics(*args) = Hash === args.last ? args.pop.symbolize_keys : {} url = args.first ? args.shift : [:url] raise MissingArgument, "urlMetrics requires a url." unless url [:url] = url [:api] = 'url-metrics' [:query] = { 'Cols' => translateBitfield([:cols], [:columns], [:fields], :type => :url) } raise MissingArgument, "urlMetrics requires a list of columns to return." unless [:query]['Cols'].nonzero? Linkscape::Request.run(@options.merge()) end |