Class: Nanowrimo::Core

Inherits:
Object
  • Object
show all
Defined in:
lib/nanowrimo/core.rb

Overview

Core load methods

Direct Known Subclasses

Genre, Region, Site, User

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorObject

attribute for storing error message returned by WCAPI on any response.



7
8
9
# File 'lib/nanowrimo/core.rb', line 7

def error
  @error
end

Instance Method Details

#has_error?Boolean

Tells us if the current object has any errors from the WCAPI

Returns:

  • (Boolean)


36
37
38
# File 'lib/nanowrimo/core.rb', line 36

def has_error?
  !error.nil?
end

#load(options = {}) ⇒ Object

Returns the values for all attributes for a given WCAPI type

Options:

  • :force - if set to true, will force Nanowrimo data to be pulled from the WCAPI and ignore cache data. not really recommended for bandwidth reasons.



14
15
16
17
18
19
20
21
# File 'lib/nanowrimo/core.rb', line 14

def load(options={})

  attribs = Nanowrimo.parse(load_field,id,self.class::FIELDS,options).first
  self.error = attribs[:error]
  self.class::FIELDS.each do |attrib|
    self.send(:"#{attrib}=", attribs[attrib.intern])
  end
end

#load_history(options = {}) ⇒ Object

Returns the values for all attributes for a given WCAPI type’s history

Options:

  • :force - if set to true, will force Nanowrimo data to be pulled from the WCAPI and ignore cache data. not really recommended for bandwidth reasons.



28
29
30
31
32
33
# File 'lib/nanowrimo/core.rb', line 28

def load_history(options={})
  self.history = Nanowrimo.parse(load_history_field,id,self.class::HISTORY_FIELDS,options)
  if maybe_error = self.history.first
    self.error = maybe_error[:error]
  end
end