Class: RUBG::RubgEndpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/rubg/rubg_endpoint.rb

Direct Known Subclasses

Match, Player, PlayerCollection, Status

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ RubgEndpoint

Returns a new instance of RubgEndpoint.



5
6
7
8
9
10
11
12
13
# File 'lib/rubg/rubg_endpoint.rb', line 5

def initialize( args )
  args                  = self.class.defaults.merge(args)
  @errors               = args[:response]["errors"]
  @data                 = args[:response]["data"]
  @response_ts          = Time.parse(args[:response].headers['date']) if args[:response].headers['date']
  @ratelimit            = args[:response].headers['x-ratelimit-limit']
  @ratelimit_remaining  = args[:response].headers['x-ratelimit-remaining']
  @raw_response         = args[:response]
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/rubg/rubg_endpoint.rb', line 3

def data
  @data
end

#errorsObject (readonly)

Returns the value of attribute errors.



3
4
5
# File 'lib/rubg/rubg_endpoint.rb', line 3

def errors
  @errors
end

#ratelimitObject (readonly)

Returns the value of attribute ratelimit.



3
4
5
# File 'lib/rubg/rubg_endpoint.rb', line 3

def ratelimit
  @ratelimit
end

#ratelimit_remainingObject (readonly)

Returns the value of attribute ratelimit_remaining.



3
4
5
# File 'lib/rubg/rubg_endpoint.rb', line 3

def ratelimit_remaining
  @ratelimit_remaining
end

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



3
4
5
# File 'lib/rubg/rubg_endpoint.rb', line 3

def raw_response
  @raw_response
end

#response_tsObject (readonly)

Returns the value of attribute response_ts.



3
4
5
# File 'lib/rubg/rubg_endpoint.rb', line 3

def response_ts
  @response_ts
end

Class Method Details

.fetch(args) ⇒ Object

client,endpoint,shard={},query_params={}



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rubg/rubg_endpoint.rb', line 16

def self.fetch( args ) #client,endpoint,shard={},query_params={}
  args     = self.defaults.merge(args)
  
  uri      = assemble_uri({
    :shard          => args[:shard],
    :endpoint       => args[:endpoint],
    :lookup_id      => args[:lookup_id]
    })

  headers  = assemble_headers({
    :client         => args[:client]
    })

  query    = assemble_query({
    :client         => args[:client],
    :query_params  => args[:query_params]
    })

  @response = args[:client].class.get(uri,{headers: headers,
                                    query:  query})

  return @response
end