Class: HOALife::Client::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/hoalife/client/base.rb

Overview

Base class for all HTTP requests Handles the implementation specific code of the API

Direct Known Subclasses

Delete, Get, Post, Put

Instance Method Summary collapse

Constructor Details

#initialize(url, body = nil) ⇒ Base

Returns a new instance of Base.



10
11
12
13
# File 'lib/hoalife/client/base.rb', line 10

def initialize(url, body = nil)
  @url  = url
  @body = body
end

Instance Method Details

#jsonObject



19
20
21
# File 'lib/hoalife/client/base.rb', line 19

def json
  @json ||= JSON.parse(response.body)
end

#responseObject



23
24
25
# File 'lib/hoalife/client/base.rb', line 23

def response
  @response ||= validate_response!
end

#statusObject



15
16
17
# File 'lib/hoalife/client/base.rb', line 15

def status
  @status ||= response.code.to_i
end

#uriObject



27
28
29
# File 'lib/hoalife/client/base.rb', line 27

def uri
  @uri ||= URI::HTTPS.build(host: base_uri.host, path: request_uri.path, query: request_uri.query)
end