Class: Modgen::API::Request

Inherits:
Object show all
Defined in:
lib/modgen/api/request.rb

Direct Known Subclasses

APIRequest

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, data = {}, http_method = :get) ⇒ Request

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

Hash

{
  'path'   => {},
  'params' => {},
  'body'   => {}
}
http_method

http method

default: :get



37
38
39
40
41
42
43
44
45
46
47
48
# 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

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/modgen/api/request.rb', line 5

def data
  @data
end

#http_methodObject (readonly)

Returns the value of attribute http_method.



5
6
7
# File 'lib/modgen/api/request.rb', line 5

def http_method
  @http_method
end

#origin_urlObject (readonly)

Returns the value of attribute origin_url.



5
6
7
# File 'lib/modgen/api/request.rb', line 5

def origin_url
  @origin_url
end

#urlObject (readonly)

Returns the value of attribute url.



5
6
7
# File 'lib/modgen/api/request.rb', line 5

def url
  @url
end

Instance Method Details

#responseObject

Send request



52
53
54
# File 'lib/modgen/api/request.rb', line 52

def response
  @response ||= _response
end