class Modgen::API::Request
Attributes
data[R]
http_method[R]
origin_url[R]
url[R]
Public Class Methods
new(url, data = {}, http_method = :get)
click to toggle source
Create Request
Data¶ ↑
path¶ ↑
data['path'] = {id: 1} url = http://a.a/:id
url will be transfered to
http://a.a/1
params¶ ↑
normal parameters send with request
body¶ ↑
this will be posted to the body of request
Parameters:¶ ↑
- url
-
full www adress
- data
-
{ 'path' => {}, 'params' => {}, 'body' => {} }
http_method
-
http method
default: :get
# File lib/modgen/api/request.rb, line 37 def initialize(url, data = {}, http_method = :get) @origin_url = url @url = url if data['path'] @url = url.to_s.gsub(/:([a-z][a-z0-9_]*)/) { data['path'][$1] } end @data = data @http_method = http_method.to_sym end
Public Instance Methods
response()
click to toggle source
Send request
# File lib/modgen/api/request.rb, line 52 def response @response ||= _response end
Private Instance Methods
_response()
click to toggle source
# File lib/modgen/api/request.rb, line 58 def _response conn = Faraday.new(url: @url) if @data['body'] && @data['body'].empty? response = conn.send(@http_method, "", @data['params']) else response = conn.send(@http_method, "") { |req| req.body = @data['body'] } end Modgen::API::Response.new(response, self) end