Class: NerdLog::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/nerd_log/report.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Report

Returns a new instance of Report.



4
5
6
7
8
9
# File 'lib/nerd_log/report.rb', line 4

def initialize(options)
  @realm           = options.fetch(:realm)
  @guild_name      = options.fetch(:guild_name)
  @region          = options.fetch(:region, 'US')
  @http_connection = options.fetch(:http_connection, NerdLog.configuration.http_connection)
end

Instance Attribute Details

#guild_nameObject (readonly)

Returns the value of attribute guild_name.



3
4
5
# File 'lib/nerd_log/report.rb', line 3

def guild_name
  @guild_name
end

#http_connectionObject (readonly)

Returns the value of attribute http_connection.



3
4
5
# File 'lib/nerd_log/report.rb', line 3

def http_connection
  @http_connection
end

#realmObject (readonly)

Returns the value of attribute realm.



3
4
5
# File 'lib/nerd_log/report.rb', line 3

def realm
  @realm
end

#regionObject (readonly)

Returns the value of attribute region.



3
4
5
# File 'lib/nerd_log/report.rb', line 3

def region
  @region
end

Instance Method Details

#fetchObject



20
21
22
23
24
# File 'lib/nerd_log/report.rb', line 20

def fetch
  response = http_connection.get("reports/guild/#{guild_name}/#{realm}/#{region}")

  response
end

#reportsObject



11
12
13
14
15
16
17
18
# File 'lib/nerd_log/report.rb', line 11

def reports
  reports = []
  fetch.body.each do |report|
    reports << OpenStruct.new(id: report['id'], title: report['title'],
                              zone: report['zone'], start_time: report['start'])
  end
  reports
end