Class: Fryfro::Endpoint
- Inherits:
-
Object
show all
- Includes:
- HTTParty
- Defined in:
- lib/fryfro/endpoint.rb
Class Method Summary
collapse
Class Method Details
.[](metric) ⇒ Object
12
13
14
15
16
17
18
19
20
|
# File 'lib/fryfro/endpoint.rb', line 12
def [](metric)
Proc.new do |code, key, opts = {}|
hash = { api_access_code: code }
hash[:api_key] = key if key
hash.merge!(opts)
get("/#{camelize(metric)}?#{queryize(hash)}")
end
end
|
.camelize(sym) ⇒ Object
27
28
29
|
# File 'lib/fryfro/endpoint.rb', line 27
def camelize(sym)
sym.to_s.split('_').map { |w| w.capitalize }.join
end
|
.camelize_key(sym) ⇒ Object
31
32
33
34
|
# File 'lib/fryfro/endpoint.rb', line 31
def camelize_key(sym)
parts = sym.to_s.split('_')
parts[0] + parts[1..-1].map { |w| w.capitalize }.join
end
|
.queryize(hash) ⇒ Object
22
23
24
25
|
# File 'lib/fryfro/endpoint.rb', line 22
def queryize(hash)
camelized_hash = Hash[hash.map { |k, v| [camelize_key(k), v] }]
URI.encode_www_form(camelized_hash)
end
|