Class: Webspicy::Web::RackTestClient::Api

Inherits:
Object
  • Object
show all
Includes:
Client::Support
Defined in:
lib/webspicy/web/client/rack_test_client.rb

Overview

class RackHandler

Constant Summary

Constants included from Client::Support

Client::Support::NONE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Client::Support

#debug, #debug_response, #info_request, #json_pretty, #querystring_params, #request_body_to_s, #response_body_to_s, #status_to_s, #value_to_s

Methods included from Support::Colorize

colorize, colorize_error, colorize_highlight, colorize_section, colorize_success

Constructor Details

#initialize(scope, app) ⇒ Api

Returns a new instance of Api.



62
63
64
65
# File 'lib/webspicy/web/client/rack_test_client.rb', line 62

def initialize(scope, app)
  @scope = scope
  @app = app
end

Instance Attribute Details

#last_responseObject (readonly)

Returns the value of attribute last_response.



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

def last_response
  @last_response
end

Instance Method Details

#configObject



67
68
69
# File 'lib/webspicy/web/client/rack_test_client.rb', line 67

def config
  @scope.config
end

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



163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/webspicy/web/client/rack_test_client.rb', line 163

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

  info_request("DELETE", url, params, headers, body)

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

  debug_response(@last_response)

  @last_response
end

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



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/webspicy/web/client/rack_test_client.rb', line 84

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

  params = Hash[params.map{|k,v| [k, v.nil? ? "" : v] }]
  info_request("GET", url, params, headers, body)

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

  debug_response(@last_response)

  @last_response
end

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



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/webspicy/web/client/rack_test_client.rb', line 71

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

  info_request("OPTIONS", url, params, headers, body)

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

  debug_response(@last_response)

  @last_response
end

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



124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/webspicy/web/client/rack_test_client.rb', line 124

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

  info_request("PATCH", url, params, headers, body)

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

  debug_response(@last_response)

  @last_response
end

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



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/webspicy/web/client/rack_test_client.rb', line 98

def post(url, params = {}, headers = nil, body = nil)
  url = url + "?" + Rack::Utils.build_query(params) if body && !params.empty?
  headers = {
    "Content-Type" => "application/json"
  }.merge(headers || {}) if body.nil?
  handler = get_handler(headers)

  case body
  when NilClass
    info_request("POST", url, params, headers, body)
    handler.post(url, params.to_json, headers)
  when FileUpload
    file = Rack::Test::UploadedFile.new(body.path, body.content_type)
    info_request("POST", url, params, headers, body)
    handler.post(url, body.param_name.to_sym => file)
  else
    info_request("POST", url, params, headers, body)
    handler.post(url, body)
  end
  @last_response = handler.last_response

  debug_response(@last_response)

  @last_response
end

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



150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/webspicy/web/client/rack_test_client.rb', line 150

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

  info_request("POST", url, params, headers, body)

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

  debug_response(@last_response)

  @last_response
end

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



137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/webspicy/web/client/rack_test_client.rb', line 137

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

  info_request("PUT", url, params, headers, body)

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

  debug_response(@last_response)

  @last_response
end