Class: Entrata::Request::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/entrata/request/base.rb

Instance Method Summary collapse

Constructor Details

#initialize(conn:, **other_args) ⇒ Base

Returns a new instance of Base.



9
10
11
12
13
14
# File 'lib/entrata/request/base.rb', line 9

def initialize(conn:, **other_args)
  @conn = conn
  set_content_header!

  after_initialize(**other_args)
end

Instance Method Details

#after_initialize(**params) ⇒ Object

Initialization call back for subclasses init parameter access



17
18
19
# File 'lib/entrata/request/base.rb', line 17

def after_initialize(**params)
  # No-op, this method is a call back for subclasses
end

#bodyObject



64
65
66
67
68
69
70
71
72
# File 'lib/entrata/request/base.rb', line 64

def body
  {
    auth: resource_auth,
    method: {
      name: resource_name,
      params: resource_params
    }
  }.to_json
end

#performObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/entrata/request/base.rb', line 37

def perform
  response = conn.post(resource_path) do |request|
    request.body = body
  end

  result_hash = try_parsing_body(response.body)

  if response.success? && result_hash
    result_hash
  else
    error = create_response_error(response.body)
    raise error
  end
end

#perform_with_curlObject



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/entrata/request/base.rb', line 52

def perform_with_curl
  stdout, _stderr, status = Open3.capture3(curl_command,)
  result_hash = try_parsing_body(stdout)

  if status == 0 && result_hash
    result_hash
  else
    error = create_response_error(stdout)
    raise error
  end
end

#resource_authObject



29
30
31
# File 'lib/entrata/request/base.rb', line 29

def resource_auth
  { type: 'oauth' }
end

#resource_nameObject

Raises:

  • (NotImplementedError)


21
22
23
# File 'lib/entrata/request/base.rb', line 21

def resource_name
  raise NotImplementedError, 'implement with exact case of resource'
end

#resource_paramsObject



33
34
35
# File 'lib/entrata/request/base.rb', line 33

def resource_params
  {}
end

#resource_pathObject



25
26
27
# File 'lib/entrata/request/base.rb', line 25

def resource_path
  '/api/ils/internetlisting'
end