Class: CustomRequest

Inherits:
RequestBase show all
Defined in:
lib/CustomRequest/CustomRequest.rb

Instance Attribute Summary collapse

Attributes inherited from RequestBase

#http_helper, #query_params

Instance Method Summary collapse

Methods inherited from RequestBase

#with_accept_language, #with_custom_header, #with_custom_parameter

Constructor Details

#initialize(api_key, access_token) ⇒ CustomRequest

Returns a new instance of CustomRequest.



8
9
10
11
# File 'lib/CustomRequest/CustomRequest.rb', line 8

def initialize(api_key, access_token)
    @route = "/v3/"
    super(api_key, access_token)
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



5
6
7
# File 'lib/CustomRequest/CustomRequest.rb', line 5

def body
  @body
end

#headersObject

Returns the value of attribute headers.



5
6
7
# File 'lib/CustomRequest/CustomRequest.rb', line 5

def headers
  @headers
end

#methodObject

Returns the value of attribute method.



5
6
7
# File 'lib/CustomRequest/CustomRequest.rb', line 5

def method
  @method
end

#routeObject

Returns the value of attribute route.



5
6
7
# File 'lib/CustomRequest/CustomRequest.rb', line 5

def route
  @route
end

Instance Method Details

#executeObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/CustomRequest/CustomRequest.rb', line 13

def execute
    case @method
    when "GET"
        return @http_helper.get(@route, @query_params, self.headers)
    when "POST"
        return @http_helper.post(@route, @query_params, self.body, self.headers)
    when "PUT"
        return @http_helper.put(@route, @query_params, self.body, self.headers)
    when "DELETE"
        return @http_helper.delete(@route, @query_params, self.headers)
    else
        raise "No appropriate HTTP method found for this request."
    end
	
end

#with_body(body) ⇒ Object



58
59
60
61
# File 'lib/CustomRequest/CustomRequest.rb', line 58

def with_body(body)	
    self.body = body
    return self
end

#with_headers(headers) ⇒ Object



63
64
65
66
# File 'lib/CustomRequest/CustomRequest.rb', line 63

def with_headers(headers)	
    self.headers = headers
    return self
end

#with_method(method) ⇒ Object



34
35
36
37
# File 'lib/CustomRequest/CustomRequest.rb', line 34

def with_method(method)	
    @method = method
    return self
end

#with_query_parameters(params) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/CustomRequest/CustomRequest.rb', line 39

def with_query_parameters(params)
    params.each do |key,value|
        if value.is_a?(Array)
value = value.join(",")
if !key.include? "id"
	value.downcase!
            end	
            params[key] = value
			else
if (!key.include? "id") && (value.is_a?(String))
	value.downcase!
            end	
            params[key] = value
        end
    end
    @query_params = params
    return self
end

#with_route(route) ⇒ Object



29
30
31
32
# File 'lib/CustomRequest/CustomRequest.rb', line 29

def with_route(route)	
    @route += route
    return self
end