Class: DmtdVbmappData::RequestHelpers

Inherits:
Object
  • Object
show all
Defined in:
lib/dmtd_vbmapp_data/request_helpers.rb

Class Method Summary collapse

Class Method Details

.get_authorized(opts = {}) ⇒ Object

GET an authorized message from the vbmappdata server

Params:

end_point

The end point to post

params

The parameters to send to the end point (may be nil)

client_id

The client id under which to record the post (may be nil)

client_code

The client code under which to record the post (may be nil)

language

The language to fetch (may be nil)



16
17
18
19
20
21
22
23
24
# File 'lib/dmtd_vbmapp_data/request_helpers.rb', line 16

def self.get_authorized(opts = {})
  end_point = opts.fetch(:end_point)
  params = opts.fetch(:params, nil)
  client_id = opts.fetch(:client_id, nil)
  client_code = opts.fetch(:client_code, nil)
  language = opts.fetch(:language, nil)

  get url(end_point), params, client_id, client_code, language
end

.post_authorized(opts = {}) ⇒ Object

POST an authorized message to the vbmappdata server

Params:

end_point

The end point to post

params

The parameters to send to the end point (may be nil)

client_id

The client id under which to record the post (may be nil)

client_code

The client code under which to record the post (may be nil)



33
34
35
36
37
38
39
40
# File 'lib/dmtd_vbmapp_data/request_helpers.rb', line 33

def self.(opts = {})
  end_point = opts.fetch(:end_point)
  params = opts.fetch(:params, nil)
  client_id = opts.fetch(:client_id, nil)
  client_code = opts.fetch(:client_code, nil)

  post url(end_point), params, client_id, client_code
end

.process_json_response(response) ⇒ Object

Process a JSON response from the server

Returns: { json: <json>, code: <response.code.to_i> }



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/dmtd_vbmapp_data/request_helpers.rb', line 46

def self.process_json_response(response)
  json = nil
  server_response_code = response.code.to_i

  if server_response_code == 200
    json_body = JSON.parse(response.body).symbolize_hash_keys
    json = json_body[:response]
  end

  { json: json, code: server_response_code }
end