Class: Tinylinks::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/tinylinks/client.rb

Defined Under Namespace

Classes: ApiError

Instance Method Summary collapse

Constructor Details

#initialize(token: nil) ⇒ Client

Returns a new instance of Client.



19
20
21
# File 'lib/tinylinks/client.rb', line 19

def initialize(token: nil)
  @token = token
end

Instance Method Details

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



23
24
25
26
27
# File 'lib/tinylinks/client.rb', line 23

def get(path, params = {})
  uri = build_uri(path, params)
  request = Net::HTTP::Get.new(uri)
  execute(request)
end

#patch(path, body = {}) ⇒ Object



36
37
38
39
40
41
# File 'lib/tinylinks/client.rb', line 36

def patch(path, body = {})
  uri = build_uri(path)
  request = Net::HTTP::Patch.new(uri)
  request.body = JSON.generate(body)
  execute(request)
end

#post(path, body = {}) ⇒ Object



29
30
31
32
33
34
# File 'lib/tinylinks/client.rb', line 29

def post(path, body = {})
  uri = build_uri(path)
  request = Net::HTTP::Post.new(uri)
  request.body = JSON.generate(body)
  execute(request)
end