-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmoboqo.rb
33 lines (28 loc) · 942 Bytes
/
moboqo.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
class AdtekioAdnetworks::Cost::Moboqo
include AdtekioAdnetworks::CostImport
define_required_credentials do
[:api_key]
end
def campaign_costs(from, till)
uri = Addressable::URI.parse("http://dashboard.moboqo.com/stats/stats.json")
uri.query_values = {
:api_key => credentials.api_key,
:start_date => from.strftime("%Y-%m-%d"),
:end_date => till.strftime("%Y-%m-%d"),
"group[0]" => "Stat.date",
"group[1]" => "Offer.name",
}
req = Net::HTTP::Get.new(uri.request_uri)
res = Net::HTTP.start(uri.host, uri.port) do |http|
http.request(req)
end
JSON.parse(res.body)['data'].map do |datapoint|
{
:date => Date.strptime(datapoint["date"], "%Y-%m-%d"),
:campaign => datapoint["offer"],
:conversions => datapoint['conversions'].to_i,
:amount => datapoint['cost'].gsub(/\$/, '').to_f
}
end
end
end