-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathchartboost.rb
40 lines (34 loc) · 1.17 KB
/
chartboost.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
class AdtekioAdnetworks::Cost::Chartboost
include AdtekioAdnetworks::CostImport
define_required_credentials do
[:user_id, :signature]
end
def campaign_costs(from, till)
uri = Addressable::URI.
parse("https://analytics.chartboost.com/v3/metrics/campaign")
uri.query_values = {
:userId => credentials.user_id,
:userSignature => credentials.signature,
:dateMin => from.strftime("%Y-%m-%d"),
:dateMax => till.strftime("%Y-%m-%d"),
}
req = Net::HTTP::Get.new(uri.request_uri)
res = Net::HTTP.start(uri.host, uri.port) do |http|
http.request(req)
end
raise 'could not load report' if res.code.to_i != 200
JSON(res.body).reject do |a|
a["moneySpent"].to_f == 0.00
end.map do |campaign|
{
:date => Date.parse(campaign['dt']),
:campaign => campaign["campaign"],
:adgroup => :banner,
:impressions => campaign['impressionsReceived'].to_i,
:clicks => campaign['clicksReceived'].to_i,
:conversions => campaign['installReceived'].to_i,
:amount => campaign['moneySpent'].to_f
}
end.compact
end
end