Class: NerdLog::Encounter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Encounter

Returns a new instance of Encounter.



6
7
8
# File 'lib/nerd_log/encounter.rb', line 6

def initialize(options = {})
  @http_connection = options.fetch(:http_connection, NerdLog.configuration.http_connection)
end

Instance Attribute Details

#http_connectionObject (readonly)

Returns the value of attribute http_connection.



5
6
7
# File 'lib/nerd_log/encounter.rb', line 5

def http_connection
  @http_connection
end

Instance Method Details

#encountersObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/nerd_log/encounter.rb', line 10

def encounters
  encounters = []

  fetch.body.each do |zone|
    zone['encounters'].each do |encounter|
      encounters << OpenStruct.new(zone_id: zone['id'],
                                   id: encounter['id'],
                                   name: encounter['name'])
    end
  end
  encounters
end

#fetchObject



23
24
25
26
27
# File 'lib/nerd_log/encounter.rb', line 23

def fetch
  response = http_connection.get("zones")

  response
end