Class: REQUESTER

Inherits:
Object
  • Object
show all
Defined in:
lib/SWGOH/API/CLIENT/requester.rb

Overview

Makes requests for the client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeREQUESTER

Returns a new instance of REQUESTER.



13
14
15
# File 'lib/SWGOH/API/CLIENT/requester.rb', line 13

def initialize
  @log = LOG.new
end

Instance Attribute Details

#logObject

Returns the value of attribute log.



11
12
13
# File 'lib/SWGOH/API/CLIENT/requester.rb', line 11

def log
  @log
end

Instance Method Details

#auth_request(username, password) ⇒ JSON || nil

Parameters:

  • username (String)
  • password (String)

Returns:

  • (JSON || nil)


20
21
22
23
24
25
# File 'lib/SWGOH/API/CLIENT/requester.rb', line 20

def auth_request(username, password)
  response = Net::HTTP.post_form(uri(SWGOH::API::PATH::AUTH_SIGNIN), auth_request_form(username, password))
  return @log.error(response) unless response.is_a?(Net::HTTPSuccess)

  JSON.parse(response.body)
end

#request(access_token, path, data) ⇒ JSON || nil

Parameters:

  • access_token (String)
  • path (PATH)
  • data (Hash)

Returns:

  • (JSON || nil)


31
32
33
34
35
36
# File 'lib/SWGOH/API/CLIENT/requester.rb', line 31

def request(access_token, path, data)
  response = Net::HTTP.post(uri(path), default_data.merge(data).to_json, request_headers(access_token))
  return @log.error(response) unless response.is_a?(Net::HTTPSuccess)

  JSON.parse(response.body)
end