Class: SocialNet::Byte::Api::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/social_net/byte/api/request.rb

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Request

Returns a new instance of Request.



10
11
12
13
14
15
16
17
# File 'lib/social_net/byte/api/request.rb', line 10

def initialize(attrs = {})
  @host = 'api.byte.co'
  @username = attrs[:username]
  @endpoint = attrs.fetch :endpoint, "/account/id/#{@username}/posts"
  @block = attrs.fetch :block, -> (request) {add_access_token_and_cursor! request}
  @next_page = attrs[:next_page] if attrs[:next_page]
  @method = attrs.fetch :method, :get
end

Instance Method Details

#runObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/social_net/byte/api/request.rb', line 19

def run
  print "#{as_curl}\n"
  case response = run_http_request
  when Net::HTTPOK
    rate_limit_reset response.header["x-ratelimit-remaining"].to_i
    JSON response.body
  else
    raise Errors::ResponseError, response
  end
end