Class: Webspicy::RackTestClient::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/webspicy/client/rack_test_client.rb

Overview

class RackHandler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Api

Returns a new instance of Api.



60
61
62
# File 'lib/webspicy/client/rack_test_client.rb', line 60

def initialize(app)
  @app = app
end

Instance Attribute Details

#last_responseObject (readonly)

Returns the value of attribute last_response.



58
59
60
# File 'lib/webspicy/client/rack_test_client.rb', line 58

def last_response
  @last_response
end

Instance Method Details

#delete(url, params = {}, headers = nil, body = nil) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/webspicy/client/rack_test_client.rb', line 140

def delete(url, params = {}, headers = nil, body = nil)
  handler = get_handler(headers)

  Webspicy.info("DELETE #{url} -- #{params.inspect} -- #{headers.inspect}")

  handler.delete(url, params.to_json, {"CONTENT_TYPE" => "application/json"})
  @last_response = handler.last_response

  Webspicy.debug("Headers: #{@last_response.headers.to_hash}")
  Webspicy.debug("Response: #{@last_response.body}")

  @last_response
end

#get(url, params = {}, headers = nil, body = nil) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/webspicy/client/rack_test_client.rb', line 78

def get(url, params = {}, headers = nil, body = nil)
  handler = get_handler(headers)

  Webspicy.info("GET #{url} -- #{params.inspect} -- #{headers.inspect}")

  handler.get(url, params)
  @last_response = handler.last_response

  Webspicy.debug("Headers: #{@last_response.headers.to_hash}")
  Webspicy.debug("Response: #{@last_response.body}")

  @last_response
end

#options(url, params = {}, headers = nil, body = nil) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/webspicy/client/rack_test_client.rb', line 64

def options(url, params = {}, headers = nil, body = nil)
  handler = get_handler(headers)

  Webspicy.info("OPTIONS #{url} -- #{params.inspect} -- #{headers.inspect}")

  handler.options(url, params)
  @last_response = handler.last_response

  Webspicy.debug("Headers: #{@last_response.headers.to_hash}")
  Webspicy.debug("Response: #{@last_response.body}")

  @last_response
end

#patch(url, params = {}, headers = nil, body = nil) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/webspicy/client/rack_test_client.rb', line 112

def patch(url, params = {}, headers = nil, body = nil)
  handler = get_handler(headers)

  Webspicy.info("PATCH #{url} -- #{params.inspect} -- #{headers.inspect}")

  handler.patch(url, params.to_json, {"CONTENT_TYPE" => "application/json"})
  @last_response = handler.last_response

  Webspicy.debug("Headers: #{@last_response.headers.to_hash}")
  Webspicy.debug("Response: #{@last_response.body}")

  @last_response
end

#post(url, params = {}, headers = nil, body = nil) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/webspicy/client/rack_test_client.rb', line 92

def post(url, params = {}, headers = nil, body = nil)
  handler = get_handler(headers)

  url = url + "?" + Rack::Utils.build_query(params) if body && !params.empty?

  Webspicy.info("POST #{url} -- #{params.inspect} -- #{headers.inspect}")

  if body
    handler.post(url, body)
  else
    handler.post(url, params.to_json, {"CONTENT_TYPE" => "application/json"})
  end
  @last_response = handler.last_response

  Webspicy.debug("Headers: #{@last_response.headers.to_hash}")
  Webspicy.debug("Response: #{@last_response.body}")

  @last_response
end

#post_form(url, params = {}, headers = nil, body = nil) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/webspicy/client/rack_test_client.rb', line 126

def post_form(url, params = {}, headers = nil, body = nil)
  handler = get_handler(headers)

  Webspicy.info("POST #{url} -- #{params.inspect} -- #{headers.inspect}")

  handler.post(url, params)
  @last_response = handler.last_response

  Webspicy.debug("Headers: #{@last_response.headers.to_hash}")
  Webspicy.debug("Response: #{@last_response.body}")

  @last_response
end