Module: Pebblebed::Http
- Defined in:
- lib/pebblebed/http.rb
Defined Under Namespace
Classes: Response
Constant Summary collapse
- DEFAULT_REQUEST_TIMEOUT =
30
- DEFAULT_CONNECT_TIMEOUT =
30
- DEFAULT_READ_TIMEOUT =
30
- DEFAULT_WRITE_TIMEOUT =
60
Class Attribute Summary collapse
-
.connect_timeout ⇒ Object
Returns the value of attribute connect_timeout.
-
.read_timeout ⇒ Object
Returns the value of attribute read_timeout.
-
.write_timeout ⇒ Object
Returns the value of attribute write_timeout.
Class Method Summary collapse
- .delete(url, params, &block) ⇒ Object
- .get(url = nil, params = nil, &block) ⇒ Object
- .post(url, params, &block) ⇒ Object
- .put(url, params, &block) ⇒ Object
- .stream_get(url = nil, params = nil, headers: {}, on_data:) ⇒ Object
- .stream_post(url, params, headers: {}, on_data:) ⇒ Object
- .stream_put(url, params, on_data:) ⇒ Object
- .streamer(on_data) ⇒ Object
Class Attribute Details
.connect_timeout ⇒ Object
Returns the value of attribute connect_timeout.
61 62 63 |
# File 'lib/pebblebed/http.rb', line 61 def connect_timeout @connect_timeout end |
.read_timeout ⇒ Object
Returns the value of attribute read_timeout.
61 62 63 |
# File 'lib/pebblebed/http.rb', line 61 def read_timeout @read_timeout end |
.write_timeout ⇒ Object
Returns the value of attribute write_timeout.
61 62 63 |
# File 'lib/pebblebed/http.rb', line 61 def write_timeout @write_timeout end |
Class Method Details
.delete(url, params, &block) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/pebblebed/http.rb', line 134 def self.delete(url, params, &block) url, params, query = url_and_params_from_args(url, params, &block) content_type, body = serialize_params(params) return do_request(url) { |connection| connection.delete( :host => url.host, :path => url.path, :headers => { 'Accept' => 'application/json', 'Content-Type' => content_type }, :body => body, :query => query, :persistent => true ) } end |
.get(url = nil, params = nil, &block) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/pebblebed/http.rb', line 86 def self.get(url = nil, params = nil, &block) url, params, query = url_and_params_from_args(url, params, &block) return do_request(url) { |connection| connection.get( :host => url.host, :path => url.path, :query => QueryParams.encode((params || {}).merge(query)), :persistent => true ) } end |
.post(url, params, &block) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/pebblebed/http.rb', line 98 def self.post(url, params, &block) url, params, query = url_and_params_from_args(url, params, &block) content_type, body = serialize_params(params) return do_request(url) { |connection| connection.post( :host => url.host, :path => url.path, :headers => { 'Accept' => 'application/json', 'Content-Type' => content_type }, :body => body, :query => query, :persistent => true ) } end |
.put(url, params, &block) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/pebblebed/http.rb', line 116 def self.put(url, params, &block) url, params, query = url_and_params_from_args(url, params, &block) content_type, body = serialize_params(params) return do_request(url) { |connection| connection.put( :host => url.host, :path => url.path, :headers => { 'Accept' => 'application/json', 'Content-Type' => content_type }, :body => body, :query => query, :persistent => true ) } end |
.stream_get(url = nil, params = nil, headers: {}, on_data:) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/pebblebed/http.rb', line 159 def self.stream_get(url = nil, params = nil, headers: {}, on_data:) url, params, query = url_and_params_from_args(url, params) return do_request(url, share: false) { |connection| connection.get( :host => url.host, :path => url.path, :headers => headers, :query => QueryParams.encode((params || {}).merge(query)), :persistent => false, :response_block => streamer(on_data) ) } end |
.stream_post(url, params, headers: {}, on_data:) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/pebblebed/http.rb', line 173 def self.stream_post(url, params, headers: {}, on_data:) url, params, query = url_and_params_from_args(url, params) content_type, body = serialize_params(params) return do_request(url, share: false) { |connection| connection.post( :host => url.host, :path => url.path, :headers => { 'Accept' => 'application/json', 'Content-Type' => content_type }.merge(headers), :body => body, :persistent => false, :query => query, :response_block => streamer(on_data) ) } end |
.stream_put(url, params, on_data:) ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/pebblebed/http.rb', line 192 def self.stream_put(url, params, on_data:) url, params, query = url_and_params_from_args(url, params) content_type, body = serialize_params(params) return do_request(url, share: false) { |connection| connection.put( :host => url.host, :path => url.path, :headers => { 'Accept' => 'application/json', 'Content-Type' => content_type }.merge(headers), :body => body, :query => query, :persistent => false, :response_block => streamer(on_data) ) } end |
.streamer(on_data) ⇒ Object
152 153 154 155 156 157 |
# File 'lib/pebblebed/http.rb', line 152 def self.streamer(on_data) lambda do |chunk, remaining_bytes, total_bytes| on_data.call(chunk) total_bytes end end |