From 0b6759a21236617ba5c4f39178e7a73fc1a4ae4e Mon Sep 17 00:00:00 2001 From: Tushar Bhushan Date: Fri, 27 May 2022 15:47:35 -0700 Subject: [PATCH] Ads API v11 (#265) * Added support for unified cards and tests * updated cards example * update API_VERSION to 11 * Removed deprecated website/app cards * Line item budget changes * code quality changes * removed start/end times from campaigns * Remove string version of IDs Co-authored-by: Tom Osowski --- examples/cards.rb | 15 +- examples/draft_tweet.rb | 10 +- examples/promoted_tweet.rb | 4 +- lib/twitter-ads.rb | 4 - lib/twitter-ads/campaign/campaign.rb | 3 +- lib/twitter-ads/campaign/line_item.rb | 3 +- lib/twitter-ads/client.rb | 2 +- lib/twitter-ads/creative/cards.rb | 53 +- lib/twitter-ads/creative/draft_tweet.rb | 1 - .../creative/image_app_download_card.rb | 47 - .../creative/video_app_download_card.rb | 48 - .../creative/video_website_card.rb | 50 -- lib/twitter-ads/creative/website_card.rb | 45 - lib/twitter-ads/enum.rb | 4 + lib/twitter-ads/resources/analytics.rb | 1 - lib/twitter-ads/version.rb | 2 +- spec/fixtures/cards_all.json | 836 ++++++++++++++++++ spec/fixtures/cards_load.json | 42 + spec/twitter-ads/campaign/line_item_spec.rb | 1 + spec/twitter-ads/creative/cards_spec.rb | 52 ++ 20 files changed, 990 insertions(+), 233 deletions(-) delete mode 100644 lib/twitter-ads/creative/image_app_download_card.rb delete mode 100644 lib/twitter-ads/creative/video_app_download_card.rb delete mode 100644 lib/twitter-ads/creative/video_website_card.rb delete mode 100644 lib/twitter-ads/creative/website_card.rb create mode 100644 spec/fixtures/cards_all.json create mode 100644 spec/fixtures/cards_load.json create mode 100644 spec/twitter-ads/creative/cards_spec.rb diff --git a/examples/cards.rb b/examples/cards.rb index 8097b8d3..762aa66c 100644 --- a/examples/cards.rb +++ b/examples/cards.rb @@ -37,7 +37,18 @@ ] vwc = TwitterAds::Creative::Cards.new(account) -video_website_card = vwc.create(account, name, components) +vwc.name = name +vwc.components = components +vwc.save +vwc.name = 'vwc - ruby sdk' +vwc.save +puts vwc.name # vwc - ruby sdk + +# fetch all +# card = TwitterAds::Creative::Cards.all(account, card_ids: '1508693734346485761').first + +# fetch by card-id +# card = TwitterAds::Creative::Cards.load(account, '1508693734346485761') # get user_id for as_user_id parameter user_id = TwitterRestApi::UserIdLookup.load(account, screen_name: 'your_screen_name').id @@ -46,5 +57,5 @@ tweet = TwitterAds::Creative::DraftTweet.new(account) tweet.text = 'Created from SDK' tweet.as_user_id = user_id -tweet.card_uri = video_website_card.card_uri +tweet.card_uri = vwc.card_uri tweet.save diff --git a/examples/draft_tweet.rb b/examples/draft_tweet.rb index 71f1f9b2..2f873164 100644 --- a/examples/draft_tweet.rb +++ b/examples/draft_tweet.rb @@ -26,7 +26,7 @@ # fetch draft tweets from a given account tweets = TwitterAds::Creative::DraftTweet.all(account) tweets.each { |tweet| - p tweet.id_str + p tweet.id p tweet.text } @@ -35,19 +35,19 @@ draft_tweet.text = 'draft tweet - new' draft_tweet.as_user_id = user_id draft_tweet.save -p draft_tweet.id_str +p draft_tweet.id p draft_tweet.text # fetch single draft tweet metadata -tweet_id = draft_tweet.id_str +tweet_id = draft_tweet.id draft_tweet = TwitterAds::Creative::DraftTweet.load(account, tweet_id) -p draft_tweet.id_str +p draft_tweet.id p draft_tweet.text # update (PUT) metadata draft_tweet.text = 'draft tweet - update' draft_tweet = draft_tweet.save -p draft_tweet.id_str +p draft_tweet.id p draft_tweet.text # preview draft tweet of current instance (send notification) diff --git a/examples/promoted_tweet.rb b/examples/promoted_tweet.rb index b80f8848..4e09e137 100644 --- a/examples/promoted_tweet.rb +++ b/examples/promoted_tweet.rb @@ -31,7 +31,7 @@ # promote the tweet using our line item promoted_tweet = TwitterAds::Creative::PromotedTweet.new(account) promoted_tweet.line_item_id = line_item.id -promoted_tweet.tweet_id = tweet1[:id_str] +promoted_tweet.tweet_id = tweet1[:id] promoted_tweet.save # create request for a nullcasted tweet with a website card @@ -46,5 +46,5 @@ # promote the tweet using our line item promoted_tweet = TwitterAds::Creative::PromotedTweet.new(account) promoted_tweet.line_item_id = line_item.id -promoted_tweet.tweet_id = tweet2[:id_str] +promoted_tweet.tweet_id = tweet2[:id] promoted_tweet.save diff --git a/lib/twitter-ads.rb b/lib/twitter-ads.rb index 824874f0..3aa98475 100644 --- a/lib/twitter-ads.rb +++ b/lib/twitter-ads.rb @@ -60,7 +60,6 @@ require 'twitter-ads/creative/account_media' require 'twitter-ads/creative/cards_fetch' require 'twitter-ads/creative/cards' -require 'twitter-ads/creative/image_app_download_card' require 'twitter-ads/creative/image_conversation_card' require 'twitter-ads/creative/media_creative' require 'twitter-ads/creative/media_library' @@ -68,10 +67,7 @@ require 'twitter-ads/creative/promoted_tweet' require 'twitter-ads/creative/scheduled_tweet' require 'twitter-ads/creative/draft_tweet' -require 'twitter-ads/creative/video_app_download_card' require 'twitter-ads/creative/video_conversation_card' -require 'twitter-ads/creative/video_website_card' -require 'twitter-ads/creative/website_card' require 'twitter-ads/creative/poll_cards' require 'twitter-ads/creative/tweet_previews' require 'twitter-ads/creative/tweets' diff --git a/lib/twitter-ads/campaign/campaign.rb b/lib/twitter-ads/campaign/campaign.rb index a838ec1d..2c94a4a4 100644 --- a/lib/twitter-ads/campaign/campaign.rb +++ b/lib/twitter-ads/campaign/campaign.rb @@ -20,14 +20,13 @@ class Campaign < Analytics property :name property :funding_instrument_id - property :end_time, type: :time - property :start_time, type: :time property :entity_status property :effective_status property :currency property :standard_delivery property :daily_budget_amount_local_micro property :total_budget_amount_local_micro + property :budget_optimization # sdk only property :to_delete, type: :bool diff --git a/lib/twitter-ads/campaign/line_item.rb b/lib/twitter-ads/campaign/line_item.rb index 1a347d67..4e6f8a01 100644 --- a/lib/twitter-ads/campaign/line_item.rb +++ b/lib/twitter-ads/campaign/line_item.rb @@ -34,9 +34,8 @@ class LineItem < Analytics property :primary_web_event_tag property :product_type property :start_time, type: :time + property :standard_delivery, type: :bool property :total_budget_amount_local_micro - - # beta (not yet generally available) property :advertiser_user_id # sdk only diff --git a/lib/twitter-ads/client.rb b/lib/twitter-ads/client.rb index aec0e996..afd280ba 100644 --- a/lib/twitter-ads/client.rb +++ b/lib/twitter-ads/client.rb @@ -3,7 +3,7 @@ module TwitterAds - API_VERSION = '10' + API_VERSION = '11' # The Ads API Client class which functions as a # container for basic API consumer information. diff --git a/lib/twitter-ads/creative/cards.rb b/lib/twitter-ads/creative/cards.rb index 8fe28152..1cecce11 100644 --- a/lib/twitter-ads/creative/cards.rb +++ b/lib/twitter-ads/creative/cards.rb @@ -12,36 +12,46 @@ class Cards attr_reader :account + property :id, read_only: true + property :card_type, read_only: true property :card_uri, read_only: true property :created_at, type: :time, read_only: true property :deleted, type: :bool, read_only: true property :updated_at, type: :time, read_only: true # these are writable, but not in the sense that they can be set on an object and then saved - property :name, read_only: true - property :components, read_only: true + property :name + property :components RESOURCE = "/#{TwitterAds::API_VERSION}/" + - 'accounts/%{account_id}/cards' # @api private + 'accounts/%{account_id}/cards/%{id}' # @api private + RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/" + + 'accounts/%{account_id}/cards' # @api private - def load(*) - raise ArgumentError.new( - "'Cards' object has no attribute 'load'") - end - - def reload(*) - raise ArgumentError.new( - "'Cards' object has no attribute 'reload'") - end - - def create(account, name, components) - resource = RESOURCE % { account_id: account.id } - params = { 'name': name, 'components': components } + def save headers = { 'Content-Type' => 'application/json' } - response = Request.new(account.client, - :post, - resource, - headers: headers, - body: params.to_json).perform + params = { 'name': name, 'components': components } + if @id + resource = RESOURCE % { + account_id: account.id, + id: id + } + request = Request.new(account.client, + :put, + resource, + headers: headers, + body: params.to_json) + else + resource = RESOURCE_COLLECTION % { + account_id: account.id + } + request = Request.new(account.client, + :post, + resource, + headers: headers, + body: params.to_json) + end + + response = request.perform from_response(response.body[:data]) end @@ -49,7 +59,6 @@ def initialize(account) @account = account self end - end end diff --git a/lib/twitter-ads/creative/draft_tweet.rb b/lib/twitter-ads/creative/draft_tweet.rb index e45ff9f2..1a83416a 100644 --- a/lib/twitter-ads/creative/draft_tweet.rb +++ b/lib/twitter-ads/creative/draft_tweet.rb @@ -14,7 +14,6 @@ class DraftTweet # read-only property :id, read_only: true - property :id_str, read_only: true property :created_at, type: :time, read_only: true property :updated_at, type: :time, read_only: true property :user_id, read_only: true diff --git a/lib/twitter-ads/creative/image_app_download_card.rb b/lib/twitter-ads/creative/image_app_download_card.rb deleted file mode 100644 index bb95726b..00000000 --- a/lib/twitter-ads/creative/image_app_download_card.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true -# Copyright (C) 2019 Twitter, Inc. - -module TwitterAds - module Creative - - class ImageAppDownloadCard - - include TwitterAds::DSL - include TwitterAds::Resource - include TwitterAds::Persistence - - attr_reader :account - - property :card_type, read_only: true - property :card_uri, read_only: true - property :created_at, type: :time, read_only: true - property :deleted, type: :bool, read_only: true - property :id, read_only: true - property :image_display_height, read_only: true - property :image_display_width, read_only: true - property :updated_at, type: :time, read_only: true - property :media_url, read_only: true - - property :country_code - property :app_cta - property :googleplay_app_id - property :googleplay_deep_link - property :ios_app_store_identifier - property :ios_deep_link - property :name - property :media_key - - RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/" \ - 'accounts/%{account_id}/cards/image_app_download' # @api private - RESOURCE = "/#{TwitterAds::API_VERSION}/" \ - 'accounts/%{account_id}/cards/image_app_download/%{id}' # @api private - - def initialize(account) - @account = account - self - end - - end - - end -end diff --git a/lib/twitter-ads/creative/video_app_download_card.rb b/lib/twitter-ads/creative/video_app_download_card.rb deleted file mode 100644 index 9038b24b..00000000 --- a/lib/twitter-ads/creative/video_app_download_card.rb +++ /dev/null @@ -1,48 +0,0 @@ -# frozen_string_literal: true -# Copyright (C) 2019 Twitter, Inc. - -module TwitterAds - module Creative - - class VideoAppDownloadCard - - include TwitterAds::DSL - include TwitterAds::Resource - include TwitterAds::Persistence - - attr_reader :account - - property :card_type, read_only: true - property :card_uri, read_only: true - property :created_at, type: :time, read_only: true - property :deleted, type: :bool, read_only: true - property :id, read_only: true - property :updated_at, type: :time, read_only: true - property :video_owner_id, read_only: true - property :poster_media_url, read_only: true - property :media_url, read_only: true - - property :country_code - property :app_cta - property :poster_media_key - property :ios_app_store_identifier - property :ios_deep_link - property :googleplay_app_id - property :googleplay_deep_link - property :name - property :media_key - - RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/" \ - 'accounts/%{account_id}/cards/video_app_download' # @api private - RESOURCE = "/#{TwitterAds::API_VERSION}/" \ - 'accounts/%{account_id}/cards/video_app_download/%{id}' # @api private - - def initialize(account) - @account = account - self - end - - end - - end -end diff --git a/lib/twitter-ads/creative/video_website_card.rb b/lib/twitter-ads/creative/video_website_card.rb deleted file mode 100644 index aa46b345..00000000 --- a/lib/twitter-ads/creative/video_website_card.rb +++ /dev/null @@ -1,50 +0,0 @@ -# frozen_string_literal: true -# Copyright (C) 2019 Twitter, Inc. - -module TwitterAds - module Creative - - class VideoWebsiteCard - - include TwitterAds::DSL - include TwitterAds::Resource - include TwitterAds::Persistence - - attr_reader :account - - property :account_id, read_only: true - property :card_type, read_only: true - property :card_uri, read_only: true - property :created_at, type: :time, read_only: true - property :deleted, type: :bool, read_only: true - property :id, read_only: true - property :updated_at, type: :time, read_only: true - property :video_height, read_only: true - property :video_owner_id, read_only: true - property :video_poster_height, read_only: true - property :poster_media_url, read_only: true - property :video_poster_width, read_only: true - property :media_url, read_only: true - property :video_width, read_only: true - property :website_display_url, read_only: true - property :website_dest_url, read_only: true - - property :name - property :title - property :media_key - property :website_url - - RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/accounts/%{account_id}/cards/video_website" - # @api private - RESOURCE = "/#{TwitterAds::API_VERSION}/" \ - 'accounts/%{account_id}/cards/video_website/%{id}' # @api private - - def initialize(account) - @account = account - self - end - - end - - end -end diff --git a/lib/twitter-ads/creative/website_card.rb b/lib/twitter-ads/creative/website_card.rb deleted file mode 100644 index 17699cef..00000000 --- a/lib/twitter-ads/creative/website_card.rb +++ /dev/null @@ -1,45 +0,0 @@ -# frozen_string_literal: true -# Copyright (C) 2019 Twitter, Inc. - -module TwitterAds - module Creative - - class WebsiteCard - - include TwitterAds::DSL - include TwitterAds::Resource - include TwitterAds::Persistence - - attr_reader :account - - property :card_type, read_only: true - property :card_uri, read_only: true - property :created_at, type: :time, read_only: true - property :deleted, type: :bool, read_only: true - property :id, read_only: true - property :media_url, read_only: true - property :image_display_height, read_only: true - property :image_display_width, read_only: true - property :updated_at, type: :time, read_only: true - property :website_dest_url, read_only: true - property :website_display_url, read_only: true - - property :media_key - property :name - property :website_title - property :website_url - - RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/accounts/%{account_id}/cards/website" - # @api private - RESOURCE = "/#{TwitterAds::API_VERSION}/accounts/%{account_id}/cards/website/%{id}" - # @api private - - def initialize(account) - @account = account - self - end - - end - - end -end diff --git a/lib/twitter-ads/enum.rb b/lib/twitter-ads/enum.rb index 9eb42361..9fc92702 100644 --- a/lib/twitter-ads/enum.rb +++ b/lib/twitter-ads/enum.rb @@ -234,5 +234,9 @@ module TimelineType NULLCAST = 'NULLCAST' ORGANIC = 'ORGANIC' end + + module BudgetOptimization + CAMPAIGN = 'CAMPAIGN' + end end end diff --git a/lib/twitter-ads/resources/analytics.rb b/lib/twitter-ads/resources/analytics.rb index 9c97095d..fae47e1a 100644 --- a/lib/twitter-ads/resources/analytics.rb +++ b/lib/twitter-ads/resources/analytics.rb @@ -14,7 +14,6 @@ class Analytics attr_reader :account property :id, read_only: true - property :id_str, read_only: true property :status, read_only: true property :url, read_only: true property :created_at, type: :time, read_only: true diff --git a/lib/twitter-ads/version.rb b/lib/twitter-ads/version.rb index 0d087d77..2854ce99 100644 --- a/lib/twitter-ads/version.rb +++ b/lib/twitter-ads/version.rb @@ -2,5 +2,5 @@ # Copyright (C) 2019 Twitter, Inc. module TwitterAds - VERSION = '10.1.0' + VERSION = '11.0.0' end diff --git a/spec/fixtures/cards_all.json b/spec/fixtures/cards_all.json new file mode 100644 index 00000000..1feec127 --- /dev/null +++ b/spec/fixtures/cards_all.json @@ -0,0 +1,836 @@ +{ + "request": { + "params": { + "account_id": "2iqph" + } + }, + "next_cursor": null, + "data": [ + { + "name": "website carousel", + "components": [ + { + "media_key": "13_794652834998325248", + "media_metadata": { + "13_794652834998325248": { + "type": "VIDEO", + "url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", + "width": 640, + "height": 360, + "video_duration": 7967, + "video_aspect_ratio": "16:9" + } + }, + "type": "MEDIA" + }, + { + "title": "Twitter", + "destination": { + "url": "https://www.dell.de/", + "type": "WEBSITE" + }, + "type": "DETAILS" + } + ], + "id": "1340029888649076737", + "created_at": "2020-12-18T20:23:16Z", + "card_uri": "card://1340029888649076737", + "updated_at": "2021-08-26T19:09:58Z", + "deleted": false, + "card_type": "VIDEO_WEBSITE" + }, + { + "name": "video website card", + "components": [ + { + "media_key": "13_794652834998325248", + "media_metadata": { + "13_794652834998325248": { + "type": "VIDEO", + "url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", + "width": 640, + "height": 360, + "video_duration": 7967, + "video_aspect_ratio": "16:9" + } + }, + "type": "MEDIA" + }, + { + "title": "Twitter", + "destination": { + "url": "http://twitter.com/", + "type": "WEBSITE" + }, + "type": "DETAILS" + } + ], + "id": "1410461519343591424", + "created_at": "2021-07-01T04:53:25Z", + "card_uri": "card://1410461519343591424", + "updated_at": "2021-08-26T19:09:58Z", + "deleted": false, + "card_type": "VIDEO_WEBSITE" + }, + { + "name": "video website card", + "components": [ + { + "media_key": "13_794652834998325248", + "media_metadata": { + "13_794652834998325248": { + "type": "VIDEO", + "url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", + "width": 640, + "height": 360, + "video_duration": 7967, + "video_aspect_ratio": "16:9" + } + }, + "type": "MEDIA" + }, + { + "title": "Twitter", + "destination": { + "url": "http://twitter.com/", + "type": "WEBSITE" + }, + "type": "DETAILS" + } + ], + "id": "1410461595289853954", + "created_at": "2021-07-01T04:53:44Z", + "card_uri": "card://1410461595289853954", + "updated_at": "2021-08-26T19:09:58Z", + "deleted": false, + "card_type": "VIDEO_WEBSITE" + }, + { + "name": "video website card", + "components": [ + { + "media_key": "13_794652834998325248", + "media_metadata": { + "13_794652834998325248": { + "type": "VIDEO", + "url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", + "width": 640, + "height": 360, + "video_duration": 7967, + "video_aspect_ratio": "16:9" + } + }, + "type": "MEDIA" + }, + { + "title": "Twitter", + "destination": { + "url": "http://twitter.com/", + "type": "WEBSITE" + }, + "type": "DETAILS" + } + ], + "id": "1410461798390591491", + "created_at": "2021-07-01T04:54:32Z", + "card_uri": "card://1410461798390591491", + "updated_at": "2021-08-26T19:09:58Z", + "deleted": false, + "card_type": "VIDEO_WEBSITE" + }, + { + "name": "video website card", + "components": [ + { + "media_key": "13_794652834998325248", + "media_metadata": { + "13_794652834998325248": { + "type": "VIDEO", + "url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", + "width": 640, + "height": 360, + "video_duration": 7967, + "video_aspect_ratio": "16:9" + } + }, + "type": "MEDIA" + }, + { + "title": "Twitter", + "destination": { + "url": "http://twitter.com/", + "type": "WEBSITE" + }, + "type": "DETAILS" + } + ], + "id": "1410461877499359237", + "created_at": "2021-07-01T04:54:51Z", + "card_uri": "card://1410461877499359237", + "updated_at": "2021-08-26T19:09:58Z", + "deleted": false, + "card_type": "VIDEO_WEBSITE" + }, + { + "name": "video website card", + "components": [ + { + "media_key": "13_794652834998325248", + "media_metadata": { + "13_794652834998325248": { + "type": "VIDEO", + "url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", + "width": 640, + "height": 360, + "video_duration": 7967, + "video_aspect_ratio": "16:9" + } + }, + "type": "MEDIA" + }, + { + "title": "Twitter", + "destination": { + "url": "http://twitter.com/", + "type": "WEBSITE" + }, + "type": "DETAILS" + } + ], + "id": "1410461997494276100", + "created_at": "2021-07-01T04:55:19Z", + "card_uri": "card://1410461997494276100", + "updated_at": "2021-08-26T19:09:58Z", + "deleted": false, + "card_type": "VIDEO_WEBSITE" + }, + { + "name": "video website card", + "components": [ + { + "media_key": "13_794652834998325248", + "media_metadata": { + "13_794652834998325248": { + "type": "VIDEO", + "url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", + "width": 640, + "height": 360, + "video_duration": 7967, + "video_aspect_ratio": "16:9" + } + }, + "type": "MEDIA" + }, + { + "title": "Twitter", + "destination": { + "url": "http://twitter.com/", + "type": "WEBSITE" + }, + "type": "DETAILS" + } + ], + "id": "1410462120282521603", + "created_at": "2021-07-01T04:55:49Z", + "card_uri": "card://1410462120282521603", + "updated_at": "2021-08-26T19:09:58Z", + "deleted": false, + "card_type": "VIDEO_WEBSITE" + }, + { + "name": "video website card", + "components": [ + { + "media_key": "13_794652834998325248", + "media_metadata": { + "13_794652834998325248": { + "type": "VIDEO", + "url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", + "width": 640, + "height": 360, + "video_duration": 7967, + "video_aspect_ratio": "16:9" + } + }, + "type": "MEDIA" + }, + { + "title": "Twitter", + "destination": { + "url": "http://twitter.com/", + "type": "WEBSITE" + }, + "type": "DETAILS" + } + ], + "id": "1410462217586102272", + "created_at": "2021-07-01T04:56:12Z", + "card_uri": "card://1410462217586102272", + "updated_at": "2021-08-26T19:09:58Z", + "deleted": false, + "card_type": "VIDEO_WEBSITE" + }, + { + "name": "video website card", + "components": [ + { + "media_key": "13_794652834998325248", + "media_metadata": { + "13_794652834998325248": { + "type": "VIDEO", + "url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", + "width": 640, + "height": 360, + "video_duration": 7967, + "video_aspect_ratio": "16:9" + } + }, + "type": "MEDIA" + }, + { + "title": "Twitter", + "destination": { + "url": "http://twitter.com/", + "type": "WEBSITE" + }, + "type": "DETAILS" + } + ], + "id": "1410462382632042496", + "created_at": "2021-07-01T04:56:51Z", + "card_uri": "card://1410462382632042496", + "updated_at": "2021-08-26T19:09:58Z", + "deleted": false, + "card_type": "VIDEO_WEBSITE" + }, + { + "name": "video website card", + "components": [ + { + "media_key": "13_794652834998325248", + "media_metadata": { + "13_794652834998325248": { + "type": "VIDEO", + "url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", + "width": 640, + "height": 360, + "video_duration": 7967, + "video_aspect_ratio": "16:9" + } + }, + "type": "MEDIA" + }, + { + "title": "Twitter", + "destination": { + "url": "http://twitter.com/", + "type": "WEBSITE" + }, + "type": "DETAILS" + } + ], + "id": "1410702122887237632", + "created_at": "2021-07-01T20:49:30Z", + "card_uri": "card://1410702122887237632", + "updated_at": "2021-08-26T19:09:58Z", + "deleted": false, + "card_type": "VIDEO_WEBSITE" + }, + { + "name": "video website card", + "components": [ + { + "media_key": "13_794652834998325248", + "media_metadata": { + "13_794652834998325248": { + "type": "VIDEO", + "url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", + "width": 640, + "height": 360, + "video_duration": 7967, + "video_aspect_ratio": "16:9" + } + }, + "type": "MEDIA" + }, + { + "title": "Twitter", + "destination": { + "url": "http://twitter.com/", + "type": "WEBSITE" + }, + "type": "DETAILS" + } + ], + "id": "1410702325044301827", + "created_at": "2021-07-01T20:50:18Z", + "card_uri": "card://1410702325044301827", + "updated_at": "2021-08-26T19:09:58Z", + "deleted": false, + "card_type": "VIDEO_WEBSITE" + }, + { + "name": "video website card", + "components": [ + { + "media_key": "13_794652834998325248", + "media_metadata": { + "13_794652834998325248": { + "type": "VIDEO", + "url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", + "width": 640, + "height": 360, + "video_duration": 7967, + "video_aspect_ratio": "16:9" + } + }, + "type": "MEDIA" + }, + { + "title": "Twitter", + "destination": { + "url": "http://twitter.com/", + "type": "WEBSITE" + }, + "type": "DETAILS" + } + ], + "id": "1410702487212883969", + "created_at": "2021-07-01T20:50:57Z", + "card_uri": "card://1410702487212883969", + "updated_at": "2021-08-26T19:09:58Z", + "deleted": false, + "card_type": "VIDEO_WEBSITE" + }, + { + "name": "video website card", + "components": [ + { + "media_key": "13_794652834998325248", + "media_metadata": { + "13_794652834998325248": { + "type": "VIDEO", + "url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", + "width": 640, + "height": 360, + "video_duration": 7967, + "video_aspect_ratio": "16:9" + } + }, + "type": "MEDIA" + }, + { + "title": "Twitter", + "destination": { + "url": "http://twitter.com/", + "type": "WEBSITE" + }, + "type": "DETAILS" + } + ], + "id": "1410702742541148162", + "created_at": "2021-07-01T20:51:58Z", + "card_uri": "card://1410702742541148162", + "updated_at": "2021-08-26T19:09:58Z", + "deleted": false, + "card_type": "VIDEO_WEBSITE" + }, + { + "name": "video website card", + "components": [ + { + "media_key": "13_794652834998325248", + "media_metadata": { + "13_794652834998325248": { + "type": "VIDEO", + "url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", + "width": 640, + "height": 360, + "video_duration": 7967, + "video_aspect_ratio": "16:9" + } + }, + "type": "MEDIA" + }, + { + "title": "Twitter", + "destination": { + "url": "http://twitter.com/", + "type": "WEBSITE" + }, + "type": "DETAILS" + } + ], + "id": "1410703177888849923", + "created_at": "2021-07-01T20:53:41Z", + "card_uri": "card://1410703177888849923", + "updated_at": "2021-08-26T19:09:58Z", + "deleted": false, + "card_type": "VIDEO_WEBSITE" + }, + { + "name": "video website card", + "components": [ + { + "media_key": "13_794652834998325248", + "media_metadata": { + "13_794652834998325248": { + "type": "VIDEO", + "url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", + "width": 640, + "height": 360, + "video_duration": 7967, + "video_aspect_ratio": "16:9" + } + }, + "type": "MEDIA" + }, + { + "title": "Twitter", + "destination": { + "url": "http://twitter.com/", + "type": "WEBSITE" + }, + "type": "DETAILS" + } + ], + "id": "1410703377667821568", + "created_at": "2021-07-01T20:54:29Z", + "card_uri": "card://1410703377667821568", + "updated_at": "2021-08-26T19:09:58Z", + "deleted": false, + "card_type": "VIDEO_WEBSITE" + }, + { + "name": "new card pytest", + "components": [ + { + "media_key": "13_794652834998325248", + "media_metadata": { + "13_794652834998325248": { + "type": "VIDEO", + "url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", + "width": 640, + "height": 360, + "video_duration": 7967, + "video_aspect_ratio": "16:9" + } + }, + "type": "MEDIA" + }, + { + "title": "Twitter", + "destination": { + "url": "http://twitter.com/", + "type": "WEBSITE" + }, + "type": "DETAILS" + } + ], + "id": "1502039535651196928", + "created_at": "2022-03-10T21:51:46Z", + "card_uri": "card://1502039535651196928", + "updated_at": "2022-03-10T21:51:46Z", + "deleted": false, + "card_type": "VIDEO_WEBSITE" + }, + { + "name": "new card pytest", + "components": [ + { + "media_key": "13_794652834998325248", + "media_metadata": { + "13_794652834998325248": { + "type": "VIDEO", + "url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", + "width": 640, + "height": 360, + "video_duration": 7967, + "video_aspect_ratio": "16:9" + } + }, + "type": "MEDIA" + }, + { + "title": "Twitter", + "destination": { + "url": "http://twitter.com/", + "type": "WEBSITE" + }, + "type": "DETAILS" + } + ], + "id": "1502039980394254337", + "created_at": "2022-03-10T21:53:32Z", + "card_uri": "card://1502039980394254337", + "updated_at": "2022-03-10T21:53:32Z", + "deleted": false, + "card_type": "VIDEO_WEBSITE" + }, + { + "name": "new card pytest", + "components": [ + { + "media_key": "13_794652834998325248", + "media_metadata": { + "13_794652834998325248": { + "type": "VIDEO", + "url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", + "width": 640, + "height": 360, + "video_duration": 7967, + "video_aspect_ratio": "16:9" + } + }, + "type": "MEDIA" + }, + { + "title": "Twitter", + "destination": { + "url": "http://twitter.com/newvalue", + "type": "WEBSITE" + }, + "type": "DETAILS" + } + ], + "id": "1502039983049232388", + "created_at": "2022-03-10T21:53:33Z", + "card_uri": "card://1502039983049232388", + "updated_at": "2022-03-10T21:53:33Z", + "deleted": false, + "card_type": "VIDEO_WEBSITE" + }, + { + "name": "new card pytest", + "components": [ + { + "media_key": "13_794652834998325248", + "media_metadata": { + "13_794652834998325248": { + "type": "VIDEO", + "url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", + "width": 640, + "height": 360, + "video_duration": 7967, + "video_aspect_ratio": "16:9" + } + }, + "type": "MEDIA" + }, + { + "title": "Twitter", + "destination": { + "url": "http://twitter.com/", + "type": "WEBSITE" + }, + "type": "DETAILS" + } + ], + "id": "1502039996441628673", + "created_at": "2022-03-10T21:53:36Z", + "card_uri": "card://1502039996441628673", + "updated_at": "2022-03-10T21:53:36Z", + "deleted": false, + "card_type": "VIDEO_WEBSITE" + }, + { + "name": "new card pytest", + "components": [ + { + "media_key": "13_794652834998325248", + "media_metadata": { + "13_794652834998325248": { + "type": "VIDEO", + "url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", + "width": 640, + "height": 360, + "video_duration": 7967, + "video_aspect_ratio": "16:9" + } + }, + "type": "MEDIA" + }, + { + "title": "Twitter", + "destination": { + "url": "http://twitter.com/newvalue", + "type": "WEBSITE" + }, + "type": "DETAILS" + } + ], + "id": "1502039998987587584", + "created_at": "2022-03-10T21:53:36Z", + "card_uri": "card://1502039998987587584", + "updated_at": "2022-03-10T21:53:36Z", + "deleted": false, + "card_type": "VIDEO_WEBSITE" + }, + { + "name": "my new card", + "components": [ + { + "media_key": "13_794652834998325248", + "media_metadata": { + "13_794652834998325248": { + "type": "VIDEO", + "url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", + "width": 640, + "height": 360, + "video_duration": 7967, + "video_aspect_ratio": "16:9" + } + }, + "type": "MEDIA" + }, + { + "title": "Twitter", + "destination": { + "url": "http://twitter.com/login", + "type": "WEBSITE" + }, + "type": "DETAILS" + } + ], + "id": "1503829009708175360", + "created_at": "2022-03-15T20:22:30Z", + "card_uri": "card://1503829009708175360", + "updated_at": "2022-03-15T20:22:30Z", + "deleted": false, + "card_type": "VIDEO_WEBSITE" + }, + { + "name": "my new card", + "components": [ + { + "media_key": "13_794652834998325248", + "media_metadata": { + "13_794652834998325248": { + "type": "VIDEO", + "url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", + "width": 640, + "height": 360, + "video_duration": 7967, + "video_aspect_ratio": "16:9" + } + }, + "type": "MEDIA" + }, + { + "title": "Twitter", + "destination": { + "url": "http://twitter.com/login", + "type": "WEBSITE" + }, + "type": "DETAILS" + } + ], + "id": "1503829523753697280", + "created_at": "2022-03-15T20:24:32Z", + "card_uri": "card://1503829523753697280", + "updated_at": "2022-03-15T20:24:32Z", + "deleted": false, + "card_type": "VIDEO_WEBSITE" + }, + { + "name": "my new card", + "components": [ + { + "media_key": "13_794652834998325248", + "media_metadata": { + "13_794652834998325248": { + "type": "VIDEO", + "url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", + "width": 640, + "height": 360, + "video_duration": 7967, + "video_aspect_ratio": "16:9" + } + }, + "type": "MEDIA" + }, + { + "title": "Twitter", + "destination": { + "url": "http://twitter.com/login", + "type": "WEBSITE" + }, + "type": "DETAILS" + } + ], + "id": "1503829695233617920", + "created_at": "2022-03-15T20:25:13Z", + "card_uri": "card://1503829695233617920", + "updated_at": "2022-03-15T20:25:13Z", + "deleted": false, + "card_type": "VIDEO_WEBSITE" + }, + { + "name": "my new card", + "components": [ + { + "media_key": "13_794652834998325248", + "media_metadata": { + "13_794652834998325248": { + "type": "VIDEO", + "url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", + "width": 640, + "height": 360, + "video_duration": 7967, + "video_aspect_ratio": "16:9" + } + }, + "type": "MEDIA" + }, + { + "title": "Twitter", + "destination": { + "url": "http://twitter.com/login", + "type": "WEBSITE" + }, + "type": "DETAILS" + } + ], + "id": "1503829883746598912", + "created_at": "2022-03-15T20:25:58Z", + "card_uri": "card://1503829883746598912", + "updated_at": "2022-03-15T20:25:58Z", + "deleted": false, + "card_type": "VIDEO_WEBSITE" + }, + { + "name": "my new card", + "components": [ + { + "media_key": "13_794652834998325248", + "media_metadata": { + "13_794652834998325248": { + "type": "VIDEO", + "url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", + "width": 640, + "height": 360, + "video_duration": 7967, + "video_aspect_ratio": "16:9" + } + }, + "type": "MEDIA" + }, + { + "title": "Twitter", + "destination": { + "url": "http://twitter.com/login", + "type": "WEBSITE" + }, + "type": "DETAILS" + } + ], + "id": "1503831318555086849", + "created_at": "2022-03-15T20:31:40Z", + "card_uri": "card://1503831318555086849", + "updated_at": "2022-03-15T20:31:40Z", + "deleted": false, + "card_type": "VIDEO_WEBSITE" + } + ] + } + \ No newline at end of file diff --git a/spec/fixtures/cards_load.json b/spec/fixtures/cards_load.json new file mode 100644 index 00000000..502f8748 --- /dev/null +++ b/spec/fixtures/cards_load.json @@ -0,0 +1,42 @@ +{ + "request": { + "params": { + "account_id": "2iqph", + "card_id": "1503831318555086849" + } + }, + "data": { + "name": "my new card", + "components": [ + { + "media_key": "13_794652834998325248", + "media_metadata": { + "13_794652834998325248": { + "type": "VIDEO", + "url": "https://video.twimg.com/amplify_video/794652834998325248/vid/640x360/pUgE2UKcfPwF_5Uh.mp4", + "width": 640, + "height": 360, + "video_duration": 7967, + "video_aspect_ratio": "16:9" + } + }, + "type": "MEDIA" + }, + { + "title": "Twitter", + "destination": { + "url": "http://twitter.com/login", + "type": "WEBSITE" + }, + "type": "DETAILS" + } + ], + "id": "1503831318555086849", + "created_at": "2022-03-15T20:31:40Z", + "card_uri": "card://1503831318555086849", + "updated_at": "2022-03-15T20:31:40Z", + "deleted": false, + "card_type": "VIDEO_WEBSITE" + } + } + \ No newline at end of file diff --git a/spec/twitter-ads/campaign/line_item_spec.rb b/spec/twitter-ads/campaign/line_item_spec.rb index c3299b70..7cd5fec3 100644 --- a/spec/twitter-ads/campaign/line_item_spec.rb +++ b/spec/twitter-ads/campaign/line_item_spec.rb @@ -44,6 +44,7 @@ total_budget_amount_local_micro goal ios_app_store_identifier + standard_delivery ) include_examples 'object property check', read, write diff --git a/spec/twitter-ads/creative/cards_spec.rb b/spec/twitter-ads/creative/cards_spec.rb new file mode 100644 index 00000000..cc99c8f1 --- /dev/null +++ b/spec/twitter-ads/creative/cards_spec.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true +# Copyright (C) 2019 Twitter, Inc. + +require 'spec_helper' + +include TwitterAds::Enum + +describe TwitterAds::Creative::Cards do + + let!(:resource) { "#{ADS_API}/accounts/2iqph/cards" } + + before(:each) do + stub_fixture(:get, :accounts_load, "#{ADS_API}/accounts/2iqph") + + resource_collection = "#{ADS_API}/accounts/#{account.id}/cards" + stub_fixture(:get, :cards_all, resource_collection) + + resource = "#{ADS_API}/accounts/#{account.id}/cards/1508693734346485761" + stub_fixture(:get, :cards_load, /#{resource}\?.*/) + end + + let(:client) do + Client.new( + Faker::Lorem.characters(40), + Faker::Lorem.characters(40), + Faker::Lorem.characters(40), + Faker::Lorem.characters(40) + ) + end + + let(:account) { client.accounts('2iqph') } + + it 'inspect Cards.load() response' do + card = described_class.load(account, '1508693734346485761') + + expect(card).to be_instance_of(TwitterAds::Creative::Cards) + expect(card.id).to eq '1503831318555086849' + expect(card.card_type).to eq 'VIDEO_WEBSITE' + expect(card.card_uri).to eq 'card://1503831318555086849' + end + + it 'inspect Cards.all() response' do + cards = described_class.all(account) + + expect(cards).to be_instance_of(Cursor) + card = cards.first + expect(card.id).to eq '1340029888649076737' + expect(card.card_type).to eq 'VIDEO_WEBSITE' + expect(card.card_uri).to eq 'card://1340029888649076737' + end + +end