Class: FatZebra::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/fat_zebra/request.rb,
lib/fat_zebra/request/multipart/part.rb,
lib/fat_zebra/request/multipart/param.rb,
lib/fat_zebra/request/multipart/stream.rb,
lib/fat_zebra/request/multipart/file_io.rb,
lib/fat_zebra/request/multipart/epilogue.rb

Overview

FatZebra Request Multipart Epilogue

Add the epilogue to the multipart

Defined Under Namespace

Modules: Multipart

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Request

Returns a new instance of Request.



53
54
55
56
57
58
59
60
61
# File 'lib/fat_zebra/request.rb', line 53

def initialize(params = {})
  @params = params
  @http   = Net::HTTP.new(uri.host,
                          uri.port,
                          proxy_host,
                          uri_proxy.port)

  setup_ssl if params[:use_ssl]
end

Instance Attribute Details

#httpObject (readonly)

Returns the value of attribute http.



51
52
53
# File 'lib/fat_zebra/request.rb', line 51

def http
  @http
end

#paramsObject (readonly)

Returns the value of attribute params.



51
52
53
# File 'lib/fat_zebra/request.rb', line 51

def params
  @params
end

#requestObject (readonly)

Returns the value of attribute request.



51
52
53
# File 'lib/fat_zebra/request.rb', line 51

def request
  @request
end

Class Method Details

.delete(params = {}) ⇒ Object



46
47
48
# File 'lib/fat_zebra/request.rb', line 46

def delete(params = {})
  new(params).delete
end

.execute(params = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fat_zebra/request.rb', line 17

def execute(params = {})
  klass = new(params)

  case params[:method]
  when :post
    klass.post
  when :put
    klass.put
  when :delete
    klass.delete
  when :get
    klass.get
  else
    raise FatZebra::UnknownRequestMethod, "#{params[:method]} haven't been implemented"
  end
end

.get(params = {}) ⇒ Object



42
43
44
# File 'lib/fat_zebra/request.rb', line 42

def get(params = {})
  new(params).get
end

.post(params = {}) ⇒ Object



34
35
36
# File 'lib/fat_zebra/request.rb', line 34

def post(params = {})
  new(params).post
end

.put(params = {}) ⇒ Object



38
39
40
# File 'lib/fat_zebra/request.rb', line 38

def put(params = {})
  new(params).put
end

Instance Method Details

#deleteObject



97
98
99
100
101
102
103
104
# File 'lib/fat_zebra/request.rb', line 97

def delete
  @request = Net::HTTP::Delete.new(uri.path)

  setup_auth_basic if params[:basic_auth]
  request.body = params[:payload].to_json

  handle_request
end

#getObject



88
89
90
91
92
93
94
95
# File 'lib/fat_zebra/request.rb', line 88

def get
  @request = Net::HTTP::Get.new(uri)

  setup_auth_basic if params[:basic_auth]
  set_header

  handle_request
end

#postObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/fat_zebra/request.rb', line 63

def post
  @request = Net::HTTP::Post.new(uri.path)

  setup_auth_basic if params[:basic_auth]

  if params[:payload] && params[:payload][:multipart]
    build_multipart_post
  else
    set_header
    request.body = params[:payload].to_json
  end

  handle_request
end

#putObject



78
79
80
81
82
83
84
85
86
# File 'lib/fat_zebra/request.rb', line 78

def put
  @request = Net::HTTP::Put.new(uri.path)

  setup_auth_basic if params[:basic_auth]
  set_header
  request.body = params[:payload].to_json

  handle_request
end