Module: Sophos::Client::Helper
- Included in:
- Sophos::Client
- Defined in:
- lib/sophos/client/helper.rb
Class Method Summary collapse
- .common_url(method) ⇒ Object
-
.def_api_call(method, url, singular_method = nil, paged = true) ⇒ Object
generate end point for ‘endpoint’ and ‘endpoints’.
- .endpoint_url(method) ⇒ Object
- .partner_url(method) ⇒ Object
- .sanitize(method_name) ⇒ Object
- .url(api, method) ⇒ Object
Class Method Details
.common_url(method) ⇒ Object
11 |
# File 'lib/sophos/client/helper.rb', line 11 def self.common_url(method) self.url('common', method); end |
.def_api_call(method, url, singular_method = nil, paged = true) ⇒ Object
generate end point for ‘endpoint’ and ‘endpoints’
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sophos/client/helper.rb', line 20 def self.def_api_call(method, url, singular_method = nil, paged = true) if singular_method self.send(:define_method, method) do |id = nil, params = {}| if id get("#{url}/#{id}", params) else get_paged(url, params) end end # strip trailing 's' self.send(:define_method, singular_method) do |id, params = {}| get("#{url}/#{id}", params) end else if paged self.send(:define_method, method) do |params = {}| get_paged(url, params) end else self.send(:define_method, method) do |params = {}| get(url, params) end end end end |
.endpoint_url(method) ⇒ Object
12 |
# File 'lib/sophos/client/helper.rb', line 12 def self.endpoint_url(method) self.url('endpoint', method); end |
.partner_url(method) ⇒ Object
13 |
# File 'lib/sophos/client/helper.rb', line 13 def self.partner_url(method) self.url('partner', method); end |
.sanitize(method_name) ⇒ Object
7 8 9 |
# File 'lib/sophos/client/helper.rb', line 7 def self.sanitize method_name method_name.to_s.gsub('_', '-') end |
.url(api, method) ⇒ Object
15 16 17 |
# File 'lib/sophos/client/helper.rb', line 15 def self.url(api,method) "/#{api}/v1/#{sanitize(method)}" end |