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.



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

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.



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

def config
  @config
end

Returns the value of attribute cookie_jar.



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

def cookie_jar
  @cookie_jar
end

Instance Method Details

#advertiser_categoriesObject



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

def advertiser_categories
  Resources::AdvertiserCategory.new(self)
end

#advertisersObject

Resource accessors



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

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

#authenticateObject



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

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["Content-Type"] = "application/json"
  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)


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

def authenticated?
  @authenticated
end

#campaignsObject



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

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

#creative_assetsObject



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

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

#creative_line_items(line_item_id) ⇒ Object



118
119
120
# File 'lib/buzz/client.rb', line 118

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

#creative_templatesObject



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

def creative_templates
  Resources::CreativeTemplate.new(self)
end

#creativesObject



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

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

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



43
44
45
# File 'lib/buzz/client.rb', line 43

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

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



31
32
33
# File 'lib/buzz/client.rb', line 31

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

#line_itemsObject



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

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

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



35
36
37
# File 'lib/buzz/client.rb', line 35

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

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



39
40
41
# File 'lib/buzz/client.rb', line 39

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

#reportingObject



122
123
124
# File 'lib/buzz/client.rb', line 122

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

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



126
127
128
129
130
# File 'lib/buzz/client.rb', line 126

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



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

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

#targetingObject



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

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