Class: FootStats::Resource

Inherits:
Object
  • Object
show all
Includes:
AttributeAccessor
Defined in:
lib/foot_stats/resource.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AttributeAccessor

#attributes, included

Constructor Details

#initialize(options = {}) ⇒ Resource

Waiting for ActiveModel::Model. =p



7
8
9
10
11
# File 'lib/foot_stats/resource.rb', line 7

def initialize(options={})
  options.each do |key, value|
    send("#{key}=", value) if respond_to?("#{key}=")
  end
end

Class Method Details

.parse_response(response) ⇒ String

Return response parsed data

Returns:

  • (String)

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/foot_stats/resource.rb', line 34

def self.parse_response(response)
  raise NotImplementedError, "need to implement .parse_response in #{self}."
end

.resource_keyString

Return the resource key that is fetch from the API response.

Returns:

  • (String)

Raises:

  • (NotImplementedError)


50
51
52
# File 'lib/foot_stats/resource.rb', line 50

def self.resource_key
  raise NotImplementedError, "need to implement .resource_key in #{self}."
end

.resource_nameString

Return the resource name to request to FootStats.

Returns:

  • (String)

Raises:

  • (NotImplementedError)


42
43
44
# File 'lib/foot_stats/resource.rb', line 42

def self.resource_name
  raise NotImplementedError, "need to implement .resource_name in #{self}."
end

.updated_response(response, options) ⇒ Array

Return parsed response if updated when requested updated data

Returns:

  • (Array)


17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/foot_stats/resource.rb', line 17

def self.updated_response(response, options)
  if options[:updated]
    if response.updated?
      response.readed
      parse_response response
    else
      []
    end
  else
    parse_response response
  end
end