yt 0.11.1 → 0.11.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +2 -0
  4. data/CHANGELOG.md +31 -33
  5. data/README.md +94 -3
  6. data/lib/yt.rb +1 -0
  7. data/lib/yt/actions/base.rb +19 -0
  8. data/lib/yt/actions/insert.rb +2 -0
  9. data/lib/yt/actions/list.rb +0 -7
  10. data/lib/yt/actions/modify.rb +2 -0
  11. data/lib/yt/collections/assets.rb +32 -0
  12. data/lib/yt/collections/authentications.rb +1 -0
  13. data/lib/yt/collections/claims.rb +16 -1
  14. data/lib/yt/collections/ownerships.rb +34 -0
  15. data/lib/yt/collections/references.rb +2 -12
  16. data/lib/yt/collections/resources.rb +0 -10
  17. data/lib/yt/models/account.rb +1 -1
  18. data/lib/yt/models/advertising_options_set.rb +33 -0
  19. data/lib/yt/models/asset.rb +100 -0
  20. data/lib/yt/models/channel.rb +1 -1
  21. data/lib/yt/models/claim.rb +22 -0
  22. data/lib/yt/models/content_owner.rb +16 -4
  23. data/lib/yt/models/match_policy.rb +2 -12
  24. data/lib/yt/models/ownership.rb +70 -0
  25. data/lib/yt/models/reference.rb +1 -1
  26. data/lib/yt/models/request.rb +13 -2
  27. data/lib/yt/models/resource.rb +0 -10
  28. data/lib/yt/models/resumable_session.rb +1 -0
  29. data/lib/yt/models/right_owner.rb +69 -0
  30. data/lib/yt/version.rb +1 -1
  31. data/spec/models/asset_spec.rb +20 -0
  32. data/spec/models/ownership_spec.rb +59 -0
  33. data/spec/models/right_owner_spec.rb +71 -0
  34. data/spec/requests/as_content_owner/advertising_options_set_spec.rb +15 -0
  35. data/spec/requests/as_content_owner/asset_spec.rb +12 -0
  36. data/spec/requests/as_content_owner/content_owner_spec.rb +37 -2
  37. data/spec/requests/as_content_owner/ownership_spec.rb +19 -0
  38. metadata +21 -3
  39. data/Gemfile.lock +0 -69
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1bca9a6106823c8817aef8eb024c9b54ae1a684d
4
- data.tar.gz: a4dd91d6a9be61e077ab502b4268cf7362383142
3
+ metadata.gz: 623d648b88a71c977785d91777067b7fe749b9ec
4
+ data.tar.gz: 41516787a905b8c36b1ce390c6850bffefed8a53
5
5
  SHA512:
