Class: Trello::NetHttpClient
- Inherits:
-
Object
- Object
- Trello::NetHttpClient
- Defined in:
- lib/trello/net_http_client.rb
Instance Method Summary collapse
-
#initialize(base_uri) ⇒ NetHttpClient
constructor
A new instance of NetHttpClient.
- #perform(method, path, body = nil, headers = {}) ⇒ Object
Constructor Details
#initialize(base_uri) ⇒ NetHttpClient
Returns a new instance of NetHttpClient.
3 4 5 6 |
# File 'lib/trello/net_http_client.rb', line 3 def initialize(base_uri) @connection = Net::HTTP.new(base_uri.host, base_uri.port) @connection.use_ssl = true if base_uri.scheme == "https" end |
Instance Method Details
#perform(method, path, body = nil, headers = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/trello/net_http_client.rb', line 8 def perform(method, path, body = nil, headers = {}) raise unless [:get, :put, :post, :delete].include?(method) req = eval("Net::HTTP::#{method.capitalize}").new(path) req["Content-Type"] = "application/json" req.body = body resp = @connection.request(req) JSON.parse(resp.body) end |