Class: AhrefsAPI::Base

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/ahrefs_api/base.rb

Direct Known Subclasses

Backlinks, BacklinksNewLost, SubscriptionInfo

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_token = ENV['AHREFS_TOKEN'], activate_debug = false) ⇒ Base

Returns a new instance of Base.



11
12
13
14
15
16
17
# File 'lib/ahrefs_api/base.rb', line 11

def initialize(api_token = ENV['AHREFS_TOKEN'], activate_debug = false)
  @mode ||= :domain
  @token = api_token
  self.class.debug_output $stdout if activate_debug
  
  raise "No token: please provide a valid token for the AhrefsAPI" if @token.nil?
end

Instance Attribute Details

#modeObject

Returns the value of attribute mode.



10
11
12
# File 'lib/ahrefs_api/base.rb', line 10

def mode
  @mode
end

Instance Method Details

#get_json(target) ⇒ Object

returns the endpoint data for the target in JSON format



21
22
23
24
# File 'lib/ahrefs_api/base.rb', line 21

def get_json(target)
  return get_data(target) if target.is_a? Hash
  get_data(target: target)
end