Class: Reattract::Request

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

Overview

Makes requests using the Connection object

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, bearer_token: generate_bearer) ⇒ Request

Returns a new instance of Request.



8
9
10
11
12
13
# File 'lib/reattract/request.rb', line 8

def initialize(path:, bearer_token: generate_bearer)
  @connection = Reattract::Connection.new(
    authorization: authorization(bearer_token),
    path:          path
  )
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



6
7
8
# File 'lib/reattract/request.rb', line 6

def connection
  @connection
end

Instance Method Details

#get(query: {}, pagination: nil, sort: nil) ⇒ Object



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

def get(query: {}, pagination: nil, sort: nil)
  if pagination
    query[:page]  = pagination[:page]
    query[:limit] = pagination[:limit]
  end
  query[:s] = sort if sort
  connection.get(query: query)
end

#patch(body: {}) ⇒ Object



24
25
26
# File 'lib/reattract/request.rb', line 24

def patch(body: {})
  connection.patch(body: body)
end

#post(body: {}) ⇒ Object



28
29
30
# File 'lib/reattract/request.rb', line 28

def post(body: {})
  connection.post(body: body)
end

#put(body: {}) ⇒ Object



32
33
34
# File 'lib/reattract/request.rb', line 32

def put(body: {})
  connection.put(body: body)
end