6
- metadata.gz: 5bcd46f496c2a4cd43a280da1bcea6b54d5527152ed2cf73cae7797ba4eb7033a20f998caf9208d19bc665f9ac9e6ebd2421df48e6f07d4c4171d37414c156f7
7
- data.tar.gz: 5da86f76c045a7760ab56ed9022029332c6f2bc75ad2fe10d9750545a0900388f52db27be88e88907e9d893798bd3927de587ce9e5376dbd52eb192104a59ff2
6
+ metadata.gz: c75aa4a2de0bbfae680c25edaff8ec2be11aa5e946577a1a55d94dce55a0690f67fb1ad57f794e979a22cf8170dcb664375a8fcd6890b223fe7ad70bb4f8413f
7
+ data.tar.gz: eb62845c855fae0565a52755b53cbebbae108c7c952d7162943de3901fbe84195756076d4b7c9de1f5be5befdb75e65ac8d2409ac537f5fba7954b8cc6ffa7c3
data/.gitignore CHANGED
@@ -12,6 +12,7 @@
12
12
  /db/*.sqlite3-journal
13
13
 
14
14
  coverage/
15
+ Gemfile.lock
15
16
 
16
17
  # Ignore all logfiles and tempfiles.
17
18
  /log/*.log
@@ -32,3 +32,5 @@ env:
32
32
  - secure: CFkNT5WI2ATF3TKehTSuCwzG4EENnoVXaddL0PqpuH4Ss82k0k0xcJBhKbmD3Qkf7nw8y0g4s3jCepHssB2ZwzqQinKcYvamzIbsNPuhsuvlc9rMvT9ZosT5CHsiRJANl+OeZ8l2SqGu6kCMDx45h+fL7YZEtn3jjVZYEAXQSig=
33
33
  - secure: WWuYLNKcTM+fjgFrRT4qa3y4IlwO6xeSkM16jbDG05FUIThMfWRVQHhs5JThw/M3SByWGWySmz74sNpGV6V/yt9jw8o1u6F81j0ec2oeHDCwkZ8xK8ubPv3Pmg14PGr1Awu04zfhTEY9KzJt6HrFSYzek/MpV5Prg4J1l6SgqyU=
34
34
  - secure: YuWrOwaqBT0tLVe90OkfCLX/7tzrLhsOBn7LnqH0Ifw6T+EddNDmQLriWLRny8uNQSg7j/AhPOuEvR/ImOibK3a003LyxQZUx9KrEOkgIa5c82OlOLdcvmXw/8wnQ/SEdTDs8r2l1aZ2NxiieCA3fl7oxR1Lt/O+lS/vgqQY+uM=
35
+ - secure: VlE28fpY6cy6a9HYq+cdGmSXM54bZkbGzqSAqvgxTIJubMzSPSvQ7p5zdLtWPG9yQqYUOXyhKItZE/Eno0VemHDyV9qj0mo0JKb2c4OmX3aupIYTh38LZodkGmW+NGxa8GaebqYeDJeH33ZLtl9aumahzgUtGykKOkNIPH6Igy4=
36
+ - secure: YcjKPgsmOFbAeJrxl/d7idji/TX9/EZLXuO3ZYy3NLljy0GXdXtFBiAaE7DDTEG4PNLp+EJTpc/XbEu8yL1ozeH3lpGPeRU+Mk2LTFI2GAjpz6DeOucEx+sFEJJHr+eqsavQrNMzgOBii3TTmMP66Dp/T1L0HlcWT3v680jfS6A=
@@ -6,16 +6,22 @@ For more information about changelogs, check
6
6
  [Keep a Changelog](http://keepachangelog.com) and
7
7
  [Vandamme](http://tech-angels.github.io/vandamme).
8
8
 
9
+ ## 0.11.2 - 2014-08-20
10
+
11
+ * [FEATURE] Add AdvertisingOptionsSet with `update` to change the advertising settings of a video
12
+ * [FEATURE] Add `content_owner.create_claim` and `claim.delete`
13
+ * [FEATURE] Add `update` method to Ownership to change owners of an asset
14
+ * [FEATURE] Add `asset.ownership` to list the owners of an asset
15
+ * [FEATURE] Add `content_owner.create_asset` and Asset model
16
+
9
17
  ## 0.11.1 - 2014-08-17
10
18
 
11
19
  * [ENHANCEMENT] Add Video search even without a parent account or channel
12
20
 
13
21
  For instance, to search for the most viewed video on the whole YouTube, run:
14
22
 
15
- ```ruby
16
- videos = Yt::Collections::Videos.new
17
- videos.where(order: 'viewCount').first.title #=> "PSY - GANGNAM STYLE"
18
- ```
23
+ videos = Yt::Collections::Videos.new
24
+ videos.where(order: 'viewCount').first.title #=> "PSY - GANGNAM STYLE"
19
25
 
20
26
  ## 0.11.0 - 2014-08-17
21
27
 
@@ -29,11 +35,9 @@ token). For security reasons, Yt will not print it out anymore by default.
29
35
  If this is acceptable, then you are good to go.
30
36
  If you want the old behavior, set the `log_level` of Yt to `:debug`:
31
37
 
32
- ```ruby
33
- Yt.configure do |config|
34
- config.log_level = :debug
35
- end
36
- ```
38
+ Yt.configure do |config|
39
+ config.log_level = :debug
40
+ end
37
41
 
38
42
  * [ENHANCEMENT] Add `log_level` to Yt.configuration
39
43
 
@@ -73,14 +77,12 @@ exactly how many items are returned.
73
77
  If this is acceptable, then you are good to go.
74
78
  If you want the old behavior, replace `size` with `count`:
75
79
 
76
- ```ruby
77
- account = Yt::Account.new access_token: 'ya29...'
78
- # old behavior
79
- account.videos.size # => retrieved *all* the pages of the account’s videos
80
- # new behavior
81
- account.videos.size # => retrieves only the first page, returning the totalResults counter
82
- account.videos.count # => retrieves *all* the pages of the account’s videos
83
- ```
80
+ account = Yt::Account.new access_token: 'ya29...'
81
+ # old behavior
82
+ account.videos.size # => retrieved *all* the pages of the account’s videos
83
+ # new behavior
84
+ account.videos.size # => retrieves only the first page, returning the totalResults counter
85
+ account.videos.count # => retrieves *all* the pages of the account’s videos
84
86
 
85
87
  * [ENHANCEMENT] Calling `size` on a collection does not load all the pages of the collection
86
88
  * [ENHANCEMENT] Alias `policy.time_updated` to more coherent `policy.updated_at`
@@ -148,13 +150,11 @@ If your code never declares instances of `Yt::Rating`, or never calls the
148
150
 
149
151
  If it does, then *simply replace `update` with `set`*:
150
152
 
151
- ```ruby
152
- rating = Yt::Rating.new
153
- # old syntax
154
- rating.update :like
155
- # new syntax
156
- rating.set :like
157
- ```
153
+ rating = Yt::Rating.new
154
+ # old syntax
155
+ rating.update :like
156
+ # new syntax
157
+ rating.set :like
158
158
 
159
159
  * [ENHANCEMENT] `rating.set` replaces `rating.update` to rate a video
160
160
 
@@ -201,15 +201,13 @@ a YouTube user tries to subscribe to her/his own YouTube channel. Instead,
201
201
  If this is acceptable, then you are good to go.
202
202
  If you want the old behavior, replace `subscribe` with `subscribe!`:
203
203
 
204
- ```ruby
205
- account = Yt::Account.new access_token: 'ya29...'
206
- channel = account.channel
207
- # old behavior
208
- channel.subscribe # => raised an error
209
- # new behavior
210
- channel.subscribe # => nil
211
- channel.subscribe! # => raises an error
212
- ```
204
+ account = Yt::Account.new access_token: 'ya29...'
205
+ channel = account.channel
206
+ # old behavior
207
+ channel.subscribe # => raised an error
208
+ # new behavior
209
+ channel.subscribe # => nil
210
+ channel.subscribe! # => raises an error
213
211
 
214
212
  * [ENHANCEMENT] `channel.subscribe` does not raise error when trying to subscribe to one’s own channel
215
213
 
data/README.md CHANGED
@@ -41,7 +41,7 @@ To install on your system, run
41
41
 
42
42
  To use inside a bundled Ruby project, add this line to the Gemfile:
43
43
 
44
- gem 'yt', '~> 0.11.1'
44
+ gem 'yt', '~> 0.11.2'
45
45
 
46
46
  Since the gem follows [Semantic Versioning](http://semver.org),
47
47
  indicating the full version in your Gemfile (~> *major*.*minor*.*patch*)
@@ -95,6 +95,9 @@ Use [Yt::ContentOwner](http://rubydoc.info/github/Fullscreen/yt/master/Yt/Models
95
95
  * authenticate as a YouTube content owner
96
96
  * list the channels partnered with a YouTube content owner
97
97
  * list the claims administered by the content owner
98
+ * list and delete the references administered by the content owner
99
+ * list the policies and policy rules administered by the content owner
100
+ * create assets
98
101
 
99
102
  ```ruby
100
103
  # Content owners can be initialized with access token, refresh token or an authorization code
@@ -105,9 +108,19 @@ content_owner.partnered_channels.first #=> #<Yt::Models::Channel @id=...>
105
108
 
106
109
  content_owner.claims.where(q: 'Fullscreen').count #=> 24
107
110
  content_owner.claims.first #=> #<Yt::Models::Claim @id=...>
111
+ content_owner.claims.first.video_id #=> 'MESycYJytkU'
112
+ content_owner.claims.first.status #=> "active"
108
113
 
109
- content_owner.references.where(asset_id: "ABCDEFG").first => #<Yt::Models::Reference @id=...>
110
- content_owner.policies.first => #<Yt::Models::Policy @id=...>
114
+ reference = content_owner.references.where(asset_id: "ABCDEFG").first #=> #<Yt::Models::Reference @id=...>
115
+ reference.delete #=> true
116
+
117
+ content_owner.policies.first #=> #<Yt::Models::Policy @id=...>
118
+ content_owner.policies.first.name #=> "Track in all countries"
119
+ content_owner.policies.first.rules.first #=> #<Yt::Models::PolicyRule @id=...>
120
+ content_owner.policies.first.rules.first.action #=> "monetize"
121
+ content_owner.policies.first.rules.first.included_territories #=> ["US", "CA"]
122
+
123
+ content_owner.create_asset type: 'web' #=> #<Yt::Models::Asset @id=...>
111
124
  ```
112
125
 
113
126
  *All the above methods require authentication (see below).*
@@ -398,6 +411,22 @@ item.delete #=> true
398
411
  *The methods above require to be authenticated as the playlist’s owner (see below).*
399
412
 
400
413
 
414
+ Yt::Collections::Videos
415
+ -----------------------
416
+
417
+ Use [Yt::Collections::Videos](http://rubydoc.info/github/Fullscreen/yt/master/Yt/Collections/Videos) to:
418
+
419
+ * search for videos
420
+
421
+ ```ruby
422
+ videos = Yt::Collections::Videos.new
423
+ videos.where(order: 'viewCount').first.title #=> "PSY - GANGNAM STYLE"
424
+ videos.where(q: 'Fullscreen CreatorPlatform', safe_search: 'none').size #=> 324
425
+ ```
426
+
427
+ *The methods above do not require authentication.*
428
+
429
+
401
430
  Yt::Annotation
402
431
  --------------
403
432
 
@@ -416,6 +445,68 @@ annotation.has_link_to_playlist? #=> true
416
445
 
417
446
  *Annotations do not require authentication.*
418
447
 
448
+ Yt::MatchPolicy
449
+ ---------------
450
+
451
+ Use [Yt::MatchPolicy](http://rubydoc.info/github/Fullscreen/yt/master/Yt/Models/MatchPolicy) to:
452
+
453
+ * update the policy used by an asset
454
+
455
+ ```ruby
456
+ content_owner = Yt::ContentOwner.new owner_name: 'CMSname', access_token: 'ya29.1.ABCDEFGHIJ'
457
+ match_policy = Yt::MatchPolicy.new asset_id: 'ABCD12345678', auth: content_owner
458
+ match_policy.update policy_id: 'aBcdEF6g-HJ' #=> true
459
+
460
+ Yt::Asset
461
+ ---------
462
+
463
+ Use [Yt::Asset](http://rubydoc.info/github/Fullscreen/yt/master/Yt/Models/Asset) to:
464
+
465
+ * read the ownership of an asset
466
+
467
+ ```ruby
468
+
469
+ content_owner = Yt::ContentOwner.new owner_name: 'CMSname', access_token: 'ya29.1.ABCDEFGHIJ'
470
+ asset = Yt::Asset.new id: 'ABCD12345678', auth: content_owner
471
+ asset.ownership #=> #<Yt::Models::Ownership @general=...>
472
+ asset.general_owners.first.owner #=> 'FullScreen'
473
+ asset.general_owners.first.everywhere? #=> true
474
+ ```
475
+
476
+ *The methods above require to be authenticated as the video’s content owner (see below).*
477
+
478
+ Yt::Ownership
479
+ -------------
480
+
481
+ Use [Yt::Ownership](http://rubydoc.info/github/Fullscreen/yt/master/Yt/Models/Ownership) to:
482
+
483
+ * update the ownership of an asset
484
+
485
+ ```ruby
486
+ content_owner = Yt::ContentOwner.new owner_name: 'CMSname', access_token: 'ya29.1.ABCDEFGHIJ'
487
+ ownership = Yt::Ownership.new asset_id: 'ABCD12345678', auth: $content_owner
488
+ new_general_owner_attrs = {ratio: 100, owner: 'FullScreen', type: 'include', territories: ['US', 'CA']}
489
+ ownership.update general: [new_general_owner_attrs]
490
+ ```
491
+
492
+ *The methods above require to be authenticated as the video’s content owner (see below).*
493
+
494
+ Yt::AdvertisingOptionsSet
495
+ -------------------------
496
+
497
+ Use [Yt::AdvertisingOptionsSet](http://rubydoc.info/github/Fullscreen/yt/master/Yt/Models/AdvertisingOptionsSet) to:
498
+
499
+ * update the advertising settings of a video
500
+
501
+ ```ruby
502
+ content_owner = Yt::ContentOwner.new owner_name: 'CMSname', access_token: 'ya29.1.ABCDEFGHIJ'
503
+ ad_options = Yt::AdvertisingOptionsSet.new video_id: 'MESycYJytkU', auth: $content_owner
504
+ ad_options.update ad_formats: %w(standard_instream long) #=> true
505
+ ```
506
+
507
+ *The methods above require to be authenticated as the video’s content owner (see below).*
508
+
509
+
419
510
  Configuring your app
420
511
  ====================
421
512
 
data/lib/yt.rb CHANGED
@@ -7,6 +7,7 @@ require 'yt/models/match_policy'
7
7
  require 'yt/models/playlist'
8
8
  require 'yt/models/playlist_item'
9
9
  require 'yt/models/video'
10
+ require 'yt/models/ownership'
10
11
 
11
12
  # An object-oriented Ruby client for YouTube.
12
13
  # Helps creating applications that need to interact with YouTube objects.
@@ -0,0 +1,19 @@
1
+ module Yt
2
+ module Actions
3
+ # Abstract module that contains methods common to every action
4
+ module Base
5
+
6
+ private
7
+
8
+ # If we dropped support for ActiveSupport 3, then we could simply
9
+ # invoke transform_keys!{|key| key.to_s.underscore.to_sym}
10
+ def underscore_keys!(hash)
11
+ hash.dup.each_key{|key| hash[underscore key] = hash.delete key}
12
+ end
13
+
14
+ def underscore(value)
15
+ value.to_s.underscore.to_sym
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,8 +1,10 @@
1
1
  require 'yt/models/request'
2
+ require 'yt/actions/base'
2
3
 
3
4
  module Yt
4
5
  module Actions
5
6
  module Insert
7
+ include Base
6
8
 
7
9
  private
8
10
 
@@ -66,7 +66,6 @@ module Yt
66
66
  end
67
67
 
68
68
  def request(params = {})
69
- camelize_keys! params[:params] if params.fetch(:camelize_params, true)
70
69
  @last_request = Yt::Request.new params
71
70
  end
72
71
 
@@ -92,12 +91,6 @@ module Yt
92
91
  def list_resources
93
92
  self.class
94
93
  end
95
-
96
- def camelize_keys!(hash = {})
97
- hash.dup.each_key do |key|
98
- hash[key.to_s.camelize(:lower).to_sym] = hash.delete key
99
- end
100
- end
101
94
  end
102
95
  end
103
96
  end
@@ -1,9 +1,11 @@
1
1
  require 'yt/models/request'
2
+ require 'yt/actions/base'
2
3
 
3
4
  module Yt
4
5
  module Actions
5
6
  # Abstract module that contains methods common to Delete and Update
6
7
  module Modify
8
+ include Base
7
9
 
8
10
  private
9
11
 
@@ -0,0 +1,32 @@
1
+ require 'yt/collections/base'
2
+ require 'yt/models/asset'
3
+
4
+ module Yt
5
+ module Collections
6
+ # Provides methods to interact with a collection of Content ID assets.
7
+ #
8
+ # Resources with assets are: {Yt::Models::ContentOwner content owners}.
9
+ class Assets < Base
10
+ def insert(attributes = {})
11
+ underscore_keys! attributes
12
+ body = {type: attributes[:type]}
13
+ params = {on_behalf_of_content_owner: @auth.owner_name}
14
+ do_insert(params: params, body: body)
15
+ end
16
+
17
+ private
18
+
19
+ def new_item(data)
20
+ Yt::Asset.new data: data, auth: @auth
21
+ end
22
+
23
+ # @return [Hash] the parameters to submit to YouTube to add a asset.
24
+ # @see https://developers.google.com/youtube/partner/docs/v1/assets/insert
25
+ def insert_params
26
+ super.tap do |params|
27
+ params[:path] = '/youtube/partner/v1/assets'
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -21,6 +21,7 @@ module Yt
21
21
  params[:method] = :post
22
22
  params[:auth] = nil
23
23
  params[:body] = auth_params
24
+ params[:camelize_body] = false
24
25
  end
25
26
  end
26
27
 
@@ -7,11 +7,18 @@ module Yt
7
7
  #
8
8
  # Resources with claims are: {Yt::Models::ContentOwner content owners}.
9
9
  class Claims < Base
10
+ def insert(attributes = {})
11
+ underscore_keys! attributes
12
+ body = attributes.slice :asset_id, :video_id, :content_type
13
+ body[:policy] = {id: attributes[:policy_id]} if attributes[:policy_id]
14
+ params = {on_behalf_of_content_owner: @auth.owner_name}
15
+ do_insert(params: params, body: body)
16
+ end
10
17
 
11
18
  private
12
19
 
13
20
  def new_item(data)
14
- Yt::Claim.new data: data
21
+ Yt::Claim.new data: data, auth: @auth
15
22
  end
16
23
 
17
24
  # @return [Hash] the parameters to submit to YouTube to list claims
@@ -25,6 +32,14 @@ module Yt
25
32
  end
26
33
  end
27
34
 
35
+ # @return [Hash] the parameters to submit to YouTube to add a claim.
36
+ # @see https://developers.google.com/youtube/partner/docs/v1/claims/insert
37
+ def insert_params
38
+ super.tap do |params|
39
+ params[:path] = '/youtube/partner/v1/claims'
40
+ end
41
+ end
42
+
28
43
  def claims_params
29
44
  apply_where_params! on_behalf_of_content_owner: @parent.owner_name
30
45
  end
@@ -0,0 +1,34 @@
1
+ require 'yt/collections/resources'
2
+ require 'yt/models/ownership'
3
+
4
+ module Yt
5
+ module Collections
6
+ # Provides methods to interact with a the ownership of a YouTube resource.
7
+ #
8
+ # Resources with ownerships are: {Yt::Models::Asset assets}.
9
+ class Ownerships < Resources
10
+
11
+ private
12
+
13
+ def new_item(data)
14
+ Yt::Ownership.new data: data, asset_id: @parent.id, auth: @auth
15
+ end
16
+
17
+ # @return [Hash] the parameters to submit to YouTube to get ownerships.
18
+ # @see https://developers.google.com/youtube/partner/docs/v1/ownership/get
19
+ def list_params
20
+ super.tap do |params|
21
+ params[:path] = "/youtube/partner/v1/assets/#{@parent.id}/ownership"
22
+ params[:params] = {on_behalf_of_content_owner: @auth.owner_name}
23
+ end
24
+ end
25
+
26
+ # @private
27
+ # @note Ownerships overwrites +fetch_page+ since it’s a get.
28
+ def fetch_page(params = {})
29
+ response = request(params).run
30
+ {items: [response.body], token: nil}
31
+ end
32
+ end
33
+ end
34
+ end