Module: Tr3llo::Client

Extended by:
Client
Included in:
Client
Defined in:
lib/3llo/client.rb

Defined Under Namespace

Classes: RequestError

Constant Summary collapse

BASE_URL =
"https://api.trello.com/1"

Instance Method Summary collapse

Instance Method Details

#get(path, params = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/3llo/client.rb', line 24

def get(path, params = {})
  uri = URI("#{BASE_URL}#{path}?#{query_string(params)}")

  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  request = Net::HTTP::Get.new(uri.request_uri)

  res = http.request(request)

  case res
  when Net::HTTPSuccess then res.body
  else raise(RequestError.new(res.body))
  end
end

#put(path, params) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/3llo/client.rb', line 40

def put(path, params)
  uri = URI("#{BASE_URL}#{path}?#{query_string(params)}")

  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  request = Net::HTTP::Put.new(uri.request_uri)

  res = http.request(request)

  case res
  when Net::HTTPOK then res.body
  else raise(RequestError.new(res.body))
  end
end