Class: Buzz::Client
- Inherits:
-
Object
- Object
- Buzz::Client
- Defined in:
- lib/buzz/client.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#cookie_jar ⇒ Object
readonly
Returns the value of attribute cookie_jar.
Instance Method Summary collapse
- #advertiser_categories ⇒ Object
-
#advertisers ⇒ Object
Resource accessors.
- #authenticate ⇒ Object
- #authenticated? ⇒ Boolean
- #campaigns ⇒ Object
- #creative_assets ⇒ Object
- #creative_line_items(line_item_id) ⇒ Object
- #creative_templates ⇒ Object
- #creatives ⇒ Object
- #delete(path, params = {}) ⇒ Object
- #get(path, params = {}) ⇒ Object
-
#initialize(buzz_key: nil, email: nil, password: nil, **options) ⇒ Client
constructor
A new instance of Client.
- #line_items ⇒ Object
- #post(path, body = {}) ⇒ Object
- #put(path, body = {}) ⇒ Object
- #reporting ⇒ Object
- #search(query:, types: nil) ⇒ Object
- #segments ⇒ Object
- #targeting ⇒ Object
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, **) @config = if buzz_key Configuration.new.tap do |c| c.buzz_key = buzz_key c.email = email c.password = password .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
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/buzz/client.rb', line 10 def config @config end |
#cookie_jar ⇒ Object (readonly)
Returns the value of attribute cookie_jar.
10 11 12 |
# File 'lib/buzz/client.rb', line 10 def @cookie_jar end |
Instance Method Details
#advertiser_categories ⇒ Object
86 87 88 |
# File 'lib/buzz/client.rb', line 86 def advertiser_categories Resources::AdvertiserCategory.new(self) end |
#advertisers ⇒ Object
Resource accessors
82 83 84 |
# File 'lib/buzz/client.rb', line 82 def advertisers Resources::Advertiser.new(self) end |
#authenticate ⇒ Object
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.account_id if config.account_id 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
77 78 79 |
# File 'lib/buzz/client.rb', line 77 def authenticated? @authenticated end |
#campaigns ⇒ Object
90 91 92 |
# File 'lib/buzz/client.rb', line 90 def campaigns Resources::Campaign.new(self) end |
#creative_assets ⇒ Object
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_templates ⇒ Object
102 103 104 |
# File 'lib/buzz/client.rb', line 102 def creative_templates Resources::CreativeTemplate.new(self) end |
#creatives ⇒ Object
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_items ⇒ Object
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 |
#reporting ⇒ Object
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 |