buzzrb 0.1.0 → 0.4.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/lib/buzz/client.rb +72 -14
- data/lib/buzz/configuration.rb +10 -2
- data/lib/buzz/cookie_jar.rb +1 -1
- data/lib/buzz/error.rb +12 -4
- data/lib/buzz/resources/advertiser_category.rb +13 -0
- data/lib/buzz/resources/creative_template.rb +13 -0
- data/lib/buzz/resources/reporting.rb +1 -1
- data/lib/buzz/version.rb +1 -1
- data/lib/buzz.rb +2 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ed74d4b39193794e41ca9e8c99c8fb0aba7dc0187ecde6189a84b92090482288
|
|
4
|
+
data.tar.gz: 7b9936b7811338e9f4aadefccabbc7935df5763a1e313da8e724b2e591d0eaad
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 667e8573b6d27eb1fcb7f419f5bf35526ab9b4e71d2414b89111163c5ea8061e0d565a2d6f14cdb3843b0087e5112e3d3eccb9f2a49f500df9cd8b05dac647a2
|
|
7
|
+
data.tar.gz: ebd0800e8a03ba0cdf4a820d26ae64f5c5af26e01422da6d9dbef78c6a5028e909d178f9fe440ca2ea8941eb267f63f27ab861309a9c0368f4cf154bfbe6fa1c
|
data/lib/buzz/client.rb
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require "net/http"
|
|
4
4
|
require "uri"
|
|
5
5
|
require "json"
|
|
6
|
+
require "tempfile"
|
|
6
7
|
|
|
7
8
|
module Buzz
|
|
8
9
|
class Client
|
|
@@ -19,6 +20,7 @@ module Buzz
|
|
|
19
20
|
else
|
|
20
21
|
Buzz.configuration.dup
|
|
21
22
|
end
|
|
23
|
+
|
|
22
24
|
@config.validate!
|
|
23
25
|
@cookie_jar = CookieJar.new
|
|
24
26
|
@http = nil
|
|
@@ -44,19 +46,22 @@ module Buzz
|
|
|
44
46
|
|
|
45
47
|
def authenticate
|
|
46
48
|
uri = build_uri("/rest/v2/authenticate")
|
|
47
|
-
body = {
|
|
49
|
+
body = {email: config.email, password: config.password}
|
|
48
50
|
body[:account_id] = config.account_id if config.account_id
|
|
49
51
|
|
|
50
52
|
req = build_request(:post, uri)
|
|
53
|
+
req["Content-Type"] = "application/json"
|
|
51
54
|
req.body = JSON.generate(body)
|
|
52
55
|
|
|
53
56
|
response = execute(uri, req)
|
|
54
57
|
|
|
55
58
|
unless response.success?
|
|
56
|
-
raise
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
raise(
|
|
60
|
+
AuthenticationError.new(
|
|
61
|
+
"Authentication failed: #{response.body}",
|
|
62
|
+
status: response.status,
|
|
63
|
+
body: response.data
|
|
64
|
+
)
|
|
60
65
|
)
|
|
61
66
|
end
|
|
62
67
|
|
|
@@ -78,6 +83,10 @@ module Buzz
|
|
|
78
83
|
Resources::Advertiser.new(self)
|
|
79
84
|
end
|
|
80
85
|
|
|
86
|
+
def advertiser_categories
|
|
87
|
+
Resources::AdvertiserCategory.new(self)
|
|
88
|
+
end
|
|
89
|
+
|
|
81
90
|
def campaigns
|
|
82
91
|
Resources::Campaign.new(self)
|
|
83
92
|
end
|
|
@@ -90,6 +99,10 @@ module Buzz
|
|
|
90
99
|
Resources::Creative.new(self)
|
|
91
100
|
end
|
|
92
101
|
|
|
102
|
+
def creative_templates
|
|
103
|
+
Resources::CreativeTemplate.new(self)
|
|
104
|
+
end
|
|
105
|
+
|
|
93
106
|
def segments
|
|
94
107
|
Resources::Segment.new(self)
|
|
95
108
|
end
|
|
@@ -111,7 +124,7 @@ module Buzz
|
|
|
111
124
|
end
|
|
112
125
|
|
|
113
126
|
def search(query:, types: nil)
|
|
114
|
-
params = {
|
|
127
|
+
params = {q: query}
|
|
115
128
|
params[:entity_types] = Array(types).map(&:to_s).join(",") if types
|
|
116
129
|
get("/rest/v2/search", params)
|
|
117
130
|
end
|
|
@@ -121,6 +134,7 @@ module Buzz
|
|
|
121
134
|
def keep_logged_in
|
|
122
135
|
uri = build_uri("/rest/v2/authenticate/keep_logged_in")
|
|
123
136
|
req = build_request(:post, uri)
|
|
137
|
+
req["Content-Type"] = "application/json"
|
|
124
138
|
req.body = JSON.generate({})
|
|
125
139
|
execute(uri, req)
|
|
126
140
|
end
|
|
@@ -130,7 +144,15 @@ module Buzz
|
|
|
130
144
|
|
|
131
145
|
uri = build_uri(path, params)
|
|
132
146
|
req = build_request(method, uri)
|
|
133
|
-
|
|
147
|
+
|
|
148
|
+
if body
|
|
149
|
+
if multipart?(body)
|
|
150
|
+
req.set_form(format_multipart(body), "multipart/form-data")
|
|
151
|
+
else
|
|
152
|
+
req["Content-Type"] = "application/json"
|
|
153
|
+
req.body = JSON.generate(body)
|
|
154
|
+
end
|
|
155
|
+
end
|
|
134
156
|
|
|
135
157
|
response = execute(uri, req)
|
|
136
158
|
|
|
@@ -139,7 +161,16 @@ module Buzz
|
|
|
139
161
|
authenticate
|
|
140
162
|
uri = build_uri(path, params)
|
|
141
163
|
req = build_request(method, uri)
|
|
142
|
-
|
|
164
|
+
|
|
165
|
+
if body
|
|
166
|
+
if multipart?(body)
|
|
167
|
+
req.set_form(format_multipart(body), "multipart/form-data")
|
|
168
|
+
else
|
|
169
|
+
req["Content-Type"] = "application/json"
|
|
170
|
+
req.body = JSON.generate(body)
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
143
174
|
response = execute(uri, req)
|
|
144
175
|
end
|
|
145
176
|
|
|
@@ -157,19 +188,23 @@ module Buzz
|
|
|
157
188
|
query = params.map { |k, v| "#{URI.encode_www_form_component(k)}=#{URI.encode_www_form_component(v)}" }
|
|
158
189
|
uri.query = query.join("&")
|
|
159
190
|
end
|
|
191
|
+
|
|
160
192
|
uri
|
|
161
193
|
end
|
|
162
194
|
|
|
163
195
|
def build_request(method, uri)
|
|
164
196
|
klass = case method
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
197
|
+
when :get
|
|
198
|
+
Net::HTTP::Get
|
|
199
|
+
when :post
|
|
200
|
+
Net::HTTP::Post
|
|
201
|
+
when :put
|
|
202
|
+
Net::HTTP::Put
|
|
203
|
+
when :delete
|
|
204
|
+
Net::HTTP::Delete
|
|
205
|
+
end
|
|
170
206
|
|
|
171
207
|
req = klass.new(uri)
|
|
172
|
-
req["Content-Type"] = "application/json"
|
|
173
208
|
req["Accept"] = "application/json"
|
|
174
209
|
req["X-Timezone"] = config.timezone if config.timezone
|
|
175
210
|
|
|
@@ -203,6 +238,7 @@ module Buzz
|
|
|
203
238
|
@http.keep_alive_timeout = 30
|
|
204
239
|
@http.start
|
|
205
240
|
end
|
|
241
|
+
|
|
206
242
|
@http
|
|
207
243
|
end
|
|
208
244
|
end
|
|
@@ -227,6 +263,28 @@ module Buzz
|
|
|
227
263
|
end
|
|
228
264
|
end
|
|
229
265
|
|
|
266
|
+
def multipart?(body)
|
|
267
|
+
return false unless body.is_a?(Hash) || body.is_a?(Array)
|
|
268
|
+
|
|
269
|
+
if body.is_a?(Hash)
|
|
270
|
+
body.values.any? { |v| v.is_a?(IO) || (defined?(Tempfile) && v.is_a?(Tempfile)) }
|
|
271
|
+
else
|
|
272
|
+
body.any? { |v| v.is_a?(IO) || (defined?(Tempfile) && v.is_a?(Tempfile)) }
|
|
273
|
+
end
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
def format_multipart(body)
|
|
277
|
+
return body unless body.is_a?(Hash)
|
|
278
|
+
|
|
279
|
+
body.map do |k, v|
|
|
280
|
+
if v.is_a?(IO) || (defined?(Tempfile) && v.is_a?(Tempfile))
|
|
281
|
+
[k.to_s, v]
|
|
282
|
+
else
|
|
283
|
+
[k.to_s, v.to_s]
|
|
284
|
+
end
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
|
|
230
288
|
def error_message(response)
|
|
231
289
|
if response.data.is_a?(Hash) && response.data["message"]
|
|
232
290
|
response.data["message"]
|
data/lib/buzz/configuration.rb
CHANGED
|
@@ -2,8 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
module Buzz
|
|
4
4
|
class Configuration
|
|
5
|
-
attr_accessor
|
|
6
|
-
|
|
5
|
+
attr_accessor(
|
|
6
|
+
:buzz_key,
|
|
7
|
+
:email,
|
|
8
|
+
:password,
|
|
9
|
+
:keep_logged_in,
|
|
10
|
+
:account_id,
|
|
11
|
+
:timezone,
|
|
12
|
+
:open_timeout,
|
|
13
|
+
:read_timeout
|
|
14
|
+
)
|
|
7
15
|
attr_writer :base_url
|
|
8
16
|
|
|
9
17
|
def initialize
|
data/lib/buzz/cookie_jar.rb
CHANGED
|
@@ -68,7 +68,7 @@ module Buzz
|
|
|
68
68
|
value = name_value[(eq_index + 1)..].strip
|
|
69
69
|
return nil if name.empty?
|
|
70
70
|
|
|
71
|
-
attrs = {
|
|
71
|
+
attrs = {name: name, value: value, domain: uri.host, path: "/", secure: false, httponly: false}
|
|
72
72
|
|
|
73
73
|
parts.each do |part|
|
|
74
74
|
key, val = part.split("=", 2).map(&:strip)
|
data/lib/buzz/error.rb
CHANGED
|
@@ -11,7 +11,9 @@ module Buzz
|
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
class AuthenticationError < Error
|
|
14
|
+
class AuthenticationError < Error
|
|
15
|
+
end
|
|
16
|
+
|
|
15
17
|
class RateLimitError < Error
|
|
16
18
|
attr_reader :retry_after
|
|
17
19
|
|
|
@@ -20,7 +22,13 @@ module Buzz
|
|
|
20
22
|
super(message, status: status, body: body)
|
|
21
23
|
end
|
|
22
24
|
end
|
|
23
|
-
|
|
24
|
-
class
|
|
25
|
-
|
|
25
|
+
|
|
26
|
+
class NotFoundError < Error
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class ValidationError < Error
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
class ServerError < Error
|
|
33
|
+
end
|
|
26
34
|
end
|
|
@@ -11,7 +11,7 @@ module Buzz
|
|
|
11
11
|
|
|
12
12
|
# Query performance data (spend, impressions, clicks, etc.)
|
|
13
13
|
def query(dimensions: [], metrics: [], **params)
|
|
14
|
-
body = {
|
|
14
|
+
body = {dimensions: dimensions, metrics: metrics}.merge(params)
|
|
15
15
|
response = client.post("/rest/v2/report-data", body)
|
|
16
16
|
response.data["results"]
|
|
17
17
|
end
|
data/lib/buzz/version.rb
CHANGED
data/lib/buzz.rb
CHANGED
|
@@ -8,6 +8,7 @@ require_relative "buzz/response"
|
|
|
8
8
|
require_relative "buzz/paginator"
|
|
9
9
|
require_relative "buzz/resource"
|
|
10
10
|
require_relative "buzz/resources/advertiser"
|
|
11
|
+
require_relative "buzz/resources/advertiser_category"
|
|
11
12
|
require_relative "buzz/resources/campaign"
|
|
12
13
|
require_relative "buzz/resources/line_item"
|
|
13
14
|
require_relative "buzz/resources/creative"
|
|
@@ -15,6 +16,7 @@ require_relative "buzz/resources/segment"
|
|
|
15
16
|
require_relative "buzz/resources/targeting"
|
|
16
17
|
require_relative "buzz/resources/creative_asset"
|
|
17
18
|
require_relative "buzz/resources/creative_line_item"
|
|
19
|
+
require_relative "buzz/resources/creative_template"
|
|
18
20
|
require_relative "buzz/resources/search"
|
|
19
21
|
require_relative "buzz/resources/reporting"
|
|
20
22
|
require_relative "buzz/client"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: buzzrb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Letterpress
|
|
@@ -65,10 +65,12 @@ files:
|
|
|
65
65
|
- lib/buzz/paginator.rb
|
|
66
66
|
- lib/buzz/resource.rb
|
|
67
67
|
- lib/buzz/resources/advertiser.rb
|
|
68
|
+
- lib/buzz/resources/advertiser_category.rb
|
|
68
69
|
- lib/buzz/resources/campaign.rb
|
|
69
70
|
- lib/buzz/resources/creative.rb
|
|
70
71
|
- lib/buzz/resources/creative_asset.rb
|
|
71
72
|
- lib/buzz/resources/creative_line_item.rb
|
|
73
|
+
- lib/buzz/resources/creative_template.rb
|
|
72
74
|
- lib/buzz/resources/line_item.rb
|
|
73
75
|
- lib/buzz/resources/reporting.rb
|
|
74
76
|
- lib/buzz/resources/search.rb
|