Class: Reattract::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/reattract/connection.rb

Overview

Handles the construction of the connection object

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(authorization:, path:) ⇒ Connection

Returns a new instance of Connection.



10
11
12
13
14
# File 'lib/reattract/connection.rb', line 10

def initialize(authorization:, path:)
  @resource_uri = build_uri
  @resource_uri.path += path
  @authorization = authorization
end

Instance Attribute Details

#authorizationObject (readonly)

Returns the value of attribute authorization.



8
9
10
# File 'lib/reattract/connection.rb', line 8

def authorization
  @authorization
end

#resource_uriObject (readonly)

Returns the value of attribute resource_uri.



8
9
10
# File 'lib/reattract/connection.rb', line 8

def resource_uri
  @resource_uri
end

Instance Method Details

#get(query: {}) ⇒ Object



16
17
18
19
20
21
# File 'lib/reattract/connection.rb', line 16

def get(query: {})
  resource_uri.query = query.to_query
  request = build_request(Net::HTTP::Get)

  make_request(request)
end

#patch(body: {}) ⇒ Object



23
24
25
26
27
# File 'lib/reattract/connection.rb', line 23

def patch(body: {})
  request = build_request(Net::HTTP::Patch, body: body)

  make_request(request)
end

#post(body: {}) ⇒ Object



35
36
37
38
39
# File 'lib/reattract/connection.rb', line 35

def post(body: {})
  request = build_request(Net::HTTP::Post, body: body)

  make_request(request)
end

#put(body: {}) ⇒ Object



29
30
31
32
33
# File 'lib/reattract/connection.rb', line 29

def put(body: {})
  request = build_request(Net::HTTP::Put, body: body)

  make_request(request)
end