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.
10 11 12 13 14 15 16 17 18 |
# File 'lib/mastodon/rest/request.rb', line 10 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 @options = @headers = @options.delete(:headers).merge @headers if @options.is_a?(Hash) && @options[:headers] end |
Instance Method Details
#perform ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/mastodon/rest/request.rb', line 20 def perform = @request_method == :get ? :params : :form response = http_client.headers(@headers).public_send(@request_method, @uri.to_s, => @options) STDERR.puts response.body if ENV['DEBUG'] == 'true' fail_or_return(response.code, response.body.empty? ? '' : Oj.load(response.to_s, mode: :null)) end |