Module: Helium::Client::Http

Included in:
Helium::Client
Defined in:
lib/helium/client/http.rb

Constant Summary

BASE_HTTP_HEADERS =
{
  'Accept'        => 'application/json',
  'Content-Type'  => 'application/json',
  'User-Agent'    => 'helium-ruby'
}

Instance Method Summary collapse

Instance Method Details

#base_urlObject



39
40
41
42
43
# File 'lib/helium/client/http.rb', line 39

def base_url
  url = "#{PROTOCOL}://#{@api_host}"
  url += "/#{@api_version}" if @api_version
  url
end

#delete(path) ⇒ Object



34
35
36
37
# File 'lib/helium/client/http.rb', line 34

def delete(path)
  response = run(path, :delete)
  response.code == 204
end

#get(path, opts = {}) ⇒ Object



10
11
12
# File 'lib/helium/client/http.rb', line 10

def get(path, opts = {})
  run(path, :get, opts)
end

#paginated_get(path, opts = {}) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/helium/client/http.rb', line 14

def paginated_get(path, opts = {})
  klass  = opts.fetch(:klass)
  cursor_klass  = opts.fetch(:cursor_klass, Helium::Cursor)
  params = opts.fetch(:params, {})

  cursor_klass.new(client: self, path: path, klass: klass, params: params)
end

#patch(path, opts = {}) ⇒ Object



26
27
28
# File 'lib/helium/client/http.rb', line 26

def patch(path, opts = {})
  run(path, :patch, opts)
end

#post(path, opts = {}) ⇒ Object



22
23
24
# File 'lib/helium/client/http.rb', line 22

def post(path, opts = {})
  run(path, :post, opts)
end

#put(path, opts = {}) ⇒ Object



30
31
32
# File 'lib/helium/client/http.rb', line 30

def put(path, opts = {})
  run(path, :put, opts)
end

#url_for(path) ⇒ Object

Contructs a proper url given a path. If the path is already a full url it will simply pass through



47
48
49
50
51
52
# File 'lib/helium/client/http.rb', line 47

def url_for(path)
  return path if path =~ /^http/

  path = path.gsub(/^\//, '')
  "#{base_url}/#{path}"
end