Module: Pebblebed::Http

Defined in:
lib/pebblebed/http.rb

Defined Under Namespace

Classes: Response

Constant Summary collapse

DEFAULT_CONNECT_TIMEOUT =
30
DEFAULT_REQUEST_TIMEOUT =
nil
DEFAULT_READ_TIMEOUT =
30

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.connect_timeoutObject

Returns the value of attribute connect_timeout.



44
45
46
# File 'lib/pebblebed/http.rb', line 44

def connect_timeout
  @connect_timeout
end

.read_timeoutObject

Returns the value of attribute read_timeout.



44
45
46
# File 'lib/pebblebed/http.rb', line 44

def read_timeout
  @read_timeout
end

.request_timeoutObject

Returns the value of attribute request_timeout.



44
45
46
# File 'lib/pebblebed/http.rb', line 44

def request_timeout
  @request_timeout
end

Class Method Details

.delete(url, params, &block) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/pebblebed/http.rb', line 88

def self.delete(url, params, &block)
  url, params = url_and_params_from_args(url, params, &block)
  return do_easy { |easy|
    easy.url = url_with_params(url, params)
    easy.http_delete
  }
end

.get(url = nil, params = nil, &block) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/pebblebed/http.rb', line 58

def self.get(url = nil, params = nil, &block)
  url, params = url_and_params_from_args(url, params, &block)
  return do_easy { |easy|
    easy.url = url_with_params(url, params)
    easy.http_get
  }
end

.post(url, params, &block) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/pebblebed/http.rb', line 66

def self.post(url, params, &block)
  url, params = url_and_params_from_args(url, params, &block)
  content_type, body = serialize_params(params)
  return do_easy { |easy|
    easy.url = url.to_s
    easy.headers['Accept'] = 'application/json'
    easy.headers['Content-Type'] = content_type
    easy.http_post(body)
  }
end

.put(url, params, &block) ⇒ Object



77
78
79
80
81
82
83
84
85
86
# File 'lib/pebblebed/http.rb', line 77

def self.put(url, params, &block)
  url, params = url_and_params_from_args(url, params, &block)
  content_type, body = serialize_params(params)
  return do_easy { |easy|
    easy.url = url.to_s
    easy.headers['Accept'] = 'application/json'
    easy.headers['Content-Type'] = content_type
    easy.http_put(body)
  }
end

.stream_get(url = nil, params = nil, options = {}) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/pebblebed/http.rb', line 96

def self.stream_get(url = nil, params = nil, options = {})
  return do_easy { |easy|
    on_data = options[:on_data] or raise "Option :on_data must be specified"

    url, params = url_and_params_from_args(url, params)

    easy.url = url_with_params(url, params)
    easy.on_body do |data|
      on_data.call(data)
      data.length
    end
    easy.http_get
  }
end

.stream_post(url, params, options = {}) ⇒ 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.stream_post(url, params, options = {})
  return do_easy { |easy|
    on_data = options[:on_data] or raise "Option :on_data must be specified"

    url, params = url_and_params_from_args(url, params)
    content_type, body = serialize_params(params)

    easy.url = url.to_s
    easy.headers['Accept'] = 'application/json'
    easy.headers['Content-Type'] = content_type
    easy.on_body do |data|
      on_data.call(data)
      data.length
    end
    easy.http_post(body)
  }
end

.stream_put(url, params, options = {}) ⇒ 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.stream_put(url, params, options = {})
  return do_easy { |easy|
    on_data = options[:on_data] or raise "Option :on_data must be specified"

    url, params = url_and_params_from_args(url, params)
    content_type, body = serialize_params(params)

    easy.url = url.to_s
    easy.headers['Accept'] = 'application/json'
    easy.headers['Content-Type'] = content_type
    easy.on_body do |data|
      on_data.call(data)
      data.length
    end
    easy.http_put(body)
  }
end