Module: FatZebra::APIHelper::ClassMethods

Defined in:
lib/fat_zebra/api_helper.rb

Instance Method Summary collapse

Instance Method Details

#base_pathObject



10
11
12
# File 'lib/fat_zebra/api_helper.rb', line 10

def base_path
  ''
end

#build_endpoint_url(base_url, path, params = nil, options = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fat_zebra/api_helper.rb', line 38

def build_endpoint_url(base_url, path, params = nil, options = {})
  host, port = base_url.split(':')
  port       = port.to_i if port

  url_params = Util.compact(
    host:  host,
    path:  path,
    port:  port,
    query: params
  )

  return URI::HTTPS.build(url_params) if options[:http_secure]
  URI::HTTP.build(url_params)
end

#class_nameString

Returns the class name.

Returns:

  • (String)

    the class name



28
29
30
# File 'lib/fat_zebra/api_helper.rb', line 28

def class_name
  name.split('::')[-1]
end

#default_headersObject



53
54
55
56
57
58
59
60
# File 'lib/fat_zebra/api_helper.rb', line 53

def default_headers
  {
    headers: {
      accept:       'application/json',
      content_type: 'application/json'
    }
  }
end

#requestObject

Send a request to the API



34
35
36
# File 'lib/fat_zebra/api_helper.rb', line 34

def request
  raise 'need to be implemented'
end

#resource_nameString

Returns resource name.

Returns:

  • (String)

    resource name



22
23
24
# File 'lib/fat_zebra/api_helper.rb', line 22

def resource_name
  Util.underscore("#{class_name}s")
end

#resource_path(path = nil) ⇒ String

Returns resource path.

Returns:

  • (String)

    resource path



16
17
18
# File 'lib/fat_zebra/api_helper.rb', line 16

def resource_path(path = nil)
  "/#{base_path}#{path || @resource_name || CGI.escape(resource_name)}"
end