Class: SyoboiCalendar::Responses::BaseResponse

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/syoboi_calendar/responses/base_response.rb

Instance Method Summary collapse

Constructor Details

#initialize(faraday_response) ⇒ BaseResponse



7
8
9
# File 'lib/syoboi_calendar/responses/base_response.rb', line 7

def initialize(faraday_response)
  @faraday_response = faraday_response
end

Instance Method Details

#bodyString



12
13
14
# File 'lib/syoboi_calendar/responses/base_response.rb', line 12

def body
  faraday_response.body
end

#codeInteger



17
18
19
# File 'lib/syoboi_calendar/responses/base_response.rb', line 17

def code
  body[response_key]["Result"]["Code"].to_i
end

#each(&block) ⇒ Object

Note:

Implementation for Enumerable



22
23
24
# File 'lib/syoboi_calendar/responses/base_response.rb', line 22

def each(&block)
  resources.each(&block)
end

#has_error?Boolean



27
28
29
# File 'lib/syoboi_calendar/responses/base_response.rb', line 27

def has_error?
  code != 200
end

#headersFaraday::Utils::Headers



32
33
34
# File 'lib/syoboi_calendar/responses/base_response.rb', line 32

def headers
  faraday_response.headers
end

#messageString?



37
38
39
# File 'lib/syoboi_calendar/responses/base_response.rb', line 37

def message
  body[response_key]["Result"]["Message"]
end

#resourcesArray<SyoboiCalendar::Resources::BaseResource>



42
43
44
45
46
# File 'lib/syoboi_calendar/responses/base_response.rb', line 42

def resources
  sources.map do |source|
    resource_class.new(source)
  end
end

#statusInteger



49
50
51
# File 'lib/syoboi_calendar/responses/base_response.rb', line 49

def status
  faraday_response.status
end