Module: Helium::Client::Http

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

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#base_url ⇒ Object



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

def base_url
  "#{PROTOCOL}://#{@api_host}/v#{API_VERSION}"
end

#delete(path) ⇒ Object



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

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

#url_for(path) ⇒ Object

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



41
42
43
44
45
46
# File 'lib/helium/client/http.rb', line 41

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

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