buzzrb 0.1.0 → 0.3.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 +68 -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/reporting.rb +1 -1
- data/lib/buzz/version.rb +1 -1
- data/lib/buzz.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 57b591611ae054f922120874732de27cb8262e9e69106bafe45b12f2ffc45375
|
|
4
|
+
data.tar.gz: 5942a746b729b99c7e3df9372b9262451c09681cb2256fea779042869c2420a7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7850c71454ce6e1eb2fa378613c8cf8a94909f895d52c5b9f14685294e5345f746e8838c5114b8e8eb5eb157cfb2ed4e0b9f7dc8d537f08ab4a6372497db871e
|
|
7
|
+
data.tar.gz: 2c4815101a08f218fda17b81fede7f38dcf85e025d0f6635522a36b11a06ddb76d2378e3425583bc0f443cd75f064426764f5a962a12ba609913e98e465cbac9
|
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
|
|
@@ -111,7 +120,7 @@ module Buzz
|
|
|
111
120
|
end
|
|
112
121
|
|
|
113
122
|
def search(query:, types: nil)
|
|
114
|
-
params = {
|
|
123
|
+
params = {q: query}
|
|
115
124
|
params[:entity_types] = Array(types).map(&:to_s).join(",") if types
|
|
116
125
|
get("/rest/v2/search", params)
|
|
117
126
|
end
|
|
@@ -121,6 +130,7 @@ module Buzz
|
|
|
121
130
|
def keep_logged_in
|
|
122
131
|
uri = build_uri("/rest/v2/authenticate/keep_logged_in")
|
|
123
132
|
req = build_request(:post, uri)
|
|
133
|
+
req["Content-Type"] = "application/json"
|
|
124
134
|
req.body = JSON.generate({})
|
|
125
135
|
execute(uri, req)
|
|
126
136
|
end
|
|
@@ -130,7 +140,15 @@ module Buzz
|
|
|
130
140
|
|
|
131
141
|
uri = build_uri(path, params)
|
|
132
142
|
req = build_request(method, uri)
|
|
133
|
-
|
|
143
|
+
|
|
144
|
+
if body
|
|
145
|
+
if multipart?(body)
|
|
146
|
+
req.set_form(format_multipart(body), "multipart/form-data")
|
|
147
|
+
else
|
|
148
|
+
req["Content-Type"] = "application/json"
|
|
149
|
+
req.body = JSON.generate(body)
|
|
150
|
+
end
|
|
151
|
+
end
|
|
134
152
|
|
|
135
153
|
response = execute(uri, req)
|
|
136
154
|
|
|
@@ -139,7 +157,16 @@ module Buzz
|
|
|
139
157
|
authenticate
|
|
140
158
|
uri = build_uri(path, params)
|
|
141
159
|
req = build_request(method, uri)
|
|
142
|
-
|
|
160
|
+
|
|
161
|
+
if body
|
|
162
|
+
if multipart?(body)
|
|
163
|
+
req.set_form(format_multipart(body), "multipart/form-data")
|
|
164
|
+
else
|
|
165
|
+
req["Content-Type"] = "application/json"
|
|
166
|
+
req.body = JSON.generate(body)
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
143
170
|
response = execute(uri, req)
|
|
144
171
|
end
|
|
145
172
|
|
|
@@ -157,19 +184,23 @@ module Buzz
|
|
|
157
184
|
query = params.map { |k, v| "#{URI.encode_www_form_component(k)}=#{URI.encode_www_form_component(v)}" }
|
|
158
185
|
uri.query = query.join("&")
|
|
159
186
|
end
|
|
187
|
+
|
|
160
188
|
uri
|
|
161
189
|
end
|
|
162
190
|
|
|
163
191
|
def build_request(method, uri)
|
|
164
192
|
klass = case method
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
193
|
+
when :get
|
|
194
|
+
Net::HTTP::Get
|
|
195
|
+
when :post
|
|
196
|
+
Net::HTTP::Post
|
|
197
|
+
when :put
|
|
198
|
+
Net::HTTP::Put
|
|
199
|
+
when :delete
|
|
200
|
+
Net::HTTP::Delete
|
|
201
|
+
end
|
|
170
202
|
|
|
171
203
|
req = klass.new(uri)
|
|
172
|
-
req["Content-Type"] = "application/json"
|
|
173
204
|
req["Accept"] = "application/json"
|
|
174
205
|
req["X-Timezone"] = config.timezone if config.timezone
|
|
175
206
|
|
|
@@ -203,6 +234,7 @@ module Buzz
|
|
|
203
234
|
@http.keep_alive_timeout = 30
|
|
204
235
|
@http.start
|
|
205
236
|
end
|
|
237
|
+
|
|
206
238
|
@http
|
|
207
239
|
end
|
|
208
240
|
end
|
|
@@ -227,6 +259,28 @@ module Buzz
|
|
|
227
259
|
end
|
|
228
260
|
end
|
|
229
261
|
|
|
262
|
+
def multipart?(body)
|
|
263
|
+
return false unless body.is_a?(Hash) || body.is_a?(Array)
|
|
264
|
+
|
|
265
|
+
if body.is_a?(Hash)
|
|
266
|
+
body.values.any? { |v| v.is_a?(IO) || (defined?(Tempfile) && v.is_a?(Tempfile)) }
|
|
267
|
+
else
|
|
268
|
+
body.any? { |v| v.is_a?(IO) || (defined?(Tempfile) && v.is_a?(Tempfile)) }
|
|
269
|
+
end
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
def format_multipart(body)
|
|
273
|
+
return body unless body.is_a?(Hash)
|
|
274
|
+
|
|
275
|
+
body.map do |k, v|
|
|
276
|
+
if v.is_a?(IO) || (defined?(Tempfile) && v.is_a?(Tempfile))
|
|
277
|
+
[k.to_s, v]
|
|
278
|
+
else
|
|
279
|
+
[k.to_s, v.to_s]
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
end
|
|
283
|
+
|
|
230
284
|
def error_message(response)
|
|
231
285
|
if response.data.is_a?(Hash) && response.data["message"]
|
|
232
286
|
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"
|
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.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Letterpress
|
|
@@ -65,6 +65,7 @@ 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
|