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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89587e15dc5719437d1136268c8ae913f3a41c21
4
- data.tar.gz: 9679338f073e248f34f2fb8ab536e49454a3e5b3
3
+ metadata.gz: ca5aede1614a9cedff3200f575914abe91091cf5
4
+ data.tar.gz: 95449395f3fdcee85cca34d0a23aa5641f6de53a
5
5
  SHA512:
6
- metadata.gz: 3694cf605bc2684ab01a9992b4331ffd38531c45762d9b1a968624fe8d7cedb888540747cdae249ccfe98735139be63aef18c6a5a084f2ec6c1df5cdef869729
7
- data.tar.gz: f9e5a3d2ea2141b5c1f87768a33260e860a09c92a5fab2f079e11aa715bf9fe3161696a20ec833c743462c467df38e1211b8cf25b1e33f2577155a4308930d1e
6
+ metadata.gz: aa161e0e36768b6ff99e8213db7a93b241aae70ca480db07ea340fbeec8dd5cc4c7ef74fdcc4fed960fa8f422abb34391e2e4dad73dfeffb9efaabfb31a2609f
7
+ data.tar.gz: b354cdd35798e518ff0e4dd981ec31fd5b2d510e93701dc53a4eccaf767141784f5497db2474185f3d4f668253ef20d539ef33b1022cb2964de61c51ee537d4a
data/lib/ahrefs_api.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "ahrefs_api/version"
2
2
  require 'ahrefs_api/base'
3
- require 'ahrefs_api/backlinks'
3
+ require 'ahrefs_api/backlinks_new_lost'
4
+ require 'ahrefs_api/subscription_info'
4
5
 
5
6
  class Hash
6
7
  # very naive implementation of to_query
@@ -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
@@ -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 httparty
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
@@ -0,0 +1,13 @@
1
+
2
+ module AhrefsAPI
3
+ class SubscriptionInfo < AhrefsAPI::Base
4
+
5
+ def from
6
+ :subscription_info
7
+ end
8
+
9
+ def get_json
10
+ super('ahrefs.com')
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module AhrefsAPI
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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.1
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-10 00:00:00.000000000 Z
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/backlinks.rb
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:
@@ -1,10 +0,0 @@
1
- require 'httparty'
2
- require 'open-uri'
3
- require 'openssl'
4
- require 'cgi'
5
-
6
- module AhrefsAPI
7
- class Backlinks < AhrefsAPI::Base
8
-
9
- end
10
- end