Module: Pebblebed::Http
- Defined in:
- lib/pebblebed/http.rb
Defined Under Namespace
Classes: Response
Constant Summary collapse
- 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, options = {}) ⇒ Object
- .streamer(on_data) ⇒ Object
Class Attribute Details
.connect_timeout ⇒ Object
Returns the value of attribute connect_timeout.
56 57 58 |
# File 'lib/pebblebed/http.rb', line 56 def connect_timeout @connect_timeout end |
.read_timeout ⇒ Object
Returns the value of attribute read_timeout.
56 57 58 |
# File 'lib/pebblebed/http.rb', line 56 def read_timeout @read_timeout end |
.write_timeout ⇒ Object
Returns the value of attribute write_timeout.
56 57 58 |
# File 'lib/pebblebed/http.rb', line 56 def write_timeout @write_timeout end |
Class Method Details
.delete(url, params, &block) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/pebblebed/http.rb', line 129 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
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/pebblebed/http.rb', line 81 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
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/pebblebed/http.rb', line 93 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, idempotent: false) { |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
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/pebblebed/http.rb', line 111 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
154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/pebblebed/http.rb', line 154 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) { |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
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/pebblebed/http.rb', line 168 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) { |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, options = {}) ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/pebblebed/http.rb', line 188 def self.stream_put(url, params, = {}) on_data = [:on_data] or raise "Option :on_data must be specified" url, params, query = url_and_params_from_args(url, params) 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 }.merge(headers), :body => body, :query => query, :persistent => false, :response_block => streamer(on_data) ) } end |
.streamer(on_data) ⇒ Object
147 148 149 150 151 152 |
# File 'lib/pebblebed/http.rb', line 147 def self.streamer(on_data) lambda do |chunk, remaining_bytes, total_bytes| on_data.call(chunk) total_bytes end end |