twitter-ads 5.2.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/lib/twitter-ads.rb +4 -1
  3. data/lib/twitter-ads/account.rb +9 -8
  4. data/lib/twitter-ads/campaign/campaign.rb +1 -2
  5. data/lib/twitter-ads/campaign/funding_instrument.rb +1 -2
  6. data/lib/twitter-ads/campaign/line_item.rb +2 -3
  7. data/lib/twitter-ads/campaign/organic_tweet.rb +1 -3
  8. data/lib/twitter-ads/campaign/targeting_criteria.rb +0 -1
  9. data/lib/twitter-ads/campaign/tweet.rb +4 -49
  10. data/lib/twitter-ads/client.rb +2 -2
  11. data/lib/twitter-ads/creative/account_media.rb +4 -6
  12. data/lib/twitter-ads/creative/draft_tweet.rb +40 -0
  13. data/lib/twitter-ads/creative/image_app_download_card.rb +2 -2
  14. data/lib/twitter-ads/creative/image_conversation_card.rb +3 -2
  15. data/lib/twitter-ads/creative/media_creative.rb +1 -2
  16. data/lib/twitter-ads/creative/media_library.rb +2 -4
  17. data/lib/twitter-ads/creative/promoted_account.rb +1 -2
  18. data/lib/twitter-ads/creative/promoted_tweet.rb +1 -2
  19. data/lib/twitter-ads/creative/scheduled_tweet.rb +1 -12
  20. data/lib/twitter-ads/creative/tweets.rb +52 -0
  21. data/lib/twitter-ads/creative/video_app_download_card.rb +4 -6
  22. data/lib/twitter-ads/creative/video_conversation_card.rb +6 -6
  23. data/lib/twitter-ads/creative/video_website_card.rb +3 -5
  24. data/lib/twitter-ads/creative/website_card.rb +2 -2
  25. data/lib/twitter-ads/cursor.rb +6 -0
  26. data/lib/twitter-ads/enum.rb +10 -5
  27. data/lib/twitter-ads/error.rb +5 -15
  28. data/lib/twitter-ads/http/request.rb +30 -1
  29. data/lib/twitter-ads/http/response.rb +1 -13
  30. data/lib/twitter-ads/resources/analytics.rb +99 -47
  31. data/lib/twitter-ads/resources/dsl.rb +8 -1
  32. data/lib/twitter-ads/restapi.rb +29 -0
  33. data/lib/twitter-ads/settings/tax.rb +13 -1
  34. data/lib/twitter-ads/targeting_criteria/conversation.rb +23 -0
  35. data/lib/twitter-ads/utils.rb +23 -0
  36. data/lib/twitter-ads/version.rb +1 -1
  37. data/spec/fixtures/tweet_previews.json +23 -0
  38. data/spec/twitter-ads/campaign/targeting_criteria_spec.rb +0 -1
  39. data/spec/twitter-ads/campaign/tweet_spec.rb +0 -59
  40. data/spec/twitter-ads/client_spec.rb +17 -1
  41. data/spec/twitter-ads/creative/tweet_previews_spec.rb +41 -0
  42. data/spec/twitter-ads/rate_limit_spec.rb +247 -0
  43. data/spec/twitter-ads/retry_count_spec.rb +61 -0
  44. metadata +14 -17
  45. data/lib/twitter-ads/audiences/audience_intelligence.rb +0 -68
  46. data/spec/fixtures/tweet_preview.json +0 -24
  47. data/spec/twitter-ads/creative/account_media_spec.rb +0 -32
  48. data/spec/twitter-ads/creative/image_app_download_card_spec.rb +0 -43
  49. data/spec/twitter-ads/creative/image_conversation_card_spec.rb +0 -40
  50. data/spec/twitter-ads/creative/video_app_download_card_spec.rb +0 -42
  51. data/spec/twitter-ads/creative/video_conversation_card_spec.rb +0 -51
  52. data/spec/twitter-ads/creative/website_card_spec.rb +0 -42
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3cd47b38d08667bf292088700123342cf46e6576a3cb9a315ae9011517f85db4
4
- data.tar.gz: d8d0de8d946a946c483373d0a01cfbd716a0c43e2c48932e3dc77a091d4bdfeb
3
+ metadata.gz: '05206182b0393791a3d5541b133b276f37fbd7bd440db7977b5fb7f17b3c3abc'
4
+ data.tar.gz: 72617e530b12e11efed8b8c33a259a5aaa26b50088da58f66e9e9c234047bcb1
5
5
  SHA512:
