class Bizside::Redmine::ResultSet

Attributes

errors[R]
key[R]
rows[R]
status[R]

Public Class Methods

new(key, status, json_string = nil) click to toggle source
# File lib/bizside/redmine/result_set.rb, line 9
def initialize(key, status, json_string = nil)
  @key = key
  @status = status

  if json_string.present?
    json = ActiveSupport::JSON.decode(json_string.force_encoding('UTF-8'))
    @rows = key.present? ? json[key.to_s] : json
    @errors = json['errors']
  else
    warn(status)
  end

  @rows ||= []
end

Public Instance Methods

==(target) click to toggle source
# File lib/bizside/redmine/result_set.rb, line 24
def ==(target)
  self.key == target.key &&
    self.status == target.status &&
    self.rows == target.rows &&
    self.errors == target.errors
end
each() { |hash| ... } click to toggle source
# File lib/bizside/redmine/result_set.rb, line 31
def each
  rows.each do |hash|
    yield hash
  end
end

Private Instance Methods

warn(status) click to toggle source
# File lib/bizside/redmine/result_set.rb, line 39
def warn(status)
  case status
  when 200, 201
    return
  when 401
    message = "[Redmine] HTTP#{status}: API authentication failed."
  else
    message = "[Redmine] HTTP#{status}: An error has occurred."
  end

  if Bizside::Redmine::Client.logger
    Bizside::Redmine::Client.logger.warn message
  else
    puts message
  end
end