Module: Pebblebed::Http

Defined in:
lib/pebblebed/http.rb

Defined Under Namespace

Classes: Response

Class Method Summary collapse

Class Method Details

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



81
82
83
84
85
86
87
# File 'lib/pebblebed/http.rb', line 81

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



51
52
53
54
55
56
57
# File 'lib/pebblebed/http.rb', line 51

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



59
60
61
62
63
64
65
66
67
68
# File 'lib/pebblebed/http.rb', line 59

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



70
71
72
73
74
75
76
77
78
79
# File 'lib/pebblebed/http.rb', line 70

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



89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/pebblebed/http.rb', line 89

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



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/pebblebed/http.rb', line 104

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



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/pebblebed/http.rb', line 122

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