Class: AutoPilot::API

Inherits:
Object
  • Object
show all
Defined in:
lib/auto_pilot/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user = AutoPilot.configuration.user, options = {}) ⇒ API

Returns a new instance of API.



6
7
8
9
10
11
# File 'lib/auto_pilot/api.rb', line 6

def initialize(user = AutoPilot.configuration.user, options = {})
  @user    = user
  @options = options
  @answers = []
  add_config_client_key
end

Instance Attribute Details

#answersObject (readonly)

Returns the value of attribute answers.



4
5
6
# File 'lib/auto_pilot/api.rb', line 4

def answers
  @answers
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/auto_pilot/api.rb', line 4

def options
  @options
end

#userObject (readonly)

Returns the value of attribute user.



4
5
6
# File 'lib/auto_pilot/api.rb', line 4

def user
  @user
end

Instance Method Details

#get_answersObject



13
14
15
16
17
18
19
20
21
# File 'lib/auto_pilot/api.rb', line 13

def get_answers
  Log.green "fetching information for #{AutoPilot.configuration.user} via stackoverflow api"
  pages.each do |page|
    response = answer_response(page)
    answers << response.data.first.answers
    break unless response.has_more
  end
  filtered(answers)
end

#pagesObject



23
24
25
# File 'lib/auto_pilot/api.rb', line 23

def pages
  Array(1..(AutoPilot.configuration.max_pages || 3))
end

#throttleObject

api.stackexchange.com/docs/throttle NOTE: While not strictly a throttle, the Stack Exchange API employs heavy caching and as such no application should make semantically identical requests more than once a minute.



29
30
31
32
# File 'lib/auto_pilot/api.rb', line 29

def throttle
  sleep(AutoPilot.configuration.throttle || 3)
  yield if block_given?
end