Class: Buzz::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/buzz/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buzz_key: nil, email: nil, password: nil, **options) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/buzz/client.rb', line 11

def initialize(buzz_key: nil, email: nil, password: nil, **options)
  @config = if buzz_key
    Configuration.new.tap do |c|
      c.buzz_key = buzz_key
      c.email = email
      c.password = password
      options.each { |k, v| c.public_send(:"#{k}=", v) }
    end
  else
    Buzz.configuration.dup
  end
  @config.validate!
  @cookie_jar = CookieJar.new
  @http = nil
  @authenticated = false
  @mutex = Mutex.new
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



9
10
11
# File 'lib/buzz/client.rb', line 9

def config
  @config
end

Returns the value of attribute cookie_jar.



9
10
11
# File 'lib/buzz/client.rb', line 9

def cookie_jar
  @cookie_jar
end

Instance Method Details

#advertisersObject

Resource accessors



77
78
79
# File 'lib/buzz/client.rb', line 77

def advertisers
  Resources::Advertiser.new(self)
end

#authenticateObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/buzz/client.rb', line 45

def authenticate
  uri = build_uri("/rest/v2/authenticate")
  body = { email: config.email, password: config.password }
  body[:account_id] = config. if config.

  req = build_request(:post, uri)
  req.body = JSON.generate(body)

  response = execute(uri, req)

  unless response.success?
    raise AuthenticationError.new(
      "Authentication failed: #{response.body}",
      status: response.status,
      body: response.data
    )
  end

  @authenticated = true

  if config.keep_logged_in
    keep_logged_in
  end

  response
end

#authenticated?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/buzz/client.rb', line 72

def authenticated?
  @authenticated
end

#campaignsObject



81
82
83
# File 'lib/buzz/client.rb', line 81

def campaigns
  Resources::Campaign.new(self)
end

#creative_assetsObject



101
102
103
# File 'lib/buzz/client.rb', line 101

def creative_assets
  Resources::CreativeAsset.new(self)
end

#creative_line_items(line_item_id) ⇒ Object



105
106
107
# File 'lib/buzz/client.rb', line 105

def creative_line_items(line_item_id)
  Resources::CreativeLineItem.new(self, line_item_id)
end

#creativesObject



89
90
91
# File 'lib/buzz/client.rb', line 89

def creatives
  Resources::Creative.new(self)
end

#delete(path, params = {}) ⇒ Object



41
42
43
# File 'lib/buzz/client.rb', line 41

def delete(path, params = {})
  request(:delete, path, params: params)
end

#get(path, params = {}) ⇒ Object



29
30
31
# File 'lib/buzz/client.rb', line 29

def get(path, params = {})
  request(:get, path, params: params)
end

#line_itemsObject



85
86
87
# File 'lib/buzz/client.rb', line 85

def line_items
  Resources::LineItem.new(self)
end

#post(path, body = {}) ⇒ Object



33
34
35
# File 'lib/buzz/client.rb', line 33

def post(path, body = {})
  request(:post, path, body: body)
end

#put(path, body = {}) ⇒ Object



37
38
39
# File 'lib/buzz/client.rb', line 37

def put(path, body = {})
  request(:put, path, body: body)
end

#reportingObject



109
110
111
# File 'lib/buzz/client.rb', line 109

def reporting
  Resources::Reporting.new(self)
end

#search(query:, types: nil) ⇒ Object



113
114
115
116
117
# File 'lib/buzz/client.rb', line 113

def search(query:, types: nil)
  params = { q: query }
  params[:entity_types] = Array(types).map(&:to_s).join(",") if types
  get("/rest/v2/search", params)
end

#segmentsObject



93
94
95
# File 'lib/buzz/client.rb', line 93

def segments
  Resources::Segment.new(self)
end

#targetingObject



97
98
99
# File 'lib/buzz/client.rb', line 97

def targeting
  Resources::Targeting.new(self)
end