6
- metadata.gz: 5e9298f7816c6a34f72d57ec64a36ca867bd226601486a41de01716283139ac3142788a7b4506567f097e143ebd39ff54bddd34db64bd84599815dd98a4a3a81
7
- data.tar.gz: fb148af4796eaad730508ea7a4b3e63d5bcb36f56270e305707df52c36b96dbb485093bf2998684dcaaa8550e3a3ef8cf80294f1dee740ebc4c931b16d27b31d
6
+ metadata.gz: ce83a7aec3141813b2b93050bd192bb235b4bf8ff4318c2c8807b5bc1de214ccfe5cae7d31c8bacbf8b918850e637d2e72618682679f5ef7f37dc40550268246
7
+ data.tar.gz: 27389f140dc023a6eafc4bc0a758bc6105fe502fab32e3f5b5c6c8ecbb6c6811b0b4542bd0b0ed227760c506d16c3d3f7f1a24909ceb543681c5a8426c0efa5e
data/lib/twitter-ads.rb CHANGED
@@ -27,7 +27,8 @@ require 'twitter-ads/resources/batch'
27
27
  require 'twitter-ads/http/request'
28
28
  require 'twitter-ads/http/response'
29
29
 
30
- require 'twitter-ads/audiences/audience_intelligence'
30
+ require 'twitter-ads/restapi.rb'
31
+
31
32
  require 'twitter-ads/audiences/tailored_audience'
32
33
 
33
34
  require 'twitter-ads/campaign/app_list'
@@ -63,12 +64,14 @@ require 'twitter-ads/creative/media_library'
63
64
  require 'twitter-ads/creative/promoted_account'
64
65
  require 'twitter-ads/creative/promoted_tweet'
65
66
  require 'twitter-ads/creative/scheduled_tweet'
67
+ require 'twitter-ads/creative/draft_tweet'
66
68
  require 'twitter-ads/creative/video_app_download_card'
67
69
  require 'twitter-ads/creative/video_conversation_card'
68
70
  require 'twitter-ads/creative/video_website_card'
69
71
  require 'twitter-ads/creative/website_card'
70
72
  require 'twitter-ads/creative/poll_cards'
71
73
  require 'twitter-ads/creative/tweet_previews'
74
+ require 'twitter-ads/creative/tweets'
72
75
 
73
76
  require 'twitter-ads/targeting/reach_estimate'
74
77
 
@@ -17,14 +17,13 @@ module TwitterAds
17
17
  property :updated_at, type: :time, read_only: true
18
18
  property :deleted, type: :bool, read_only: true
19
19
 
20
- RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/" \
21
- 'accounts' # @api private
22
- RESOURCE = "/#{TwitterAds::API_VERSION}/" \
23
- 'accounts/%{id}' # @api private
24
- FEATURES = "/#{TwitterAds::API_VERSION}/" \
25
- 'accounts/%{id}/features' # @api private
26
- SCOPED_TIMELINE = "/#{TwitterAds::API_VERSION}/" \
27
- 'accounts/%{id}/scoped_timeline' # @api private
20
+ RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/" \
21
+ 'accounts' # @api private
22
+ RESOURCE = "/#{TwitterAds::API_VERSION}/" \
23
+ 'accounts/%{id}' # @api private
24
+ FEATURES = "/#{TwitterAds::API_VERSION}/" \
25
+ 'accounts/%{id}/features' # @api private
26
+ SCOPED_TIMELINE = '/5/accounts/%{id}/scoped_timeline' # @api private
28
27
  AUTHENTICATED_USER_ACCESS = "/#{TwitterAds::API_VERSION}/" \
