Class: Enklawa::Api::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/enklawa/api/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResponse

Returns a new instance of Response.



6
7
8
9
10
# File 'lib/enklawa/api/response.rb', line 6

def initialize
  @programs   = []
  @threads    = []
  @categories = []
end

Instance Attribute Details

#phoneObject

Returns the value of attribute phone.



4
5
6
# File 'lib/enklawa/api/response.rb', line 4

def phone
  @phone
end

#radioObject

Returns the value of attribute radio.



4
5
6
# File 'lib/enklawa/api/response.rb', line 4

def radio
  @radio
end

#skypeObject

Returns the value of attribute skype.



4
5
6
# File 'lib/enklawa/api/response.rb', line 4

def skype
  @skype
end

Instance Method Details

#<<(program) ⇒ Object



16
17
18
# File 'lib/enklawa/api/response.rb', line 16

def <<(program)
  @programs << program
end

#add_category(category) ⇒ Object



20
21
22
# File 'lib/enklawa/api/response.rb', line 20

def add_category(category)
  @categories << category
end

#add_thread(category) ⇒ Object



24
25
26
# File 'lib/enklawa/api/response.rb', line 24

def add_thread(category)
  @threads << category
end

#programsObject



12
13
14
# File 'lib/enklawa/api/response.rb', line 12

def programs
  @programs
end

#save(filename) ⇒ Object



41
42
43
44
# File 'lib/enklawa/api/response.rb', line 41

def save(filename)
  json = JSON.pretty_generate(to_h)
  File.open(filename, "w") { |f| f.write json }
end

#to_hObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/enklawa/api/response.rb', line 28

def to_h
  {
    version: VERSION,
    skype: skype,
    build: Time.now.to_s,
    phone: phone,
    radio: radio,
    forum: @threads.map(&:to_h),
    categories: @categories.map(&:to_h),
    programs: @programs.map(&:to_h)
  }
end