Class: Marchex::Marchexapi
- Inherits:
-
Object
- Object
- Marchex::Marchexapi
- Defined in:
- lib/marchex.rb
Instance Method Summary collapse
- #account_list ⇒ Object
- #ad_custom_define(acc_id, field_number, field_name, field_type, field_values) ⇒ Object
- #ad_custom_set(acc_id, campaign_id, field_name, field_value) ⇒ Object
- #ad_forward_list(campaign_id) ⇒ Object
- #ad_record_status(campaign_id) ⇒ Object
- #call_search(opts = {}) ⇒ Object
- #client_ad_list(client_id, status = '') ⇒ Object
- #get_call(call_id) ⇒ Object
- #get_call_audio(call_id, audio_format) ⇒ Object
-
#initialize(u, p) ⇒ Marchexapi
constructor
RestClient.log = ‘stdout’ #Debugging API calls.
- #parse_json(response) ⇒ Object
- #user_list(account_id) ⇒ Object
- #user_permissions(user_id) ⇒ Object
Constructor Details
#initialize(u, p) ⇒ Marchexapi
RestClient.log = ‘stdout’ #Debugging API calls
16 17 18 19 |
# File 'lib/marchex.rb', line 16 def initialize(u, p) @url = 'https://userapi.voicestar.com/api/jsonrpc/1' $auth = 'Basic ' + Base64.encode64(u + ':' + p).chomp end |
Instance Method Details
#account_list ⇒ Object
22 23 24 25 |
# File 'lib/marchex.rb', line 22 def account_list() response = parse_json(RestClient.post(@url, {'jsonrpc' => '2.0', 'id' => '1', 'method' => 'acct.list', 'params' => [] }.to_json, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)) end |
#ad_custom_define(acc_id, field_number, field_name, field_type, field_values) ⇒ Object
56 57 58 59 |
# File 'lib/marchex.rb', line 56 def ad_custom_define(acc_id,field_number, field_name, field_type, field_values) response = parse_json(RestClient.post(@url, {'jsonrpc' => '2.0', 'id' => '1', 'method' => 'ad.custom.define', 'params' => [acc_id,field_number, field_name, field_type, field_values]}.to_json, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)) return response.body["result"] end |
#ad_custom_set(acc_id, campaign_id, field_name, field_value) ⇒ Object
61 62 63 64 |
# File 'lib/marchex.rb', line 61 def ad_custom_set(acc_id, campaign_id, field_name, field_value) response = parse_json(RestClient.post(@url, {'jsonrpc' => '2.0', 'id' => '1', 'method' => 'ad.custom.set', 'params' => [acc_id,campaign_id, field_name, field_value]}.to_json, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)) return response.body["result"] end |
#ad_forward_list(campaign_id) ⇒ Object
37 38 39 |
# File 'lib/marchex.rb', line 37 def ad_forward_list(campaign_id) response = parse_json(RestClient.post(@url, {'jsonrpc' => '2.0', 'id' => '1', 'method' => 'ad.forw.list', 'params' => [campaign_id]}.to_json, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)) end |
#ad_record_status(campaign_id) ⇒ Object
41 42 43 44 |
# File 'lib/marchex.rb', line 41 def ad_record_status(campaign_id) response = parse_json(RestClient.post(@url, {'jsonrpc' => '2.0', 'id' => '1', 'method' => 'ad.recordcall.get', 'params' => [campaign_id]}.to_json, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)) return response.body["result"] end |
#call_search(opts = {}) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/marchex.rb', line 66 def call_search ( opts = {}) = {} [:start] = opts[:start] if opts[:start] [:end] = opts[:end] if opts[:end] [:assto] = opts[:assto] if opts[:assto] [:call_boundary] = opts[:call_boundary] if opts[:call_boundary] [:callerid] = opts[:callerid] if opts[:callerid] [:cmpid] = opts[:cmpid] if opts[:cmpid] [:dispo] = opts[:dispo] if opts[:dispo] [:dna_class] = opts[:dna_class] if opts[:dna_class] [:exact_times] = opts[:exact_times] if opts[:exact_times] [:extended] = opts[:extended] if opts[:extended] [:exact_times] = true if opts[:extended] == true [:grpid] = opts[:grpid] if opts[:grpid] [:include_dna] = opts[:include_dna] if opts[:include_dna] [:include_spotted_keywords] = opts[:include_spotted_keywords] if opts[:include_spotted_keywords] [:keyword] = opts[:keyword] if opts[:keyword] [:min_duration_secs] = opts[:min_duration_secs] if opts[:min_duration_secs] [:status] = opts[:status] if opts[:status] [:spotted_keywords] = opts[:spotted_keywords] if opts[:spotted_keywords] [:subacct] = opts[:subacct] if opts[:subacct] response = parse_json(RestClient.post(@url, {'jsonrpc' => '2.0', 'id' => '1', 'method' => 'call.search', 'params' => [opts[:acct_id], ]}.to_json, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)) return response.body["result"] end |
#client_ad_list(client_id, status = '') ⇒ Object
27 28 29 30 |
# File 'lib/marchex.rb', line 27 def client_ad_list(client_id, status ='') response = parse_json(RestClient.post(@url, {'jsonrpc' => '2.0', 'id' => '1', 'method' => 'ad.list.all', 'params' => [client_id, {'status' => status.downcase}]}.to_json, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)) end |
#get_call(call_id) ⇒ Object
91 92 93 94 |
# File 'lib/marchex.rb', line 91 def get_call (call_id) response = parse_json(RestClient.post(@url, {'jsonrpc' => '2.0', 'id' => '1', 'method' => 'call.get', 'params' => [call_id]}.to_json, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)) return response.body["result"] end |
#get_call_audio(call_id, audio_format) ⇒ Object
96 97 98 99 |
# File 'lib/marchex.rb', line 96 def get_call_audio(call_id, audio_format) response = parse_json(RestClient.post(@url, {'jsonrpc' => '2.0', 'id' => '1', 'method' => 'call.audio', 'params' => [call_id, audio_format]}.to_json, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)) return response.body["result"] end |
#parse_json(response) ⇒ Object
32 33 34 35 |
# File 'lib/marchex.rb', line 32 def parse_json(response) body = JSON.parse(response.to_str) if response.code == 200 OpenStruct.new(code: response.code, body: body) end |
#user_list(account_id) ⇒ Object
46 47 48 49 |
# File 'lib/marchex.rb', line 46 def user_list(account_id) response = parse_json(RestClient.post(@url, {'jsonrpc' => '2.0', 'id' => '1', 'method' => 'user.list', 'params' => [account_id]}.to_json, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)) return response.body["result"] end |
#user_permissions(user_id) ⇒ Object
51 52 53 54 |
# File 'lib/marchex.rb', line 51 def (user_id) response = parse_json(RestClient.post(@url, {'jsonrpc' => '2.0', 'id' => '1', 'method' => 'user.permissions.get', 'params' => [user_id]}.to_json, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)) return response.body["result"] end |