Module: Connectify
- Defined in:
- lib/connectify.rb,
lib/connectify/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
- .connection ⇒ Object
- .path_for(uri, path, format) ⇒ Object
- .request(uri, path, format = "json", type = "GET", params = {}) ⇒ Object
Instance Method Summary collapse
Class Method Details
.connection ⇒ Object
28 29 30 31 32 33 |
# File 'lib/connectify.rb', line 28 def self.connection @connection = Faraday.new(:url => @request_uri) do |faraday| faraday.request :url_encoded faraday.adapter Faraday.default_adapter end end |
.path_for(uri, path, format) ⇒ Object
24 25 26 |
# File 'lib/connectify.rb', line 24 def self.path_for uri, path, format @request_uri = uri + path + ".#{format}" end |
.request(uri, path, format = "json", type = "GET", params = {}) ⇒ Object
5 6 7 8 9 |
# File 'lib/connectify.rb', line 5 def self.request uri, path, format="json", type="GET", params={} path_for uri, path, format resp = response type, params JSON.parse(resp) end |
Instance Method Details
#response(type, params) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/connectify.rb', line 11 def response type, params @response = case type when "POST" connection.post "", params when "PUT" connection.put "", params when "DELETE" connection.delete "", params else connection.get "", params end end |