balihoo_lpc_client 0.2.0.pre → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +247 -5
- data/lib/balihoo_lpc_client/api.rb +53 -0
- data/lib/balihoo_lpc_client/configuration.rb +5 -4
- data/lib/balihoo_lpc_client/request/api_base.rb +56 -5
- data/lib/balihoo_lpc_client/request/authentication.rb +5 -5
- data/lib/balihoo_lpc_client/request/base.rb +4 -4
- data/lib/balihoo_lpc_client/request/campaigns.rb +2 -3
- data/lib/balihoo_lpc_client/request/campaigns_with_tactics.rb +2 -3
- data/lib/balihoo_lpc_client/request/metrics.rb +4 -4
- data/lib/balihoo_lpc_client/request/tactics.rb +22 -0
- data/lib/balihoo_lpc_client/request/website_metrics.rb +10 -0
- data/lib/balihoo_lpc_client/response/campaign.rb +2 -2
- data/lib/balihoo_lpc_client/response/metric.rb +1 -1
- data/lib/balihoo_lpc_client/response/tactic.rb +3 -3
- data/lib/balihoo_lpc_client/response/website_metric.rb +11 -0
- data/lib/balihoo_lpc_client/response/website_metric_leads.rb +15 -0
- data/lib/balihoo_lpc_client/response/website_metric_visits.rb +14 -0
- data/lib/balihoo_lpc_client/version.rb +1 -1
- data/lib/balihoo_lpc_client.rb +6 -1
- metadata +10 -5
- data/lib/balihoo_lpc_client/connection.rb +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8e2fcc6ac94fd1400fb46186ef93ed9033524fc
|
4
|
+
data.tar.gz: 927f056161496be58a5b38cb97f53bccfc9d9041
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acbcf8533b7e57780381e479a710e0a5d9b1b347c154d18fb38db328056e531944ef1855ee51a3ea52c7ae7b8b4dd24d88b2518373b6d97fca98b3d20a184938
|
7
|
+
data.tar.gz: 4b248eff98af0ec02d81c98df87c79b1dde93073db0089d212e245a34c4d9109e7350d2f5fbf06b85219ce585b95da6624a8ddfc1094eba1835bc4efbcd8377a
|
data/README.md
CHANGED
@@ -27,19 +27,261 @@ Or install it yourself as:
|
|
27
27
|
|
28
28
|
## Usage
|
29
29
|
|
30
|
-
|
30
|
+
Using the gem is quite simple.
|
31
|
+
|
32
|
+
### Configuration
|
33
|
+
|
34
|
+
First we must create a Configuration object.
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
opts = {
|
38
|
+
brand_key: 'brand_key',
|
39
|
+
api_key: 'api_key',
|
40
|
+
location_key: 'location_key', # optional more below
|
41
|
+
user_id: 'brand_key', # currently not used, Balihoo suggests setting same as brand_key
|
42
|
+
group_id: 'brand_key' # currently not used, Balihoo suggests setting same as brand_key
|
43
|
+
}
|
44
|
+
config = BalihooLpcClient::Configuration.create(opts)
|
45
|
+
```
|
46
|
+
|
47
|
+
The `location_key` is an optional parameter. When not given the api will require
|
48
|
+
an array of locations to be passed to the api endpoints. This is explained
|
49
|
+
further below.
|
50
|
+
|
51
|
+
### Initialization
|
52
|
+
|
53
|
+
Once we have the config created we can use that to create an instance of the Api
|
54
|
+
object and authenticate with Balihoo.
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
api = BalihooLpcClient::Api.new(config: config)
|
58
|
+
api.authenticate!
|
59
|
+
```
|
60
|
+
|
61
|
+
The `authenticate!` method will call out to Balihoo and set the `client_id` and
|
62
|
+
`client_api_key` on the config object for you.
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
config.client_id # => <client_id from Balihoo>
|
66
|
+
config.client_api_key # => <client_api_key from Balihoo>
|
67
|
+
```
|
68
|
+
|
69
|
+
Once we have authenticated we can begin to call the various endpoints.
|
70
|
+
|
71
|
+
### Endpoints
|
72
|
+
|
73
|
+
#### Common Options
|
74
|
+
|
75
|
+
There are a set of common options that can be sent to an endpoint. These are
|
76
|
+
always sent as the params argument to an endpoint.
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
api.campaigns(params: options)
|
80
|
+
```
|
81
|
+
|
82
|
+
The options are as follows:
|
83
|
+
|
84
|
+
- `from:` A start date to filter results, with the format `yyyy-mm-dd`
|
85
|
+
- `to:` An end date to filter results, with the format `yyyy-mm-dd`
|
86
|
+
- `locations:` An array of locations (Use location key). _*If location_key was
|
87
|
+
given during authentication this should not be used.*_
|
88
|
+
- `tactic_id:` Tactic id to filter results. Only supported with
|
89
|
+
`get_report_data` endpoint.
|
90
|
+
|
91
|
+
#### Campaigns
|
92
|
+
|
93
|
+
If you passed a `location_key` to the config then you can simply call
|
94
|
+
`campaigns` on the api object.
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
api.campaigns # => Array[Response::Campaign]
|
98
|
+
```
|
99
|
+
|
100
|
+
If the `location_key` was not passed then you must pass an array of locations to
|
101
|
+
get campaigns for.
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
# Single location requested
|
105
|
+
campaigns = api.campaigns(params: { locations: [1] })
|
106
|
+
campaigns # => Array[Response::Campaign]
|
107
|
+
|
108
|
+
# Multiple locations requested
|
109
|
+
campaigns = api.campaigns(params: { locations: [1,2] })
|
110
|
+
campaigns # => { "1" => Array[Response::Campaign], "2" => Array[Response::Campaign] }
|
111
|
+
```
|
112
|
+
|
113
|
+
#### Tactics
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
tactics = api.tactics(campaign_id: 1)
|
117
|
+
tactics # => Array[BalihooLpcClient::Response::Tactic]
|
118
|
+
|
119
|
+
# Without location_key using locations: param
|
120
|
+
# Single location requested
|
121
|
+
tactics = api.tactics(campaign_id: 1, params: { locations: [1] })
|
122
|
+
tactics # => Array[BalihooLpcClient::Response::Tactic]
|
123
|
+
|
124
|
+
# Multiple locations requested
|
125
|
+
tactics = api.tactics(campaign_id: 1, params: { locations: [1,2] })
|
126
|
+
tactics # => { "1" => Array[Response::Tactic], "2" => Array[Response::Tactic] }
|
127
|
+
```
|
128
|
+
|
129
|
+
#### Campaigns with Tactics
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
response = api.campaigns_with_tactics # => Array[BalihooLpcClient::Response::Campaign]
|
133
|
+
response.tactics # => Array[BalihooLpcClient::Response::Tactic]
|
134
|
+
|
135
|
+
# Without location_key using locations: param
|
136
|
+
# Single location requested
|
137
|
+
campaigns = api.campaigns_with_tactics(params: { locations: [1] })
|
138
|
+
campaigns # => Array[BalihooLpcClient::Response::Campaign]
|
139
|
+
campaigns.first.tactics # => Array[BalihooLpcClient::Response::Tactic]
|
140
|
+
|
141
|
+
# Multiple locations requested
|
142
|
+
campaigns = api.campaigns_with_tactics(params: { locations: [1,2] })
|
143
|
+
campaigns # => { "1" => Array[Response::Campaign], "2" => Array[Response::Campaign] }
|
144
|
+
```
|
145
|
+
|
146
|
+
#### Metrics
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
metrics = api.metrics(tactic_id: 1)
|
150
|
+
metrics # => Response::Metric
|
151
|
+
|
152
|
+
# Without location_key using locations: param
|
153
|
+
# Single location requested
|
154
|
+
metrics = api.metrics(tactic_id: 1, params: { locations: [1] })
|
155
|
+
metrics # => Response::Metric
|
156
|
+
|
157
|
+
# Multiple locations requested
|
158
|
+
metrics = api.metrics(tactic_id: 1, params: { locations: [1,2] })
|
159
|
+
metrics # => {"1" => Response::Metric, "2" => Response::Metric}
|
160
|
+
```
|
161
|
+
|
162
|
+
#### Website Metrics
|
163
|
+
|
164
|
+
```ruby
|
165
|
+
website_metrics = api.website_metrics
|
166
|
+
website_metrics # => Response::WebsiteMetric
|
167
|
+
|
168
|
+
# Without location_key using locations: param
|
169
|
+
# Single location requested
|
170
|
+
website_metrics = api.website_metrics(params: { locations: [1] })
|
171
|
+
website_metrics # => Response::WebsiteMetric
|
172
|
+
|
173
|
+
# Multiple locations requested
|
174
|
+
website_metrics = api.website_metrics(params: { locations: [1,2] })
|
175
|
+
website_metrics # => {"1" => Response::WebsiteMetric, "2" => Response::WebsiteMetric}
|
176
|
+
```
|
177
|
+
|
178
|
+
#### Report Data
|
179
|
+
|
180
|
+
**This endpoint has not been implemented.**
|
181
|
+
|
182
|
+
#### Profile Data
|
183
|
+
|
184
|
+
**This endpoint has not been implemented.**
|
185
|
+
|
186
|
+
### Response Objects
|
187
|
+
|
188
|
+
#### BalihooLpcClient::Response::Authentication
|
189
|
+
|
190
|
+
```ruby
|
191
|
+
auth.client_id # => String (GUID)
|
192
|
+
auth.client_api_key # => String (GUID)
|
193
|
+
```
|
194
|
+
|
195
|
+
#### BalihooLpcClient::Response::Campaign
|
196
|
+
|
197
|
+
```ruby
|
198
|
+
campaign.id # => Fixnum
|
199
|
+
campaign.title # => String
|
200
|
+
campaign.description # => String
|
201
|
+
campaign.start # => Date
|
202
|
+
campaign.end # => Date
|
203
|
+
campaign.status # => String
|
204
|
+
campaign.tactics # => Array[BalihooLpcClient::Response::Tactic]
|
205
|
+
```
|
206
|
+
|
207
|
+
_Note: `tactics` is only populated if `campaigns_with_tactics` is called._
|
208
|
+
|
209
|
+
#### BalihooLpcClient::Response::Tactic
|
210
|
+
|
211
|
+
```ruby
|
212
|
+
tactic.id # => Fixnum
|
213
|
+
tactic.title # => String
|
214
|
+
tactic.start # => Date
|
215
|
+
tactic.end # => Date
|
216
|
+
tactic.channel # => String
|
217
|
+
tactic.description # => String
|
218
|
+
tactic.creative # => String - this is a url
|
219
|
+
```
|
220
|
+
|
221
|
+
#### BalihooLpcClient::Response::Metric
|
222
|
+
|
223
|
+
```ruby
|
224
|
+
metric.tactic_ids # => Array[Int]
|
225
|
+
metric.channel # => String
|
226
|
+
metric.clicks # => Fixnum
|
227
|
+
metric.spend # Float
|
228
|
+
metric.impressions # => Fixnum
|
229
|
+
metric.ctr # Float
|
230
|
+
metric.avg_cpc # Float
|
231
|
+
metric.avg_cpm # Float
|
232
|
+
```
|
233
|
+
|
234
|
+
#### BalihooLpcClient::Response::WebsiteMetric
|
235
|
+
|
236
|
+
```ruby
|
237
|
+
website_metric.visits # => Response::WebsiteMetricVisits
|
238
|
+
website_metric.leads # => Response::WebsiteMetricLeads
|
239
|
+
```
|
240
|
+
|
241
|
+
#### BalihooLpcClient::Response::WebsiteMetricVisits
|
242
|
+
|
243
|
+
```ruby
|
244
|
+
visits.total # => Fixnum
|
245
|
+
visits.organic # => Fixnum
|
246
|
+
visits.direct # => Fixnum
|
247
|
+
visits.referral # => Fixnum
|
248
|
+
visits.paid # => Fixnum
|
249
|
+
visits.new_visits_percent # => Float
|
250
|
+
```
|
251
|
+
|
252
|
+
#### BalihooLpcClient::Response::WebsiteMetricLeads
|
253
|
+
|
254
|
+
```ruby
|
255
|
+
leads.total # => Fixnum
|
256
|
+
leads.total_web # => Fixnum
|
257
|
+
leads.total_phone # => Fixnum
|
258
|
+
leads.organic_web # => Fixnum
|
259
|
+
leads.paid_web # => Fixnum
|
260
|
+
leads.organic_phone # => Fixnum
|
261
|
+
leads.paid_phone # => Fixnum
|
262
|
+
```
|
31
263
|
|
32
264
|
## Development
|
33
265
|
|
34
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
266
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
267
|
+
`rake spec` to run the tests. You can also run `bin/console` for an interactive
|
268
|
+
prompt that will allow you to experiment.
|
35
269
|
|
36
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To
|
270
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
271
|
+
release a new version, update the version number in `version.rb`, and then run
|
272
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
273
|
+
git commits and tags, and push the `.gem` file to
|
274
|
+
[rubygems.org](https://rubygems.org).
|
37
275
|
|
38
276
|
## Contributing
|
39
277
|
|
40
|
-
Bug reports and pull requests are welcome on GitHub at
|
278
|
+
Bug reports and pull requests are welcome on GitHub at
|
279
|
+
https://github.com/riverock/balihoo_lpc. This project is intended to be a safe,
|
280
|
+
welcoming space for collaboration, and contributors are expected to adhere to
|
281
|
+
the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
41
282
|
|
42
283
|
|
43
284
|
## License
|
44
285
|
|
45
|
-
The gem is available as open source under the terms of the
|
286
|
+
The gem is available as open source under the terms of the
|
287
|
+
[MIT License](http://opensource.org/licenses/MIT).
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module BalihooLpcClient
|
2
|
+
class Api
|
3
|
+
attr_accessor :config
|
4
|
+
|
5
|
+
def initialize(config:)
|
6
|
+
self.config = config
|
7
|
+
end
|
8
|
+
|
9
|
+
def authenticate!
|
10
|
+
auth = Request::Authentication.new(api: self)
|
11
|
+
auth.authenticate!
|
12
|
+
end
|
13
|
+
|
14
|
+
def campaigns(params: {})
|
15
|
+
validate_params_and_fetch!(params: params, class: Request::Campaigns)
|
16
|
+
end
|
17
|
+
|
18
|
+
def tactics(campaign_id:, params: {})
|
19
|
+
validate_params_and_fetch!(params: params, campaign_id: campaign_id, class: Request::Tactics)
|
20
|
+
end
|
21
|
+
|
22
|
+
def campaigns_with_tactics(params: {})
|
23
|
+
validate_params_and_fetch!(params: params, class: Request::CampaignsWithTactics)
|
24
|
+
end
|
25
|
+
|
26
|
+
def metrics(tactic_id:, params: {})
|
27
|
+
validate_params_and_fetch!(params: params, tactic_id: tactic_id, class: Request::Metrics)
|
28
|
+
end
|
29
|
+
|
30
|
+
def website_metrics(params: {})
|
31
|
+
validate_params_and_fetch!(params: params, class: Request::WebsiteMetrics)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def validate_params_and_fetch!(**args)
|
37
|
+
locations = args[:params][:locations]
|
38
|
+
|
39
|
+
if config.location_key.nil? && locations.nil?
|
40
|
+
raise ApiOptionError, 'must give params[:locations] since no location_key given'
|
41
|
+
elsif config.location_key.nil? && !locations.is_a?(Array)
|
42
|
+
raise ApiOptionError, 'locations must be an array'
|
43
|
+
end
|
44
|
+
|
45
|
+
fetch(**args)
|
46
|
+
end
|
47
|
+
|
48
|
+
def fetch(**args)
|
49
|
+
klass = args.delete(:class)
|
50
|
+
klass.new(api: self, **args).fetch
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -3,14 +3,15 @@ module BalihooLpcClient
|
|
3
3
|
attr_accessor :api_base, :api_version, :brand_key, :api_key, :location_key,
|
4
4
|
:user_id, :group_id, :client_id, :client_api_key
|
5
5
|
|
6
|
-
def initialize
|
7
|
-
defaults.
|
6
|
+
def initialize(**args)
|
7
|
+
opts = defaults.merge(args)
|
8
|
+
opts.each do |k, v|
|
8
9
|
self.send("#{k}=", v)
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
12
|
-
def self.create
|
13
|
-
config = new
|
13
|
+
def self.create(**args)
|
14
|
+
config = new(**args)
|
14
15
|
yield config if block_given?
|
15
16
|
config
|
16
17
|
end
|
@@ -3,22 +3,73 @@ module BalihooLpcClient
|
|
3
3
|
class ApiBase < Base
|
4
4
|
attr_accessor :params
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
super(
|
6
|
+
def initialize(api:, params:)
|
7
|
+
super(api: api)
|
8
8
|
self.params = params
|
9
9
|
end
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
|
+
def multiple_locations?
|
14
|
+
if locations_expected?
|
15
|
+
params[:locations].count > 1
|
16
|
+
else
|
17
|
+
false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def locations_expected?
|
22
|
+
config.location_key.nil? || config.location_key.strip.empty?
|
23
|
+
end
|
24
|
+
|
13
25
|
def opts
|
14
26
|
{
|
15
27
|
headers: {
|
16
|
-
'X-ClientId' =>
|
17
|
-
'X-ClientApiKey' =>
|
28
|
+
'X-ClientId' => config.client_id,
|
29
|
+
'X-ClientApiKey' => config.client_api_key
|
18
30
|
},
|
19
|
-
query:
|
31
|
+
query: sanitized_params
|
20
32
|
}
|
21
33
|
end
|
34
|
+
|
35
|
+
def sanitized_params
|
36
|
+
if locations_expected?
|
37
|
+
sanitized = params.dup
|
38
|
+
sanitized[:locations] = sanitized[:locations].join(?,)
|
39
|
+
sanitized
|
40
|
+
else
|
41
|
+
params.delete(:locations)
|
42
|
+
params
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def handle_response(response:, klass:, mappable: true)
|
47
|
+
if multiple_locations?
|
48
|
+
multiple_locations(response: response, klass: klass, mappable: mappable)
|
49
|
+
else
|
50
|
+
single_location(response: response, klass: klass, mappable: mappable)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def multiple_locations(response:, klass:, mappable:)
|
55
|
+
response.inject({}) do |h, pair|
|
56
|
+
if mappable
|
57
|
+
h.merge({ pair[0] => pair[1].map { |v| klass.new(v) } })
|
58
|
+
else
|
59
|
+
h.merge({ pair[0] => klass.new(pair[1]) })
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def single_location(response:, klass:, mappable:)
|
65
|
+
if mappable
|
66
|
+
response.map do |result|
|
67
|
+
klass.new result
|
68
|
+
end
|
69
|
+
else
|
70
|
+
klass.new response
|
71
|
+
end
|
72
|
+
end
|
22
73
|
end
|
23
74
|
end
|
24
75
|
end
|
@@ -12,11 +12,11 @@ module BalihooLpcClient
|
|
12
12
|
def opts
|
13
13
|
{
|
14
14
|
query: {
|
15
|
-
brandKey:
|
16
|
-
apiKey:
|
17
|
-
locationKey:
|
18
|
-
userId:
|
19
|
-
groupId:
|
15
|
+
brandKey: api.config.brand_key,
|
16
|
+
apiKey: api.config.api_key,
|
17
|
+
locationKey: api.config.location_key,
|
18
|
+
userId: api.config.user_id,
|
19
|
+
groupId: api.config.group_id
|
20
20
|
}
|
21
21
|
}
|
22
22
|
end
|
@@ -3,17 +3,17 @@ module BalihooLpcClient
|
|
3
3
|
class Base
|
4
4
|
include HTTParty
|
5
5
|
|
6
|
-
attr_accessor :
|
6
|
+
attr_accessor :api
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
self.
|
8
|
+
def initialize(api:)
|
9
|
+
self.api = api
|
10
10
|
self.class.base_uri config.url
|
11
11
|
end
|
12
12
|
|
13
13
|
private
|
14
14
|
|
15
15
|
def config
|
16
|
-
|
16
|
+
api.config
|
17
17
|
end
|
18
18
|
|
19
19
|
def handle_errors_with(klass:, response:)
|
@@ -2,9 +2,8 @@ module BalihooLpcClient
|
|
2
2
|
module Request
|
3
3
|
class Campaigns < ApiBase
|
4
4
|
def fetch
|
5
|
-
self.class.get('/campaigns', opts).parsed_response
|
6
|
-
|
7
|
-
end
|
5
|
+
response = self.class.get('/campaigns', opts).parsed_response
|
6
|
+
handle_response(response: response, klass: Response::Campaign)
|
8
7
|
end
|
9
8
|
end
|
10
9
|
end
|
@@ -2,9 +2,8 @@ module BalihooLpcClient
|
|
2
2
|
module Request
|
3
3
|
class CampaignsWithTactics < ApiBase
|
4
4
|
def fetch
|
5
|
-
self.class.get('/campaignswithtactics', opts).parsed_response
|
6
|
-
|
7
|
-
end
|
5
|
+
response = self.class.get('/campaignswithtactics', opts).parsed_response
|
6
|
+
handle_response(response: response, klass: Response::Campaign)
|
8
7
|
end
|
9
8
|
end
|
10
9
|
end
|
@@ -3,14 +3,14 @@ module BalihooLpcClient
|
|
3
3
|
class Metrics < ApiBase
|
4
4
|
attr_accessor :tactic_id
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
super(
|
6
|
+
def initialize(api:, params:, tactic_id:)
|
7
|
+
super(api: api, params: params)
|
8
8
|
self.tactic_id = tactic_id
|
9
9
|
end
|
10
10
|
|
11
11
|
def fetch
|
12
|
-
|
13
|
-
Response::Metric
|
12
|
+
response = self.class.get("/tactic/#{tactic_id}/metrics", opts).parsed_response
|
13
|
+
handle_response(response: response, klass: Response::Metric, mappable: false)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module BalihooLpcClient
|
2
|
+
module Request
|
3
|
+
class Tactics < ApiBase
|
4
|
+
attr_accessor :campaign_id
|
5
|
+
|
6
|
+
def initialize(api:, params:, campaign_id:)
|
7
|
+
super(api: api, params: params)
|
8
|
+
self.campaign_id = campaign_id
|
9
|
+
end
|
10
|
+
|
11
|
+
def fetch
|
12
|
+
response = self.class.get("/campaign/#{campaign_id}/tactics", opts).parsed_response
|
13
|
+
|
14
|
+
if multiple_locations?
|
15
|
+
multiple_locations(response: response, klass: Response::Tactic, mappable: true)
|
16
|
+
else
|
17
|
+
single_location(response: response['tactics'], klass: Response::Tactic, mappable: true)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module BalihooLpcClient
|
2
|
+
module Request
|
3
|
+
class WebsiteMetrics < ApiBase
|
4
|
+
def fetch
|
5
|
+
response = self.class.get("/websitemetrics", opts).parsed_response
|
6
|
+
handle_response(response: response, klass: Response::WebsiteMetric, mappable: false)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -7,8 +7,8 @@ module BalihooLpcClient
|
|
7
7
|
property :id, from: 'id'
|
8
8
|
property :title, from: 'title'
|
9
9
|
property :description, from: 'description'
|
10
|
-
property :start, from: 'start'
|
11
|
-
property :end, from: 'end'
|
10
|
+
property :start, from: 'start', with: -> (v) { Date.parse(v) }
|
11
|
+
property :end, from: 'end', with: -> (v) { Date.parse(v) }
|
12
12
|
property :status, from: 'status'
|
13
13
|
property :tactics, from: 'tactics', coerce: Array[Tactic]
|
14
14
|
end
|
@@ -3,7 +3,7 @@ module BalihooLpcClient
|
|
3
3
|
class Metric < Hashie::Dash
|
4
4
|
include Hashie::Extensions::Dash::PropertyTranslation
|
5
5
|
|
6
|
-
property :tactic_ids, from: 'tacticIds'
|
6
|
+
property :tactic_ids, from: 'tacticIds'
|
7
7
|
property :channel, from: 'channel'
|
8
8
|
property :clicks, from: 'clicks'
|
9
9
|
property :spend, from: 'spend'
|
@@ -2,11 +2,11 @@ module BalihooLpcClient
|
|
2
2
|
module Response
|
3
3
|
class Tactic < Hashie::Dash
|
4
4
|
include Hashie::Extensions::Dash::PropertyTranslation
|
5
|
-
|
5
|
+
|
6
6
|
property :id, from: 'id'
|
7
7
|
property :title, from: 'title'
|
8
|
-
property :start, from: 'start'
|
9
|
-
property :end, from: 'end'
|
8
|
+
property :start, from: 'start', with: -> (v) { Date.parse(v) }
|
9
|
+
property :end, from: 'end', with: -> (v) { Date.parse(v) }
|
10
10
|
property :channel, from: 'channel'
|
11
11
|
property :description, from: 'description'
|
12
12
|
property :creative, from: 'creative'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module BalihooLpcClient
|
2
|
+
module Response
|
3
|
+
class WebsiteMetric < Hashie::Dash
|
4
|
+
include Hashie::Extensions::Dash::PropertyTranslation
|
5
|
+
include Hashie::Extensions::Dash::Coercion
|
6
|
+
|
7
|
+
property :visits, from: 'visits', coerce: WebsiteMetricVisits
|
8
|
+
property :leads, from: 'leads', coerce: WebsiteMetricLeads
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module BalihooLpcClient
|
2
|
+
module Response
|
3
|
+
class WebsiteMetricLeads < Hashie::Dash
|
4
|
+
include Hashie::Extensions::Dash::PropertyTranslation
|
5
|
+
|
6
|
+
property :total, from: 'total'
|
7
|
+
property :total_web, from: 'totalWeb'
|
8
|
+
property :total_phone, from: 'totalPhone'
|
9
|
+
property :organic_web, from: 'organicWeb'
|
10
|
+
property :paid_web, from: 'paidWeb'
|
11
|
+
property :organic_phone, from: 'organicPhone'
|
12
|
+
property :paid_phone, from: 'paidPhone'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module BalihooLpcClient
|
2
|
+
module Response
|
3
|
+
class WebsiteMetricVisits < Hashie::Dash
|
4
|
+
include Hashie::Extensions::Dash::PropertyTranslation
|
5
|
+
|
6
|
+
property :total, from: 'total'
|
7
|
+
property :organic, from: 'organic'
|
8
|
+
property :direct, from: 'direct'
|
9
|
+
property :referral, from: 'referral'
|
10
|
+
property :paid, from: 'paid'
|
11
|
+
property :new_visits_percent, from: 'newVisitsPercent'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/balihoo_lpc_client.rb
CHANGED
@@ -3,17 +3,22 @@ require 'hashie'
|
|
3
3
|
|
4
4
|
require 'balihoo_lpc_client/version'
|
5
5
|
require 'balihoo_lpc_client/configuration'
|
6
|
-
require 'balihoo_lpc_client/
|
6
|
+
require 'balihoo_lpc_client/api'
|
7
7
|
require 'balihoo_lpc_client/request/base'
|
8
8
|
require 'balihoo_lpc_client/request/api_base'
|
9
9
|
require 'balihoo_lpc_client/request/authentication'
|
10
10
|
require 'balihoo_lpc_client/request/campaigns'
|
11
11
|
require 'balihoo_lpc_client/request/campaigns_with_tactics'
|
12
12
|
require 'balihoo_lpc_client/request/metrics'
|
13
|
+
require 'balihoo_lpc_client/request/tactics'
|
14
|
+
require 'balihoo_lpc_client/request/website_metrics'
|
13
15
|
require 'balihoo_lpc_client/response/authentication'
|
14
16
|
require 'balihoo_lpc_client/response/tactic'
|
15
17
|
require 'balihoo_lpc_client/response/campaign'
|
16
18
|
require 'balihoo_lpc_client/response/metric'
|
19
|
+
require 'balihoo_lpc_client/response/website_metric_visits'
|
20
|
+
require 'balihoo_lpc_client/response/website_metric_leads'
|
21
|
+
require 'balihoo_lpc_client/response/website_metric'
|
17
22
|
|
18
23
|
module BalihooLpcClient
|
19
24
|
class BalihooLpcError < StandardError; end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: balihoo_lpc_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JD Guzman
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-03-
|
12
|
+
date: 2016-03-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -159,18 +159,23 @@ files:
|
|
159
159
|
- bin/console
|
160
160
|
- bin/setup
|
161
161
|
- lib/balihoo_lpc_client.rb
|
162
|
+
- lib/balihoo_lpc_client/api.rb
|
162
163
|
- lib/balihoo_lpc_client/configuration.rb
|
163
|
-
- lib/balihoo_lpc_client/connection.rb
|
164
164
|
- lib/balihoo_lpc_client/request/api_base.rb
|
165
165
|
- lib/balihoo_lpc_client/request/authentication.rb
|
166
166
|
- lib/balihoo_lpc_client/request/base.rb
|
167
167
|
- lib/balihoo_lpc_client/request/campaigns.rb
|
168
168
|
- lib/balihoo_lpc_client/request/campaigns_with_tactics.rb
|
169
169
|
- lib/balihoo_lpc_client/request/metrics.rb
|
170
|
+
- lib/balihoo_lpc_client/request/tactics.rb
|
171
|
+
- lib/balihoo_lpc_client/request/website_metrics.rb
|
170
172
|
- lib/balihoo_lpc_client/response/authentication.rb
|
171
173
|
- lib/balihoo_lpc_client/response/campaign.rb
|
172
174
|
- lib/balihoo_lpc_client/response/metric.rb
|
173
175
|
- lib/balihoo_lpc_client/response/tactic.rb
|
176
|
+
- lib/balihoo_lpc_client/response/website_metric.rb
|
177
|
+
- lib/balihoo_lpc_client/response/website_metric_leads.rb
|
178
|
+
- lib/balihoo_lpc_client/response/website_metric_visits.rb
|
174
179
|
- lib/balihoo_lpc_client/version.rb
|
175
180
|
homepage: https://github.com/riverock/balihoo_lpc
|
176
181
|
licenses:
|
@@ -188,9 +193,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
188
193
|
version: '0'
|
189
194
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
195
|
requirements:
|
191
|
-
- - "
|
196
|
+
- - ">="
|
192
197
|
- !ruby/object:Gem::Version
|
193
|
-
version:
|
198
|
+
version: '0'
|
194
199
|
requirements: []
|
195
200
|
rubyforge_project:
|
196
201
|
rubygems_version: 2.4.5.1
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module BalihooLpcClient
|
2
|
-
class Connection
|
3
|
-
attr_accessor :config
|
4
|
-
|
5
|
-
def initialize(config:)
|
6
|
-
self.config = config
|
7
|
-
end
|
8
|
-
|
9
|
-
def authenticate!
|
10
|
-
auth = Request::Authentication.new(connection: self)
|
11
|
-
auth.authenticate!
|
12
|
-
end
|
13
|
-
|
14
|
-
def campaigns(params: {})
|
15
|
-
validate_params!(params: params)
|
16
|
-
Request::Campaigns.new(connection: self, params: params).fetch
|
17
|
-
end
|
18
|
-
|
19
|
-
def campaigns_with_tactics(params: {})
|
20
|
-
validate_params!(params: params)
|
21
|
-
Request::CampaignsWithTactics.new(connection: self, params: params).fetch
|
22
|
-
end
|
23
|
-
|
24
|
-
def metrics(tactic_id:, params: {})
|
25
|
-
validate_params!(params: params)
|
26
|
-
Request::Metrics.new(connection: self, params: params, tactic_id: tactic_id).fetch
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def validate_params!(params:)
|
32
|
-
if config.location_key.nil? && params[:locations].nil?
|
33
|
-
raise ApiOptionError, 'must pass opts[:locations] array since no location_key given'
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|