Class: AutoPilot::API
- Inherits:
-
Object
- Object
- AutoPilot::API
- Defined in:
- lib/auto_pilot/api.rb
Instance Attribute Summary collapse
-
#answers ⇒ Object
readonly
Returns the value of attribute answers.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #get_answers ⇒ Object
-
#initialize(user = AutoPilot.configuration.user, options = {}) ⇒ API
constructor
A new instance of API.
- #pages ⇒ Object
-
#throttle ⇒ Object
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.
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, = {}) @user = user @options = @answers = [] add_config_client_key end |
Instance Attribute Details
#answers ⇒ Object (readonly)
Returns the value of attribute answers.
4 5 6 |
# File 'lib/auto_pilot/api.rb', line 4 def answers @answers end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/auto_pilot/api.rb', line 4 def @options end |
#user ⇒ Object (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_answers ⇒ Object
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 |
#pages ⇒ Object
23 24 25 |
# File 'lib/auto_pilot/api.rb', line 23 def pages Array(1..(AutoPilot.configuration.max_pages || 3)) end |
#throttle ⇒ Object
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 |