Class: Z4ai::JsonApi
- Inherits:
-
Object
- Object
- Z4ai::JsonApi
- Defined in:
- lib/z4ai.rb
Overview
because fuck you open weather
Instance Method Summary collapse
- #[](k) ⇒ Object
- #get(r, h = {}) ⇒ Object
-
#initialize(u) ⇒ JsonApi
constructor
A new instance of JsonApi.
- #path(r, h = {}) ⇒ Object
- #post(r, h = {}) ⇒ Object
Constructor Details
#initialize(u) ⇒ JsonApi
Returns a new instance of JsonApi.
65 66 67 68 |
# File 'lib/z4ai.rb', line 65 def initialize u @url = u @faraday = Faraday.new(url: u) end |
Instance Method Details
#[](k) ⇒ Object
75 76 77 |
# File 'lib/z4ai.rb', line 75 def [] k get(k) end |
#get(r, h = {}) ⇒ Object
78 79 80 |
# File 'lib/z4ai.rb', line 78 def get r, h={} JSON.parse(Faraday.get(path(r,h)).body) end |
#path(r, h = {}) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/z4ai.rb', line 69 def path r, h={} a = []; h.each_pair {|k,v| if v.class == Array; a << %[#{k}=#{v.join(",")}]; else a << %[#{k}=#{v}]; end } x = %[#{@url}/#{r}?#{a.join("&")}] # puts x return x end |
#post(r, h = {}) ⇒ Object
81 82 83 |
# File 'lib/z4ai.rb', line 81 def post r, h={} JSON.parse(Faraday.post(path(r,h)).body) end |