Class: CompanionApi::Request

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

Constant Summary collapse

SQEX_AUTH_URI =
'https://secure.square-enix.com/oauth/oa/oauthauth'.freeze
SQEX_LOGIN_URI =
'https://secure.square-enix.com/oauth/oa/oauthlogin'.freeze
OAUTH_CALLBACK =
'https://companion.finalfantasyxiv.com/api/0/auth/callback'.freeze
URI =
'https://companion.finalfantasyxiv.com'.freeze
URI_SE =
'https://secure.square-enix.com'.freeze
VERSION =
'/sight-v060/sight'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Request

Returns a new instance of Request.

Raises:

  • (ComapnionApi::Error)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/companion_api/request.rb', line 15

def initialize(args = {})
  defaults = {
    version:   VERSION,
    endpoint:  nil,
    json:      nil,
    form:      nil,
    query:     nil,
    cookies:   nil,
    redirect:  true,
    return202: false,
  }

  @args = args.reverse_merge(defaults)

  raise ComapnionApi::Error, 'maximum redirects reached' if args[:redirects].to_i > 3

  @args[:version] = '' if @args[:uri].include?(URI_SE)

  @headers = {
    'Accept'          => '*/*',
    'Accept-Language' => 'en-gb',
    'Accept-Encoding' => 'br, gzip, deflate',
    'User-Agent'      => 'ffxivcomapp-e/1.0.5.0 CFNetwork/976 Darwin/18.2.0',
    'request-id'      => @args[:requestId] || CompanionApi.generate_uuid,
    'token'           => @args[:token],
  }

  @headers = @headers.reverse_merge(args[:headers]) if args[:headers].present?
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



11
12
13
# File 'lib/companion_api/request.rb', line 11

def args
  @args
end

#headersObject

Returns the value of attribute headers.



13
14
15
# File 'lib/companion_api/request.rb', line 13

def headers
  @headers
end

Instance Method Details

#get!Object



49
50
51
# File 'lib/companion_api/request.rb', line 49

def get!
  execute!(:get)
end

#post!Object



45
46
47
# File 'lib/companion_api/request.rb', line 45

def post!
  execute!(:post)
end