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



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

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

#delete(path) ⇒ Object



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

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
# File 'lib/helium/client/http.rb', line 14

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

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

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



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

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

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



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

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



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

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

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