29
28
  'accounts/%{id}/authenticated_user_access' # @api private
30
29
 
@@ -257,6 +256,8 @@ module TwitterAds
257
256
  #
258
257
  # @since 0.2.3
259
258
  def scoped_timeline(id, opts = {})
259
+ TwitterAds::Utils.deprecated(
260
+ 'Scoped Timeline')
260
261
  params = { user_id: id }.merge!(opts)
261
262
  resource = SCOPED_TIMELINE % { id: @id }
262
263
  request = Request.new(client, :get, resource, params: params)
@@ -2,12 +2,11 @@
2
2
  # Copyright (C) 2019 Twitter, Inc.
3
3
 
4
4
  module TwitterAds
5
- class Campaign
5
+ class Campaign < Analytics
6
6
 
7
7
  include TwitterAds::DSL
8
8
  include TwitterAds::Resource
9
9
  include TwitterAds::Persistence
10
- include TwitterAds::Analytics
11
10
  include TwitterAds::Batch
12
11
 
13
12
  attr_reader :account
@@ -2,11 +2,10 @@
2
2
  # Copyright (C) 2019 Twitter, Inc.
3
3
 
4
4
  module TwitterAds
5
- class FundingInstrument
5
+ class FundingInstrument < Analytics
6
6
 
7
7
  include TwitterAds::DSL
8
8
  include TwitterAds::Resource
9
- include TwitterAds::Analytics
10
9
 
11
10
  attr_reader :account
12
11
 
@@ -2,12 +2,11 @@
2
2
  # Copyright (C) 2019 Twitter, Inc.
3
3
 
4
4
  module TwitterAds
5
- class LineItem
5
+ class LineItem < Analytics
6
6
 
7
7
  include TwitterAds::DSL
8
8
  include TwitterAds::Resource
9
9
  include TwitterAds::Persistence
10
- include TwitterAds::Analytics
11
10
  include TwitterAds::Batch
12
11
 
13
12
  attr_reader :account
@@ -40,7 +39,7 @@ module TwitterAds
40
39
  property :advertiser_user_id
41
40
  property :bid_type
42
41
  property :tracking_tags
43
- property :lookalike_expansion
42
+ property :audience_expansion
44
43
 
45
44
  # sdk only
46
45
  property :to_delete, type: :bool
@@ -3,9 +3,7 @@
3
3
  # Author Bob, Nugit
4
4
 
5
5
  module TwitterAds
6
- class OrganicTweet
7
-
8
- include TwitterAds::Analytics
6
+ class OrganicTweet < Analytics
9
7
 
10
8
  end
11
9
  end
@@ -22,7 +22,6 @@ module TwitterAds
22
22
  property :targeting_type
23
23
  property :targeting_value
24
24
  property :tailored_audience_expansion, type: :bool
25
- property :tailored_audience_type
26
25
  property :location_type
27
26
 
28
27
  # sdk only
@@ -2,66 +2,21 @@
2
2
  # Copyright (C) 2019 Twitter, Inc.
3
3
 
4
4
  module TwitterAds
5
- module Tweet
5
+ class Tweet < Analytics
6
6
 
7
- # cannot instaniate Tweet, only including class methods for stats
8
- extend TwitterAds::Analytics::ClassMethods
9
-
10
- RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/" \
11
- 'accounts/%{account_id}/tweet/preview' # @api private
12
- RESOURCE = "/#{TwitterAds::API_VERSION}/" \
13
- 'accounts/%{account_id}/tweet/preview/%{id}' # @api private
14
- RESOURCE_CREATE = "/#{TwitterAds::API_VERSION}/" \
15
- 'accounts/%{account_id}/tweet' # @api private
7
+ RESOURCE_CREATE = "/#{TwitterAds::API_VERSION}/" \
8
+ 'accounts/%{account_id}/tweet' # @api private
16
9
 
17
10
  class << self
18
11
 
