Class: Poke::API::RequestBuilder

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/poke-api/request_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

formatter=, log_level=, #logger

Constructor Details

#initialize(auth, pos, endpoint, http_client) ⇒ RequestBuilder

Returns a new instance of RequestBuilder.



9
10
11
12
13
14
15
16
# File 'lib/poke-api/request_builder.rb', line 9

def initialize(auth, pos, endpoint, http_client)
  @access_token = auth.access_token
  @provider     = auth.provider
  @endpoint     = endpoint
  @position     = pos
  @client       = http_client ? http_client : HTTPClient.new
  @start_time   = Helpers.fetch_time
end

Instance Attribute Details

#positionObject (readonly)

Returns the value of attribute position.



7
8
9
# File 'lib/poke-api/request_builder.rb', line 7

def position
  @position
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



7
8
9
# File 'lib/poke-api/request_builder.rb', line 7

def start_time
  @start_time
end

Instance Method Details

#request(reqs, client) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/poke-api/request_builder.rb', line 18

def request(reqs, client)
  logger.debug '[+] Creating new request'
  request_proto = build_main_request(reqs, client)

  logger.debug "[+] Generated RPC protobuf encoded request \r\n#{request_proto.inspect}"
  logger.info '[+] Executing RPC request'

  resp = execute_rpc_request(request_proto)
  resp = Response.new(resp.body, reqs)

  resp.decode(client)
  resp
end