Class: Mastodon::REST::Request
- Inherits:
-
Object
- Object
- Mastodon::REST::Request
- Defined in:
- lib/mastodon/rest/request.rb
Instance Method Summary collapse
-
#initialize(client, request_method, path, options = {}) ⇒ Request
constructor
A new instance of Request.
- #perform ⇒ Object
Constructor Details
#initialize(client, request_method, path, options = {}) ⇒ Request
Returns a new instance of Request.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mastodon/rest/request.rb', line 12 def initialize(client, request_method, path, = {}) @client = client @request_method = request_method @uri = Addressable::URI.parse(@client.base_url + path) @headers = Mastodon::Headers.new(@client).request_headers @path = @uri.path = # rubocop:disable GuardClause if .is_a?(Hash) && [:headers] @headers = .delete(:headers).merge @headers end # rubocop:enable GuardClause end |
Instance Method Details
#perform ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mastodon/rest/request.rb', line 26 def perform = @request_method == :get ? :params : :form response = http_client.headers(@headers) .public_send(@request_method, @uri.to_s, => ) STDERR.puts response.body if ENV['DEBUG'] == 'true' r_body = response.body.empty? ? '' : Oj.load(response.to_s, mode: :null) fail_or_return(response.code, r_body) end |