19
- # Returns an HTML preview of a tweet, either new or existing
20
- #
21
- # @example
22
- # Tweet.preview(account, text: 'potatoes can be deadly...')
23
- # Tweet.preview(account, id: 634798319504617472)
24
- #
25
- # @param client [Client] The Client object instance.
26
- # @param account [Account] The Account object instance.
27
- # @param opts [Hash] A hash of options.
28
- #
29
- # @option opts [Integer] :id The ID of an existing Tweet you want to preview.
30
- # @option opts [String] :text The text of your status update.
31
- # @option opts [Array] :media_ids A list of up to four media IDs to associate with the Tweet.
32
- # @option opts [String] :card_id The base-36 ID of a revenue card to be embedded in the Tweet.
33
- # @option opts [String] :preview_target The target to render the Tweet preview
34
- # for (eg. TWITTER_TIMELINES).
35
- #
36
- # @return [Array] An array containing platforms & their respective tweet previews
37
- #
38
- # @since 0.2.0
39
- # @see https://dev.twitter.com/ads/reference/get/accounts/%3Aaccount_id/tweet/preview
40
- def preview(account, opts = {})
41
- resource = opts.key?(:id) ? RESOURCE : RESOURCE_COLLECTION
42
- resource = resource % { account_id: account.id, id: opts.delete(:id) }
43
-
44
- # url encodes status message if present
45
- opts[:text] = URI.escape(opts[:text]) if opts.key?(:text)
46
-
47
- # handles array to string conversion for media IDs
48
- if opts.key?(:media_ids) && opts[:media_ids].respond_to?(:join)
49
- opts[:media_ids] = opts[:media_ids].join(',')
50
- end
51
-
52
- response = TwitterAds::Request.new(account.client, :get, resource, params: opts).perform
53
- response.body[:data]
54
- end
55
-
56
12
  # Creates a "Promoted-Only" Tweet using the specialized Ads API end point.
57
13
  #
58
14
  # @param opts [Hash] A hash of options.
59
15
  #
60
16
  # @option opts [String] :text The main Tweet body.
61
- # @option opts [Array] :media_ids A list of up to four media IDs to associate with the Tweet.
17
+ # @option opts [Array] :media_keys A list of media keys (up to 4) to associate with the Tweet.
62
18
  # @option opts [Integer] :as_user_id The user ID whom you are posting the Tweet on behalf of.
63
19
  # @option opts [Boolean] :trim_user Excludes the user object from the hydrated Tweet response.
64
- # @option opts [String] :video_id The Video UUID to be associated with thie Tweet.
65
20
  # @option opts [String] :video_title An optional title to be included.
66
21
  # @option opts [String] :video_description An optional description to be included.
67
22
  # @option opts [String] :video_cta An optional CTA value for the associated video.
@@ -3,7 +3,7 @@
3
3
 
4
4
  module TwitterAds
5
5
 
6
- API_VERSION = '5'
6
+ API_VERSION = '6'
7
7
 
8
8
  # The Ads API Client class which functions as a
9
9
  # container for basic API consumer information.
@@ -34,7 +34,7 @@ module TwitterAds
34
34
  @consumer_secret = consumer_secret
35
35
  @access_token = access_token
36
36
  @access_token_secret = access_token_secret
37
- @options = opts
37
+ @options = opts.fetch(:options, {})
38
38
  validate
39
39
  self
40
40
  end
@@ -12,15 +12,13 @@ module TwitterAds
12
12
 
13
13
  attr_reader :account
14
14
 
15
- property :created_at, type: :time, read_only: true
16
15
  property :deleted, type: :bool, read_only: true
16
+ property :created_at, type: :time, read_only: true
17
+ property :updated_at, type: :time, read_only: true
17
18
  property :id, read_only: true
19
+ property :creative_type, read_only: true
20
+ property :media_key, read_only: true
18
21
  property :media_url, read_only: true
19
- property :updated_at, type: :time, read_only: true
20
-
21
- property :creative_type
22
- property :media_id
23
- property :video_id
24
22
 
