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
-
#advertisers ⇒ Object
Resource accessors.
- #authenticate ⇒ Object
- #authenticated? ⇒ Boolean
- #campaigns ⇒ Object
- #creative_assets ⇒ Object
- #creative_line_items(line_item_id) ⇒ 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.
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, **) @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.
9 10 11 |
# File 'lib/buzz/client.rb', line 9 def config @config end |
#cookie_jar ⇒ Object (readonly)
Returns the value of attribute cookie_jar.
9 10 11 |
# File 'lib/buzz/client.rb', line 9 def @cookie_jar end |
Instance Method Details
#advertisers ⇒ Object
Resource accessors
77 78 79 |
# File 'lib/buzz/client.rb', line 77 def advertisers Resources::Advertiser.new(self) end |
#authenticate ⇒ Object
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.account_id if config.account_id 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
72 73 74 |
# File 'lib/buzz/client.rb', line 72 def authenticated? @authenticated end |
#campaigns ⇒ Object
81 82 83 |
# File 'lib/buzz/client.rb', line 81 def campaigns Resources::Campaign.new(self) end |
#creative_assets ⇒ Object
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 |
#creatives ⇒ Object
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_items ⇒ Object
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 |
#reporting ⇒ Object
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 |