ahrefs_api 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ahrefs_api.rb +2 -1
- data/lib/ahrefs_api/backlinks_new_lost.rb +22 -0
- data/lib/ahrefs_api/base.rb +47 -3
- data/lib/ahrefs_api/subscription_info.rb +13 -0
- data/lib/ahrefs_api/version.rb +1 -1
- metadata +4 -3
- data/lib/ahrefs_api/backlinks.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca5aede1614a9cedff3200f575914abe91091cf5
|
4
|
+
data.tar.gz: 95449395f3fdcee85cca34d0a23aa5641f6de53a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa161e0e36768b6ff99e8213db7a93b241aae70ca480db07ea340fbeec8dd5cc4c7ef74fdcc4fed960fa8f422abb34391e2e4dad73dfeffb9efaabfb31a2609f
|
7
|
+
data.tar.gz: b354cdd35798e518ff0e4dd981ec31fd5b2d510e93701dc53a4eccaf767141784f5497db2474185f3d4f668253ef20d539ef33b1022cb2964de61c51ee537d4a
|
data/lib/ahrefs_api.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
module AhrefsAPI
|
3
|
+
# this API endpoint gives a list of the new/lost links up to 60 days back
|
4
|
+
# it supports limit, offset, having
|
5
|
+
class BacklinksNewLost < AhrefsAPI::Base
|
6
|
+
def from
|
7
|
+
:backlinks_new_lost
|
8
|
+
end
|
9
|
+
|
10
|
+
# give options as a hash
|
11
|
+
# possible options:
|
12
|
+
# limit ==> limits the number of returned results
|
13
|
+
# select ==> only hands you back the selected columns
|
14
|
+
# offset ==>
|
15
|
+
# having ==>
|
16
|
+
# where ==> accepts type:"new"/type:"lost" and date:"2013-05-26"
|
17
|
+
def get_json(target = :'ahrefs.com', opts = {})
|
18
|
+
opts[:target] = target
|
19
|
+
get_data(opts)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/ahrefs_api/base.rb
CHANGED
@@ -1,11 +1,55 @@
|
|
1
1
|
require 'httparty'
|
2
2
|
require 'open-uri'
|
3
|
-
require 'openssl'
|
4
3
|
require 'cgi'
|
5
4
|
|
6
5
|
module AhrefsAPI
|
7
6
|
class Base
|
8
|
-
include
|
9
|
-
base_uri 'http://apiv2.ahrefs.com
|
7
|
+
include HTTParty
|
8
|
+
base_uri 'http://apiv2.ahrefs.com'
|
9
|
+
debug_output $stdout
|
10
|
+
|
11
|
+
attr_accessor :mode
|
12
|
+
def initialize(api_token = ENV['AHREFS_TOKEN'])
|
13
|
+
@mode ||= :domain
|
14
|
+
@token = api_token
|
15
|
+
raise "No token: please provide a valid token for the AhrefsAPI" if @token.nil?
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
# returns the endpoint data for the target in JSON format
|
20
|
+
def get_json(target)
|
21
|
+
return get_data(target) if target.is_a? Hash
|
22
|
+
get_data(target: target)
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
# sets common & default options
|
27
|
+
# makes the actual call to the API endpoint
|
28
|
+
def get_data(custom_query)
|
29
|
+
qopts = {
|
30
|
+
token: token,
|
31
|
+
from: from,
|
32
|
+
output: :json,
|
33
|
+
mode: mode,
|
34
|
+
target: :'ahrefs.com'
|
35
|
+
}.merge(custom_query)
|
36
|
+
|
37
|
+
response = self.class.get('/', {query: qopts})
|
38
|
+
|
39
|
+
raise "HTTP error: #{response.code}", response unless (200..299).include? response.code
|
40
|
+
json = JSON.parse response.body
|
41
|
+
unless json['error'].nil?
|
42
|
+
error = json['error']
|
43
|
+
raise "API error: #{error}"
|
44
|
+
|
45
|
+
end
|
46
|
+
return json
|
47
|
+
end
|
48
|
+
|
49
|
+
# returns the API token
|
50
|
+
def token
|
51
|
+
@token
|
52
|
+
end
|
53
|
+
|
10
54
|
end
|
11
55
|
end
|
data/lib/ahrefs_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ahrefs_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christoph Engelhardt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02
|
11
|
+
date: 2015-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -69,8 +69,9 @@ files:
|
|
69
69
|
- Rakefile
|
70
70
|
- ahrefs_api.gemspec
|
71
71
|
- lib/ahrefs_api.rb
|
72
|
-
- lib/ahrefs_api/
|
72
|
+
- lib/ahrefs_api/backlinks_new_lost.rb
|
73
73
|
- lib/ahrefs_api/base.rb
|
74
|
+
- lib/ahrefs_api/subscription_info.rb
|
74
75
|
- lib/ahrefs_api/version.rb
|
75
76
|
homepage: https://github.com/yas4891/ahrefs_api
|
76
77
|
licenses:
|