25
23
  RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/" \
26
24
  'accounts/%{account_id}/account_media' # @api private
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+ # Copyright (C) 2019 Twitter, Inc.
3
+
4
+ module TwitterAds
5
+ module Creative
6
+
7
+ class DraftTweet
8
+
9
+ include TwitterAds::DSL
10
+ include TwitterAds::Resource
11
+ include TwitterAds::Persistence
12
+
13
+ attr_reader :account
14
+
15
+ # read-only
16
+ property :id, read_only: true
17
+ property :id_str, read_only: true
18
+ property :created_at, type: :time, read_only: true
19
+ property :updated_at, type: :time, read_only: true
20
+ property :user_id, read_only: true
21
+ # writable
22
+ property :as_user_id
23
+ property :card_uri
24
+ property :media_keys
25
+ property :nullcast, type: :bool
26
+ property :text
27
+
28
+ RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/" \
29
+ 'accounts/%{account_id}/draft_tweets' # @api private
30
+ RESOURCE = "/#{TwitterAds::API_VERSION}/" \
31
+ 'accounts/%{account_id}/draft_tweets/%{id}' # @api private
32
+
33
+ def initialize(account)
34
+ @account = account
35
+ self
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -20,7 +20,7 @@ module TwitterAds
20
20
  property :image_display_height, read_only: true
21
21
  property :image_display_width, read_only: true
22
22
  property :updated_at, type: :time, read_only: true
23
- property :wide_app_image, read_only: true
23
+ property :media_url, read_only: true
24
24
 
25
25
  property :country_code
26
26
  property :app_cta
@@ -31,7 +31,7 @@ module TwitterAds
31
31
  property :ipad_app_id
32
32
  property :ipad_deep_link
33
33
  property :name
34
- property :wide_app_image_media_id
34
+ property :media_key
35
35
 
36
36
  RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/" \
37
37
  'accounts/%{account_id}/cards/image_app_download' # @api private
@@ -19,13 +19,14 @@ module TwitterAds
19
19
  property :id, read_only: true
20
20
  property :image, read_only: true
21
21
  property :updated_at, type: :time, read_only: true
22
+ property :media_url, read_only: true
22
23
 
23
- property :cover_image_id
24
+ property :unlocked_image_media_key
24
25
  property :first_cta
25
26
  property :first_cta_tweet
26
27
  property :fourth_cta
27
28
  property :fourth_cta_tweet
28
- property :image_media_id
29
+ property :media_key
29
30
  property :name
30
31
  property :second_cta
31
32
  property :second_cta_tweet
@@ -4,12 +4,11 @@
4
4
  module TwitterAds
5
5
  module Creative
6
6
 
7
- class MediaCreative
7
+ class MediaCreative < Analytics
8
8
 
9
9
  include TwitterAds::DSL
10
10
  include TwitterAds::Resource
11
11
  include TwitterAds::Persistence
12
- include TwitterAds::Analytics
13
12
 
14
13
  attr_reader :account
15
14
 
@@ -22,17 +22,15 @@ module TwitterAds
22
22
  property :media_url, read_only: true
23
23
  property :tweeted, type: :bool, read_only: true
24
24
  property :updated_at, type: :time, read_only: true
25
- property :poster_image_url, read_only: true
25
+ property :poster_media_url, read_only: true
26
26
 
27
27
  # writable
28
- property :media_category
29
- property :media_id
30
28
  property :media_key
31
29
  property :description
32
30
  property :file_name
33
31
  property :name
34
32
  property :poster_image_media_id
35
- property :poster_image_media_key
33
+ property :poster_media_key
36
34
  property :title
37
35
 
38
36
  RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/" \
@@ -4,12 +4,11 @@
4
4
  module TwitterAds
5
5
  module Creative
6
6
 
7
- class PromotedAccount
7
+ class PromotedAccount < Analytics
8
8
 
9
9
  include TwitterAds::DSL
10
10
  include TwitterAds::Resource
11
11
  include TwitterAds::Persistence
12
- include TwitterAds::Analytics
13
12
 
14
13
  attr_reader :account
15
14
 
@@ -4,12 +4,11 @@
4
4
  module TwitterAds
5
5
  module Creative
6
6
 
7
- class PromotedTweet
7
+ class PromotedTweet < Analytics
8
8
 
