Module: FatZebra::APIHelper::ClassMethods
- Defined in:
- lib/fat_zebra/api_helper.rb
Instance Method Summary collapse
- #base_path ⇒ Object
- #build_endpoint_url(base_url, path, params = nil, options = {}) ⇒ Object
-
#class_name ⇒ String
The class name.
- #default_headers ⇒ Object
-
#request ⇒ Object
Send a request to the API.
-
#resource_name ⇒ String
Resource name.
-
#resource_path(path = nil) ⇒ String
Resource path.
Instance Method Details
#base_path ⇒ Object
12 13 14 |
# File 'lib/fat_zebra/api_helper.rb', line 12 def base_path '' end |
#build_endpoint_url(base_url, path, params = nil, options = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fat_zebra/api_helper.rb', line 40 def build_endpoint_url(base_url, path, params = nil, = {}) 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 [:http_secure] URI::HTTP.build(url_params) end |
#class_name ⇒ String
Returns the class name.
30 31 32 |
# File 'lib/fat_zebra/api_helper.rb', line 30 def class_name name.split('::')[-1] end |
#default_headers ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/fat_zebra/api_helper.rb', line 56 def default_headers { headers: { accept: 'application/json', content_type: 'application/json' } } end |
#request ⇒ Object
Send a request to the API
36 37 38 |
# File 'lib/fat_zebra/api_helper.rb', line 36 def request raise 'need to be implemented' end |
#resource_name ⇒ String
Returns resource name.
24 25 26 |
# File 'lib/fat_zebra/api_helper.rb', line 24 def resource_name Util.underscore("#{class_name}s") end |
#resource_path(path = nil) ⇒ String
Returns resource path.
18 19 20 |
# File 'lib/fat_zebra/api_helper.rb', line 18 def resource_path(path = nil) "/#{base_path}#{path || @resource_name || CGI.escape(resource_name)}" end |