Class: MyInfo::V3::Api

Inherits:
Object
  • Object
show all
Extended by:
Callable
Defined in:
lib/myinfo/v3/api.rb

Overview

Base API class

Direct Known Subclasses

Person, PersonBasic, Token

Instance Method Summary collapse

Instance Method Details

#callObject



24
25
26
27
28
# File 'lib/myinfo/v3/api.rb', line 24

def call
  yield
rescue StandardError => e
  Response.new(success: false, data: e)
end

#endpointObject

Raises:

  • (NotImplementedError)


12
13
14
# File 'lib/myinfo/v3/api.rb', line 12

def endpoint
  raise NotImplementedError, 'abstract'
end

#header(params:, access_token: nil) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/myinfo/v3/api.rb', line 38

def header(params:, access_token: nil)
  {
    'Content-Type' => 'application/json',
    'Accept' => 'application/json',
    'Cache-Control' => 'no-cache'
  }.tap do |values|
    values['Authorization'] = auth_header(params: params, access_token: access_token) unless config.sandbox?

    if support_gzip?
      values['Accept-Encoding'] = 'gzip'
      values['Content-Encoding'] = 'gzip'
    end
  end
end

#http_methodObject



30
31
32
# File 'lib/myinfo/v3/api.rb', line 30

def http_method
  'GET'
end

#params(_args) ⇒ Object

Raises:

  • (NotImplementedError)


16
17
18
# File 'lib/myinfo/v3/api.rb', line 16

def params(_args)
  raise NotImplementedError, 'abstract'
end

#parse_response(response) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/myinfo/v3/api.rb', line 53

def parse_response(response)
  if response.code == '200'
    yield
  elsif errors.include?(response.code)
    json = JSON.parse(response.body)

    Response.new(success: false, data: "#{json['code']} - #{json['message']}")
  else
    Response.new(success: false, data: "#{response.code} - #{response.body}")
  end
rescue StandardError => e
  Response.new(success: false, data: e)
end

#slugObject



20
21
22
# File 'lib/myinfo/v3/api.rb', line 20

def slug
  ''
end

#support_gzip?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/myinfo/v3/api.rb', line 34

def support_gzip?
  false
end