9
9
  include TwitterAds::DSL
10
10
  include TwitterAds::Resource
11
11
  include TwitterAds::Persistence
12
- include TwitterAds::Analytics
13
12
 
14
13
  attr_reader :account
15
14
 
@@ -17,7 +17,6 @@ module TwitterAds
17
17
  property :created_at, type: :time, read_only: true
18
18
  property :id, read_only: true
19
19
  property :id_str, read_only: true
20
- property :media_keys, read_only: true
21
20
  property :scheduled_status, read_only: true
22
21
  property :tweet_id, read_only: true
23
22
  property :updated_at, type: :time, read_only: true
@@ -26,7 +25,7 @@ module TwitterAds
26
25
  # writable
27
26
  property :as_user_id
28
27
  property :card_uri
29
- property :media_ids
28
+ property :media_keys
30
29
  property :nullcast, type: :bool
31
30
  property :scheduled_at, type: :time
32
31
  property :text
@@ -35,16 +34,6 @@ module TwitterAds
35
34
  'accounts/%{account_id}/scheduled_tweets' # @api private
36
35
  RESOURCE = "/#{TwitterAds::API_VERSION}/" \
37
36
  'accounts/%{account_id}/scheduled_tweets/%{id}' # @api private
38
- PREVIEW = "/#{TwitterAds::API_VERSION}/" \
39
- 'accounts/%{account_id}/scheduled_tweets/preview/%{id}' # @api private
40
-
41
- def preview(account, opts = {})
42
- if @id
43
- resource = self.class::PREVIEW % { account_id: account.id, id: id }
44
- response = TwitterAds::Request.new(account.client, :get, resource, params: opts).perform
45
- response.body[:data]
46
- end
47
- end
48
37
 
49
38
  def initialize(account)
50
39
  @account = account
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+ # Copyright (C) 2019 Twitter, Inc.
3
+
4
+ module TwitterAds
5
+ module Creative
6
+
7
+ class Tweets
8
+
9
+ include TwitterAds::DSL
10
+ include TwitterAds::Resource
11
+
12
+ attr_reader :account
13
+
14
+ RESOURCE_COLLECTION = "/#{TwitterAds::API_VERSION}/" +
15
+ 'accounts/%{account_id}/tweets' # @api private
16
+
17
+ # Retrieve Tweet details for the account's full promotable user (default)
18
+ # or the user specified in the user_id parameter.
19
+ #
20
+ # @example
21
+ # tweets = TwitterAds::Creative::Tweets.all(
22
+ # account,
23
+ # tweet_type: 'PUBLISHED',
24
+ # tweet_ids: %w(1122911801354510336 1102836745790316550),
25
+ # timeline_type: 'ORGANIC'
26
+ # )
27
+ #
28
+ # @param account [Account] The Account object instance.
29
+ # @param tweet_type [String] The Tweet type for the specified tweet_ids.
30
+ # @option opts [Int] :count The number of records to try and retrieve per distinct request.
31
+ # @option opts [String] :cursor A cursor to get the next page of results.
32
+ # @option opts [String] :timeline_type The granularity to use (default: NULLCAST).
33
+ # @option opts [Boolean] :trim_user Whether to exclude the user object
34
+ # in the Tweet response (default: false).
35
+ # @option opts [Array] :tweet_ids A collection of tweet IDs to be fetched.
36
+ # @option opts [Long] :user_id The user ID to scope Tweets to.
37
+ #
38
+ # @return A list of tweets details.
39
+ #
40
+ # @see https://developer.twitter.com/en/docs/ads/creatives/api-reference/tweets#get-accounts-account-id-tweets
41
+ # @since 6.0.0
42
+
43
+ def self.all(account, opts = {})
44
+ params = TwitterAds::Utils.flatten_params(opts)
45
+ resource = self::RESOURCE_COLLECTION % { account_id: account.id }
46
+ request = Request.new(account.client, :get, resource, params: params)
47
+ Cursor.new(nil, request, init_with: [account])
48
+ end
49
+
50
+ end
51
+ end
52
+ end