Class: NextcallerClient::Client

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

Overview

The NextCaller API client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, api_secret) ⇒ Client

Returns a new instance of Client.



7
8
9
# File 'lib/test_nextcaller_client/client.rb', line 7

def initialize(api_key, api_secret)
  @auth = {username: api_key, password: api_secret}
end

Instance Attribute Details

#authObject

Returns the value of attribute auth.



5
6
7
# File 'lib/test_nextcaller_client/client.rb', line 5

def auth
  @auth
end

Instance Method Details

#get_by_phone(phone, response_format = JSON_RESPONSE_FORMAT, debug = false) ⇒ Object

Get profiles by phone arguments:

phone           -- 10 digits phone, str ot int, required
response_format -- response format [json|xml] (default json)
debug           -- boolean (default false)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/test_nextcaller_client/client.rb', line 18

def get_by_phone(phone, response_format=JSON_RESPONSE_FORMAT, debug=false)

  method = 'GET'
  NextcallerClient.validate_format(response_format)
  NextcallerClient.validate_phone(phone)
  url_params = {
      phone: phone,
      format: response_format
  }
  url = NextcallerClient.prepare_url('records', url_params)
  response = NextcallerClient.make_http_request(@auth, url, method, debug)

  if block_given?
    yield response
  else
    NextcallerClient.default_handle_response(response, response_format)
  end
end

#get_by_profile_id(profile_id, response_format = JSON_RESPONSE_FORMAT, debug = false) ⇒ Object

Get profile by id arguments:

profile_id      -- Profile identifier, required
response_format -- response format [json|xml] (default json)
debug           -- boolean (default false)


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/test_nextcaller_client/client.rb', line 44

def get_by_profile_id(profile_id, response_format=JSON_RESPONSE_FORMAT, debug=false)

  method = 'GET'
  NextcallerClient.validate_format(response_format)
  url_params = {
      format: response_format
  }
  url = NextcallerClient.prepare_url('users/%s/' % profile_id, url_params)
  response = NextcallerClient.make_http_request(@auth, url, method, debug)

  if block_given?
    yield response
  else
    NextcallerClient.default_handle_response(response, response_format)
  end
end

#update_by_profile_id(profile_id, data, debug = false) ⇒ Object

Update profile by id arguments:

profile_id      -- Profile identifier, required
data            -- dictionary with changed data, required
debug           -- boolean (default false)


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/test_nextcaller_client/client.rb', line 68

def update_by_profile_id(profile_id, data, debug=false)

  method = 'POST'
  url_params = {
      format: JSON_RESPONSE_FORMAT
  }
  url = NextcallerClient.prepare_url('users/%s/' % profile_id, url_params)
  data = NextcallerClient.prepare_json_data(data)
  response = NextcallerClient.make_http_request(@auth, url, method, debug, data)

  if block_given?
    yield response
  else
    response
  end
end