Module: DemoApi::ViewHelpers

Defined in:
lib/demo_api/view_helpers.rb

Constant Summary collapse

REQUEST_HEADER =
{'Content-Type' => 'application/json'}
SABEQ_URL =

SABEQ_URL = “sabeq.ps

"https://localhost:3001/"

Instance Method Summary collapse

Instance Method Details

#authorize(login_token) ⇒ Object

Authorize the request parameters: login_token return: true, auth_token in case of success

false, errors in case of failure, errors contain code and message


18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/demo_api/view_helpers.rb', line 18

def authorize()
  auth_link = SABEQ_URL + "/api/v1/auth"
  auth_json = { login_token:  }
  json_response = make_post_request(auth_link, auth_json)

  result, the_response = get_error_or_returned_value(json_response)
  if result
    return true, the_response["auth_token"]
  else
    return false, the_response
  end
end

#create_parcel(verification_token, name, phone1, phone2, content, payment_amount, area_id, address, delivery_notes) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/demo_api/view_helpers.rb', line 59

def create_parcel(verification_token, name, phone1, phone2, content,
                 payment_amount, area_id, address, delivery_notes)
  auth_link = SABEQ_URL + "/api/v1/parcels"
  auth_json = { verification_token: verification_token,
                name: name, phone1: phone1, phone2: phone2,
                content: content, payment_amount: payment_amount,
                area_id: area_id, address: address,
                delivery_notes: delivery_notes }
  json_response = make_post_request(auth_link, auth_json)

  return json_response
end

#get_areas(verification_token) ⇒ Object



52
53
54
55
56
57
# File 'lib/demo_api/view_helpers.rb', line 52

def get_areas(verification_token)
  auth_link = SABEQ_URL + "/api/v1/parcels/get_areas"
  auth_json = { verification_token: verification_token }
  json_response = make_get_request(auth_link, auth_json)
  return json_response
end


10
11
12
# File 'lib/demo_api/view_helpers.rb', line 10

def print_hello
  SABEQ_URL
end

#query_parcel(verification_token, parcel_number) ⇒ Object



45
46
47
48
49
50
# File 'lib/demo_api/view_helpers.rb', line 45

def query_parcel(verification_token, parcel_number)
  auth_link = SABEQ_URL + "/api/v1/parcels/#{parcel_number}"
  auth_json = { verification_token: verification_token }
  json_response = make_get_request(auth_link, auth_json)
  return json_response
end

#verify_profile(auth_token, profile_id, api_key) ⇒ Object

Verify the business profile



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/demo_api/view_helpers.rb', line 32

def verify_profile(auth_token, profile_id, api_key)
  auth_link = SABEQ_URL + "/api/v1/verify_business"
  auth_json = { auth_token: auth_token, profile_id: profile_id, api_key: api_key }
  json_response = make_post_request(auth_link, auth_json)

  result, the_response = get_error_or_returned_value(json_response)
  if result
    return true, the_response["verification_token"]
  else
    return false, the_response
  end
end