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_id, 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_id, 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_id, = {}) @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 22 23 24 25 26 27 28 |
# File 'lib/auto_pilot/api.rb', line 13 def get_answers Log.green "fetching information for id #{AutoPilot.configuration.user_id} via stackoverflow api" pages.each do |page| begin Log.green "fetching answers for page #{page}" response = answer_response(page) answers << response.data.first.answers rescue => e Log.red "An error occured: #{e}" Log.red '- AutoPilot will continue downloading your answers' break end break unless response.has_more end filtered(answers) end |
#pages ⇒ Object
30 31 32 |
# File 'lib/auto_pilot/api.rb', line 30 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.
36 37 38 39 |
# File 'lib/auto_pilot/api.rb', line 36 def throttle sleep(AutoPilot.configuration.throttle || 3) yield if block_given? end |