class TelegraphApi::Request
Constants
- API_URL
Attributes
opts[R]
path[R]
response_schema[R]
Public Class Methods
call(*args)
click to toggle source
# File lib/telegraph_api_ruby/request.rb, line 12 def self.call(*args) new(*args).call end
new(path, opts = {}, response_schema = nil)
click to toggle source
# File lib/telegraph_api_ruby/request.rb, line 16 def initialize(path, opts = {}, response_schema = nil) @path = path @opts = opts @response_schema = response_schema end
Public Instance Methods
call()
click to toggle source
# File lib/telegraph_api_ruby/request.rb, line 22 def call result = request(path, opts) response(result.body, response_schema) end
Private Instance Methods
request(path, body)
click to toggle source
# File lib/telegraph_api_ruby/request.rb, line 29 def request(path, body) Typhoeus.post("#{API_URL}/#{path}", body: body) end
response(data, type)
click to toggle source
# File lib/telegraph_api_ruby/request.rb, line 33 def response(data, type) json = JSON.parse(data, symbolize_names: true) if json[:ok] == true result = json[:result] (type && type[result]) || result else raise ResponseError, json[:error] end end