-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.rb
72 lines (64 loc) · 2.15 KB
/
client.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
require File.join(File.dirname(__FILE__), 'requester')
require 'spreadsheet'
require 'yaml'
require 'yajl'
#Load HasOffers config details
@config = YAML.load_file("config.yaml")
@hasoffers_api_url = @config["config"]["api_url"]
@network_id = @config["config"]["network_id"]
@network_token = @config["config"]["network_token"]
#Create xls result file
@result = Spreadsheet::Workbook.new
@sheet1 = @result.create_worksheet
@sheet1.name = 'Payout Comparison between HasOffers and AMS'
@sheet1.row(0).concat %w{LandingPageID HasOffersID ENABLED AMS_VALUE AMS_CURRENCY HO_PAYOUT HO_CURRENCY}
row_counter = 1
#Read xls file with information from SP database about landing pages
#Read Excel File
Spreadsheet.open('landing_pages.xls') do |book|
book.worksheet('Sheet1').each do |row|
break if row[0].nil?
next if row[1] == "AFFILIATE_OFFER_ID"
response = Requester.make_request(
@hasoffers_api_url,
{
"Format" => "json",
"Service" => "HasOffers",
"Version" => "2",
"NetworkId" => "#{@network_id}",
"NetworkToken" => "#{@network_token}",
"Target" => "Offer",
"Method" => "findById",
"id" => "#{row[1]}"
},
:get
)
json = StringIO.new("#{response}")
parser = Yajl::Parser.new
hash = parser.parse(json)
if hash["response"]["data"].nil?
excel_row = @sheet1.row(row_counter)
excel_row[0] = row[0]
excel_row[1] = row[1]
excel_row[2] = row[2]
excel_row[3] = row[3]
excel_row[4] = row[4]
excel_row[5] = "No data"
excel_row[6] = "No data"
else
next if hash["response"]["data"]["Offer"]["status"] == 'deleted'
payout = hash["response"]["data"]["Offer"]["default_payout"]
currency = hash["response"]["data"]["Offer"]["currency"]
excel_row = @sheet1.row(row_counter)
excel_row[0] = row[0]
excel_row[1] = row[1]
excel_row[2] = row[2]
excel_row[3] = row[3]
excel_row[4] = row[4]
excel_row[5] = payout
excel_row[6] = currency
end
row_counter += 1
end
end
@result.write 'result.xls'