class Obzvonilka::Api::Voice
Public Class Methods
new(api_key = nil)
click to toggle source
# File lib/obzvonilka/api/voice.rb, line 7 def initialize(api_key = nil) @api_key = api_key || ENV['OBZVONILKA_API_KEY'] @app_host = ENV['OBZVONILKA_APP_HOST'] || 'https://obzvonilka.ru' end
Public Instance Methods
find_contact(phone, started_at, unique_id)
click to toggle source
# File lib/obzvonilka/api/voice.rb, line 12 def find_contact(phone, started_at, unique_id) JSON.parse RestClient.get("#{@app_host}/api/get_voice_record_info", :params => {:api_key => @api_key, :phone_number => phone, :started_at => started_at, :unique_id => unique_id }) rescue RestClient::ResourceNotFound => e return {'code' => 2} end
put_voice(phone, started_at, finished_at, file_name, unique_id)
click to toggle source
# File lib/obzvonilka/api/voice.rb, line 35 def put_voice(phone, started_at, finished_at, file_name, unique_id) json = find_contact(phone, started_at, unique_id) if json['code'].zero? upload_file json['id'], phone, started_at, finished_at, file_name, unique_id, json['call_history_id'] end end
upload_file(id, phone_number, started_at, finished_at, file_name, unique_id, call_history_id)
click to toggle source
# File lib/obzvonilka/api/voice.rb, line 23 def upload_file(id, phone_number, started_at, finished_at, file_name, unique_id, call_history_id) RestClient.post "#{@app_host}/api/upload_voice_record", :api_key => @api_key, :id => id, :voice_data => {:started_at => started_at, :finished_at => finished_at, :phone_number => phone_number, :data => File.open(file_name), :unique_id => unique_id, :call_history_id => call_history_id} end