Class: Marchex::Marchexapi

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

Instance Method Summary collapse

Constructor Details

#initialize(u, p) ⇒ Marchexapi

Returns a new instance of Marchexapi.



15
16
17
18
# File 'lib/marchex.rb', line 15

def initialize(u, p)
  @url = 'https://userapi.voicestar.com/api/jsonrpc/1'
  $auth = 'Basic ' + Base64.encode64(u + ':' + p).chomp      
end

Instance Method Details

#account_listObject



21
22
23
24
# File 'lib/marchex.rb', line 21

def ()
  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



55
56
57
58
# File 'lib/marchex.rb', line 55

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_forward_list(campaign_id) ⇒ Object



36
37
38
# File 'lib/marchex.rb', line 36

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



40
41
42
43
# File 'lib/marchex.rb', line 40

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) ⇒ Object



26
27
28
29
# File 'lib/marchex.rb', line 26

def client_ad_list(client_id)
 response = parse_json(RestClient.post(@url, {'jsonrpc' => '2.0', 'id' => '1', 'method' => 'ad.list.all', 'params' => [client_id, {'status' => 'active'}]}.to_json, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth))

end

#parse_json(response) ⇒ Object



31
32
33
34
# File 'lib/marchex.rb', line 31

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



45
46
47
48
# File 'lib/marchex.rb', line 45

def user_list()
 response = parse_json(RestClient.post(@url, {'jsonrpc' => '2.0', 'id' => '1', 'method' => 'user.list', 'params' => []}.to_json, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth))
 return response.body["result"]
end

#user_permissions(user_id) ⇒ Object



50
51
52
53
# File 'lib/marchex.rb', line 50

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