Class: SocialNet::Twitter::Api::Request
- Inherits:
-
Object
- Object
- SocialNet::Twitter::Api::Request
- Defined in:
- lib/social_net/twitter/api/request.rb
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ Request
constructor
A new instance of Request.
- #run ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Request
Returns a new instance of Request.
9 10 11 12 13 14 15 |
# File 'lib/social_net/twitter/api/request.rb', line 9 def initialize(attrs = {}) @host = 'api.twitter.com' @path = attrs.fetch :path, "/1.1/#{attrs[:endpoint]}.json" @query = attrs[:params].to_param if attrs[:params] @block = attrs.fetch :block, -> (request) {add_access_token! request} @method = attrs.fetch :method, :get end |
Instance Method Details
#run ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/social_net/twitter/api/request.rb', line 17 def run #print "#{as_curl}\n" case response = run_http_request when Net::HTTPOK JSON response.body when Net::HTTPTooManyRequests store_rate_limit_reset response.header["x-rate-limit-reset"].to_i run else raise Errors::ResponseError, response end end |