Class: NextcallerClient::Client
- Inherits:
-
Object
- Object
- NextcallerClient::Client
- Defined in:
- lib/nextcaller_client/client.rb
Overview
The NextCaller API client
Instance Attribute Summary collapse
-
#auth ⇒ Object
Returns the value of attribute auth.
Instance Method Summary collapse
-
#get_by_phone(phone, debug = false) ⇒ Object
Get profiles by phone arguments: phone – 10 digits phone, str ot int, required debug – boolean (default false).
-
#get_by_profile_id(profile_id, debug = false) ⇒ Object
Get profile by id arguments: profile_id – Profile identifier, required debug – boolean (default false).
-
#initialize(api_key, api_secret) ⇒ Client
constructor
A new instance of Client.
-
#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).
Constructor Details
#initialize(api_key, api_secret) ⇒ Client
Returns a new instance of Client.
7 8 9 10 |
# File 'lib/nextcaller_client/client.rb', line 7 def initialize(api_key, api_secret) auth = {username: api_key, password: api_secret} @transport = Transport.new(auth, DEFAULT_USER_AGENT) end |
Instance Attribute Details
#auth ⇒ Object
Returns the value of attribute auth.
5 6 7 |
# File 'lib/nextcaller_client/client.rb', line 5 def auth @auth end |
Instance Method Details
#get_by_phone(phone, debug = false) ⇒ Object
Get profiles by phone arguments:
phone -- 10 digits phone, str ot int, required
debug -- boolean (default false)
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/nextcaller_client/client.rb', line 17 def get_by_phone(phone, debug=false) method = 'GET' Utils.validate_phone(phone) url_params = { phone: phone, format: JSON_RESPONSE_FORMAT } url = Utils.prepare_url('records', url_params) response = @transport.make_http_request(url, method, debug) if block_given? yield response else JSON.parse(response.body) end end |
#get_by_profile_id(profile_id, debug = false) ⇒ Object
Get profile by id arguments:
profile_id -- Profile identifier, required
debug -- boolean (default false)
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/nextcaller_client/client.rb', line 40 def get_by_profile_id(profile_id, debug=false) method = 'GET' url_params = { format: JSON_RESPONSE_FORMAT } url = Utils.prepare_url('users/%s/' % profile_id, url_params) response = @transport.make_http_request(url, method, debug) if block_given? yield response else JSON.parse(response.body) 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)
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/nextcaller_client/client.rb', line 62 def update_by_profile_id(profile_id, data, debug=false) method = 'POST' url_params = { format: JSON_RESPONSE_FORMAT } url = Utils.prepare_url('users/%s/' % profile_id, url_params) data = Utils.prepare_json_data(data) response = @transport.make_http_request(url, method, debug, data) if block_given? yield response else response end end |