-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrevmob.rb
44 lines (38 loc) · 1.32 KB
/
revmob.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
class AdtekioAdnetworks::Cost::Revmob
include AdtekioAdnetworks::CostImport
define_required_credentials do
[:user_id, :auth_token]
end
def campaign_costs(from, till)
url = "https://www.revmobmobileadnetwork.com/api/v1/users"+
"/#{credentials.user_id}/auth/#{credentials.auth_token}/campaigns"+
"/report.json"
uri = Addressable::URI.parse(url)
uri.query_values = {
:startDate => from.strftime("%Y-%m-%d"),
:endDate => till.strftime("%Y-%m-%d"),
}
req = Net::HTTP::Get.new(uri.request_uri)
res = Net::HTTP.start(uri.host, uri.port, :use_ssl => true,
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
http.request(req)
end
raise 'could not load report' if res.code.to_i != 200
campaigns = JSON(res.body)["campaigns"]
campaigns.reject! do |camp|
camp["daily_activities"].detect {|x| x["spend"].to_f > 0}.nil?
end
campaigns.map do |camp|
camp["daily_activities"].map do |d|
{
:campaign => camp["name"],
:date => Date.parse(d["day"]),
:impressions => d["impressions"].to_i,
:clicks => d["clicks"].to_i,
:conversions => d["installs"].to_i,
:amount => d["spend"].to_f
}
end
end.flatten.compact
end
end