Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v6 updates #210

Merged
merged 15 commits into from
Sep 18, 2019
6 changes: 5 additions & 1 deletion examples/draft_tweet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
# load up the account instance, campaign and line item
account = client.accounts(ADS_ACCOUNT)

# get user_id for as_user_id parameter
user_id = TwitterRestApi::UserIdLookup.load(account, screen_name: 'your_twitter_handle_name').id

# fetch draft tweets from a given account
tweets = TwitterAds::Creative::DraftTweet.all(account)
tweets.each { |tweet|
Expand All @@ -30,6 +33,7 @@
# create a new draft tweet
draft_tweet = TwitterAds::Creative::DraftTweet.new(account)
draft_tweet.text = 'draft tweet - new'
draft_tweet.as_user_id = user_id
draft_tweet.save
p draft_tweet.id_str
p draft_tweet.text
Expand All @@ -52,7 +56,7 @@
# draft_tweet.preview(draft_tweet_id: '1142048306194862080')

# create a nullcasted tweet using draft tweet metadata
tweet = TwitterAds::Tweet.create(account, text: draft_tweet.text)
tweet = TwitterAds::Tweet.create(account, text: draft_tweet.text, as_user_id: user_id)
p tweet

# delete draft tweet
Expand Down
8 changes: 6 additions & 2 deletions examples/promoted_tweet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
campaign = account.campaigns.first
line_item = account.line_items(nil, campaign_ids: campaign.id).first

# get user_id for as_user_id parameter
user_id = TwitterRestApi::UserIdLookup.load(account, screen_name: 'your_twitter_handle_name').id

# create request for a simple nullcasted tweet
tweet1 = TwitterAds::Tweet.create(account, text: 'There can be only one...')
tweet1 = TwitterAds::Tweet.create(account, text: 'There can be only one...', as_user_id: user_id)

# promote the tweet using our line item
promoted_tweet = TwitterAds::Creative::PromotedTweet.new(account)
Expand All @@ -36,7 +39,8 @@
tweet2 = TwitterAds::Tweet.create(
account,
text: 'Fine. There can be two.',
card_uri: website_card.card_uri
card_uri: website_card.card_uri,
as_user_id: user_id
)

# promote the tweet using our line item
Expand Down
3 changes: 3 additions & 0 deletions lib/twitter-ads.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
require 'twitter-ads/http/request'
require 'twitter-ads/http/response'

require 'twitter-ads/restapi.rb'

require 'twitter-ads/audiences/tailored_audience'

require 'twitter-ads/campaign/app_list'
Expand Down Expand Up @@ -69,6 +71,7 @@
require 'twitter-ads/creative/website_card'
require 'twitter-ads/creative/poll_cards'
require 'twitter-ads/creative/tweet_previews'
require 'twitter-ads/creative/tweets'

require 'twitter-ads/targeting/reach_estimate'

Expand Down
17 changes: 9 additions & 8 deletions lib/twitter-ads/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ class Account
property :updated_at, type: :time, read_only: true
property :deleted, type: :bool, read_only: true

RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/" \
'accounts' # @api private
RESOURCE = "/#{TwitterAds::API_VERSION}/" \
'accounts/%{id}' # @api private
FEATURES = "/#{TwitterAds::API_VERSION}/" \
'accounts/%{id}/features' # @api private
SCOPED_TIMELINE = "/#{TwitterAds::API_VERSION}/" \
'accounts/%{id}/scoped_timeline' # @api private
RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/" \
'accounts' # @api private
RESOURCE = "/#{TwitterAds::API_VERSION}/" \
'accounts/%{id}' # @api private
FEATURES = "/#{TwitterAds::API_VERSION}/" \
'accounts/%{id}/features' # @api private
SCOPED_TIMELINE = '/5/accounts/%{id}/scoped_timeline' # @api private
AUTHENTICATED_USER_ACCESS = "/#{TwitterAds::API_VERSION}/" \
'accounts/%{id}/authenticated_user_access' # @api private

Expand Down Expand Up @@ -257,6 +256,8 @@ def tailored_audiences(id = nil, opts = {})
#
# @since 0.2.3
def scoped_timeline(id, opts = {})
TwitterAds::Utils.deprecated(
'Scoped Timeline')
params = { user_id: id }.merge!(opts)
resource = SCOPED_TIMELINE % { id: @id }
request = Request.new(client, :get, resource, params: params)
Expand Down
3 changes: 1 addition & 2 deletions lib/twitter-ads/campaign/campaign.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
# Copyright (C) 2019 Twitter, Inc.

module TwitterAds
class Campaign
class Campaign < Analytics

include TwitterAds::DSL
include TwitterAds::Resource
include TwitterAds::Persistence
include TwitterAds::Analytics
include TwitterAds::Batch

attr_reader :account
Expand Down
3 changes: 1 addition & 2 deletions lib/twitter-ads/campaign/funding_instrument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
# Copyright (C) 2019 Twitter, Inc.

module TwitterAds
class FundingInstrument
class FundingInstrument < Analytics

include TwitterAds::DSL
include TwitterAds::Resource
include TwitterAds::Analytics

attr_reader :account

Expand Down
5 changes: 2 additions & 3 deletions lib/twitter-ads/campaign/line_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
# Copyright (C) 2019 Twitter, Inc.

module TwitterAds
class LineItem
class LineItem < Analytics

include TwitterAds::DSL
include TwitterAds::Resource
include TwitterAds::Persistence
include TwitterAds::Analytics
include TwitterAds::Batch

attr_reader :account
Expand Down Expand Up @@ -40,7 +39,7 @@ class LineItem
property :advertiser_user_id
property :bid_type
property :tracking_tags
property :lookalike_expansion
property :audience_expansion

# sdk only
property :to_delete, type: :bool
Expand Down
4 changes: 1 addition & 3 deletions lib/twitter-ads/campaign/organic_tweet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
# Author Bob, Nugit

module TwitterAds
class OrganicTweet

include TwitterAds::Analytics
class OrganicTweet < Analytics

end
end
1 change: 0 additions & 1 deletion lib/twitter-ads/campaign/targeting_criteria.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class TargetingCriteria
property :targeting_type
property :targeting_value
property :tailored_audience_expansion, type: :bool
property :tailored_audience_type
property :location_type

# sdk only
Expand Down
8 changes: 2 additions & 6 deletions lib/twitter-ads/campaign/tweet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
# Copyright (C) 2019 Twitter, Inc.

module TwitterAds
module Tweet

# cannot instaniate Tweet, only including class methods for stats
extend TwitterAds::Analytics::ClassMethods
class Tweet < Analytics

RESOURCE_CREATE = "/#{TwitterAds::API_VERSION}/" \
'accounts/%{account_id}/tweet' # @api private
Expand All @@ -17,10 +14,9 @@ class << self
# @param opts [Hash] A hash of options.
#
# @option opts [String] :text The main Tweet body.
# @option opts [Array] :media_ids A list of up to four media IDs to associate with the Tweet.
# @option opts [Array] :media_keys A list of media keys (up to 4) to associate with the Tweet.
# @option opts [Integer] :as_user_id The user ID whom you are posting the Tweet on behalf of.
# @option opts [Boolean] :trim_user Excludes the user object from the hydrated Tweet response.
# @option opts [String] :video_id The Video UUID to be associated with thie Tweet.
# @option opts [String] :video_title An optional title to be included.
# @option opts [String] :video_description An optional description to be included.
# @option opts [String] :video_cta An optional CTA value for the associated video.
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter-ads/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

module TwitterAds

API_VERSION = '5'
API_VERSION = '6'

# The Ads API Client class which functions as a
# container for basic API consumer information.
Expand Down
10 changes: 4 additions & 6 deletions lib/twitter-ads/creative/account_media.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ class AccountMedia

attr_reader :account

property :created_at, type: :time, read_only: true
property :deleted, type: :bool, read_only: true
property :created_at, type: :time, read_only: true
property :updated_at, type: :time, read_only: true
property :id, read_only: true
property :creative_type, read_only: true
property :media_key, read_only: true
property :media_url, read_only: true
property :updated_at, type: :time, read_only: true

property :creative_type
property :media_id
property :video_id

RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/" \
'accounts/%{account_id}/account_media' # @api private
Expand Down
3 changes: 1 addition & 2 deletions lib/twitter-ads/creative/draft_tweet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ class DraftTweet
# read-only
property :id, read_only: true
property :id_str, read_only: true
property :media_keys, 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
# writable
property :as_user_id
property :card_uri
property :media_ids
property :media_keys
property :nullcast, type: :bool
property :text

Expand Down
4 changes: 2 additions & 2 deletions lib/twitter-ads/creative/image_app_download_card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ImageAppDownloadCard
property :image_display_height, read_only: true
property :image_display_width, read_only: true
property :updated_at, type: :time, read_only: true
property :wide_app_image, read_only: true
property :media_url, read_only: true

property :country_code
property :app_cta
Expand All @@ -31,7 +31,7 @@ class ImageAppDownloadCard
property :ipad_app_id
property :ipad_deep_link
property :name
property :wide_app_image_media_id
property :media_key

RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/" \
'accounts/%{account_id}/cards/image_app_download' # @api private
Expand Down
5 changes: 3 additions & 2 deletions lib/twitter-ads/creative/image_conversation_card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ class ImageConversationCard
property :id, read_only: true
property :image, read_only: true
property :updated_at, type: :time, read_only: true
property :media_url, read_only: true

property :cover_image_id
property :unlocked_image_media_key
property :first_cta
property :first_cta_tweet
property :fourth_cta
property :fourth_cta_tweet
property :image_media_id
property :media_key
property :name
property :second_cta
property :second_cta_tweet
Expand Down
3 changes: 1 addition & 2 deletions lib/twitter-ads/creative/media_creative.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
module TwitterAds
module Creative

class MediaCreative
class MediaCreative < Analytics

include TwitterAds::DSL
include TwitterAds::Resource
include TwitterAds::Persistence
include TwitterAds::Analytics

attr_reader :account

Expand Down
6 changes: 2 additions & 4 deletions lib/twitter-ads/creative/media_library.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,15 @@ class MediaLibrary
property :media_url, read_only: true
property :tweeted, type: :bool, read_only: true
property :updated_at, type: :time, read_only: true
property :poster_image_url, read_only: true
property :poster_media_url, read_only: true

# writable
property :media_category
property :media_id
property :media_key
property :description
property :file_name
property :name
property :poster_image_media_id
property :poster_image_media_key
property :poster_media_key
property :title

RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/" \
Expand Down
3 changes: 1 addition & 2 deletions lib/twitter-ads/creative/promoted_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
module TwitterAds
module Creative

class PromotedAccount
class PromotedAccount < Analytics

include TwitterAds::DSL
include TwitterAds::Resource
include TwitterAds::Persistence
include TwitterAds::Analytics

attr_reader :account

Expand Down
3 changes: 1 addition & 2 deletions lib/twitter-ads/creative/promoted_tweet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
module TwitterAds
module Creative

class PromotedTweet
class PromotedTweet < Analytics

include TwitterAds::DSL
include TwitterAds::Resource
include TwitterAds::Persistence
include TwitterAds::Analytics

attr_reader :account

Expand Down
3 changes: 1 addition & 2 deletions lib/twitter-ads/creative/scheduled_tweet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class ScheduledTweet
property :created_at, type: :time, read_only: true
property :id, read_only: true
property :id_str, read_only: true
property :media_keys, read_only: true
property :scheduled_status, read_only: true
property :tweet_id, read_only: true
property :updated_at, type: :time, read_only: true
Expand All @@ -26,7 +25,7 @@ class ScheduledTweet
# writable
property :as_user_id
property :card_uri
property :media_ids
property :media_keys
property :nullcast, type: :bool
property :scheduled_at, type: :time
property :text
Expand Down
Loading