class Marchex::Marchexapi

Public Class Methods

new(u, p) click to toggle source
# 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

Public Instance Methods

account_list() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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
client_ad_list(client_id, status ='') click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/marchex.rb, line 51
def user_permissions(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