juce 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/Gemfile +7 -0
- data/README.md +537 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/juce.gemspec +27 -0
- data/lib/juce.rb +6 -0
- data/lib/juce/version.rb +3 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c24d3f7e05fbdca36dea857420f8e76c18514a44e8bd7bf62cdee8661b0292b8
|
4
|
+
data.tar.gz: d5ea43f555edf5e170151b22d4661fd7b3fed45d2aee58c681a3e40cfebd990d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8fee810d06734b3dbe8564436ec96d4290ab7142598939cfbbfab5489e6564209135370001555764819866ba3d20769badc580a8ccae82e19e1d531d133677d7
|
7
|
+
data.tar.gz: 8bd039ebf23b07917a153296c9a7752c8d804c959cf20df211d4804651aa4b6e43a135154c40c5943ed250dbec91df557457743e548fd0475a91946a3dff96d3
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,537 @@
|
|
1
|
+
Juce - a Ruby client to parse Juce content
|
2
|
+
==========================================
|
3
|
+
|
4
|
+
Juce helps you write apps that need to interact with [Juce XML format](https://docs.juce.com/master/classXmlDocument.html).
|
5
|
+
|
6
|
+
The **source code** is available on [GitHub](https://github.com/outputinc/juce) and the **documentation** on [RubyDoc](http://www.rubydoc.info/gems/outputinc/juce).
|
7
|
+
|
8
|
+
How to install
|
9
|
+
==============
|
10
|
+
|
11
|
+
To install on your system, run
|
12
|
+
|
13
|
+
gem install juce
|
14
|
+
|
15
|
+
To use inside a bundled Ruby project, add this line to the Gemfile:
|
16
|
+
|
17
|
+
gem 'juce', '~> 0.1.0'
|
18
|
+
|
19
|
+
Since the gem follows [Semantic Versioning](http://semver.org),
|
20
|
+
indicating the full version in your Gemfile (~> *major*.*minor*.*patch*)
|
21
|
+
guarantees that your project won’t occur in any error when you `bundle update`
|
22
|
+
and a new version of Juce is released.
|
23
|
+
|
24
|
+
How to use
|
25
|
+
==========
|
26
|
+
|
27
|
+
Parsing a .pfl file
|
28
|
+
-------------------
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
# Content owners can be initialized with access token, refresh token or an authorization code
|
32
|
+
content_owner = Yt::ContentOwner.new owner_name: 'CMSname', access_token: 'ya29.1.ABCDEFGHIJ'
|
33
|
+
|
34
|
+
content_owner.partnered_channels.count #=> 12
|
35
|
+
content_owner.partnered_channels.map &:title #=> ["Fullscreen", "Best of Fullscreen", ...]
|
36
|
+
content_owner.partnered_channels.where(part: 'statistics').map &:subscriber_count #=> [136925, 56945, ...]
|
37
|
+
|
38
|
+
content_owner.claims.where(q: 'Fullscreen').count #=> 24
|
39
|
+
content_owner.claims.first #=> #<Yt::Models::Claim @id=...>
|
40
|
+
content_owner.claims.first.video_id #=> 'jNQXAC9IVRw'
|
41
|
+
content_owner.claims.first.status #=> "active"
|
42
|
+
|
43
|
+
reference = content_owner.references.where(asset_id: "ABCDEFG").first #=> #<Yt::Models::Reference @id=...>
|
44
|
+
reference.delete #=> true
|
45
|
+
|
46
|
+
content_owner.policies.first #=> #<Yt::Models::Policy @id=...>
|
47
|
+
content_owner.policies.first.name #=> "Track in all countries"
|
48
|
+
content_owner.policies.first.rules.first #=> #<Yt::Models::PolicyRule @id=...>
|
49
|
+
content_owner.policies.first.rules.first.action #=> "monetize"
|
50
|
+
content_owner.policies.first.rules.first.included_territories #=> ["US", "CA"]
|
51
|
+
|
52
|
+
content_owner.create_asset type: 'web' #=> #<Yt::Models::Asset @id=...>
|
53
|
+
|
54
|
+
content_owner.assets.first #=> #<Yt::Models::AssetSnippet:0x007ff2bc543b00 @id=...>
|
55
|
+
content_owner.assets.first.id #=> "A4532885163805730"
|
56
|
+
content_owner.assets.first.title #=> "Money Train"
|
57
|
+
content_owner.assets.first.type #=> "web"
|
58
|
+
content_owner.assets.first.custom_id #=> "MoKNJFOIRroc"
|
59
|
+
|
60
|
+
```
|
61
|
+
|
62
|
+
*All the above methods require authentication (see below).*
|
63
|
+
|
64
|
+
Yt::Channel
|
65
|
+
-----------
|
66
|
+
|
67
|
+
Check [fullscreen.github.io/yt](http://fullscreen.github.io/yt/channels.html) for the list of methods available for `Yt::Channel`.
|
68
|
+
|
69
|
+
Yt::Video
|
70
|
+
---------
|
71
|
+
|
72
|
+
Check [fullscreen.github.io/yt](http://fullscreen.github.io/yt/videos.html) for the list of methods available for `Yt::Video`.
|
73
|
+
|
74
|
+
Yt::Playlist
|
75
|
+
------------
|
76
|
+
|
77
|
+
Check [fullscreen.github.io/yt](http://fullscreen.github.io/yt/playlists.html) for the list of methods available for `Yt::Playlist`.
|
78
|
+
|
79
|
+
Yt::PlaylistItem
|
80
|
+
----------------
|
81
|
+
|
82
|
+
Check [fullscreen.github.io/yt](http://fullscreen.github.io/yt/playlist_items.html) for the list of methods available for `Yt::PlaylistItem`.
|
83
|
+
|
84
|
+
Yt::CommentThread
|
85
|
+
----------------
|
86
|
+
|
87
|
+
Use [Yt::CommentThread](http://www.rubydoc.info/gems/yt/Yt/Models/CommentThread) to:
|
88
|
+
|
89
|
+
* Show details of a comment_thread.
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
Yt::CommentThread.new id: 'z13vsnnbwtv4sbnug232erczcmi3wzaug'
|
93
|
+
|
94
|
+
comment_thread.video_id #=> "1234"
|
95
|
+
comment_thread.total_reply_count #=> 1
|
96
|
+
comment_thread.can_reply? #=> true
|
97
|
+
comment_thread.public? #=> true
|
98
|
+
|
99
|
+
comment_thread.top_level_comment #=> #<Yt::Models::Comment ...>
|
100
|
+
comment_thread.text_display #=> "funny video!"
|
101
|
+
comment_thread.like_count #=> 9
|
102
|
+
comment_thread.updated_at #=> 2016-03-22 12:56:56 UTC
|
103
|
+
comment_thread.author_display_name #=> "Joe"
|
104
|
+
```
|
105
|
+
|
106
|
+
Yt::Comment
|
107
|
+
----------------
|
108
|
+
|
109
|
+
Use [Yt::Comment](http://www.rubydoc.info/gems/yt/Yt/Models/Comment) to:
|
110
|
+
|
111
|
+
* Get details of a comment.
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
Yt::Comment.new id: 'z13vsnnbwtv4sbnug232erczcmi3wzaug'
|
115
|
+
|
116
|
+
comment.text_display #=> "awesome"
|
117
|
+
comment.author_display_name #=> "Jack"
|
118
|
+
comment.like_count #=> 1
|
119
|
+
comment.updated_at #=> 2016-03-22 12:56:56 UTC
|
120
|
+
comment.parent_id #=> "abc1234" (return nil if the comment is not a reply)
|
121
|
+
```
|
122
|
+
|
123
|
+
Yt::BulkReportJob
|
124
|
+
----------------
|
125
|
+
|
126
|
+
Use [Yt::BulkReportJob](http://www.rubydoc.info/gems/yt/Yt/Models/BulkReportJob) to:
|
127
|
+
|
128
|
+
* Get details of a bulk report job.
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
content_owner = Yt::ContentOwner.new owner_name: 'CMSname', access_token: 'ya29.1.ABCDEFGHIJ'
|
132
|
+
bulk_report_job = content_owner.bulk_report_jobs.first
|
133
|
+
|
134
|
+
bulk_report_job.report_type_id #=> "content_owner_demographics_a1"
|
135
|
+
```
|
136
|
+
|
137
|
+
Yt::BulkReport
|
138
|
+
----------------
|
139
|
+
|
140
|
+
Use [Yt::BulkReport](http://www.rubydoc.info/gems/yt/Yt/Models/BulkReport) to:
|
141
|
+
|
142
|
+
* Get details of a bulk report.
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
content_owner = Yt::ContentOwner.new owner_name: 'CMSname', access_token: 'ya29.1.ABCDEFGHIJ'
|
146
|
+
bulk_report_job = content_owner.bulk_report_jobs.first
|
147
|
+
bulk_report = bulk_report_job.bulk_reports.first
|
148
|
+
|
149
|
+
bulk_report.start_time #=> 2017-08-11 07:00:00 UTC
|
150
|
+
bulk_report.end_time #=> 2017-08-12 07:00:00 UTC
|
151
|
+
bulk_report.download_url #=> "https://youtubereporting.googleapis.com/v1/..."
|
152
|
+
```
|
153
|
+
|
154
|
+
Yt::Collections::Videos
|
155
|
+
-----------------------
|
156
|
+
|
157
|
+
Use [Yt::Collections::Videos](http://www.rubydoc.info/gems/yt/Yt/Collections/Videos) to:
|
158
|
+
|
159
|
+
* search for videos
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
videos = Yt::Collections::Videos.new
|
163
|
+
videos.where(order: 'viewCount').first.title #=> "PSY - GANGNAM STYLE"
|
164
|
+
videos.where(q: 'Fullscreen CreatorPlatform', safe_search: 'none').size #=> 324
|
165
|
+
videos.where(chart: 'mostPopular', video_category_id: 44).first.title #=> "SINISTER - Trailer"
|
166
|
+
videos.where(id: 'jNQXAC9IVRw,invalid').map(&:title) #=> ["Fullscreen Creator Platform"]
|
167
|
+
```
|
168
|
+
|
169
|
+
*The methods above do not require authentication.*
|
170
|
+
|
171
|
+
|
172
|
+
Yt::Annotation
|
173
|
+
--------------
|
174
|
+
|
175
|
+
Check [fullscreen.github.io/yt](http://fullscreen.github.io/yt/annotations.html) for the list of methods available for `Yt::Annotation`.
|
176
|
+
|
177
|
+
|
178
|
+
Yt::MatchPolicy
|
179
|
+
---------------
|
180
|
+
|
181
|
+
Use [Yt::MatchPolicy](http://www.rubydoc.info/gems/yt/Yt/Models/MatchPolicy) to:
|
182
|
+
|
183
|
+
* update the policy used by an asset
|
184
|
+
|
185
|
+
```ruby
|
186
|
+
content_owner = Yt::ContentOwner.new owner_name: 'CMSname', access_token: 'ya29.1.ABCDEFGHIJ'
|
187
|
+
match_policy = Yt::MatchPolicy.new asset_id: 'ABCD12345678', auth: content_owner
|
188
|
+
match_policy.update policy_id: 'aBcdEF6g-HJ' #=> true
|
189
|
+
```
|
190
|
+
|
191
|
+
Yt::Asset
|
192
|
+
---------
|
193
|
+
|
194
|
+
Use [Yt::Asset](http://www.rubydoc.info/gems/yt/Yt/Models/Asset) to:
|
195
|
+
|
196
|
+
* read the ownership of an asset
|
197
|
+
* update the attributes of an asset
|
198
|
+
|
199
|
+
```ruby
|
200
|
+
|
201
|
+
content_owner = Yt::ContentOwner.new owner_name: 'CMSname', access_token: 'ya29.1.ABCDEFGHIJ'
|
202
|
+
asset = Yt::Asset.new id: 'ABCD12345678', auth: content_owner
|
203
|
+
asset.ownership #=> #<Yt::Models::Ownership @general=...>
|
204
|
+
asset.ownership.obtain! #=> true
|
205
|
+
asset.general_owners.first.owner #=> 'CMSname'
|
206
|
+
asset.general_owners.first.everywhere? #=> true
|
207
|
+
asset.ownership.release! #=> true
|
208
|
+
|
209
|
+
asset.update metadata_mine: {notes: 'Some notes'} #=> true
|
210
|
+
```
|
211
|
+
|
212
|
+
* to retrieve metadata for an asset (e.g. title, notes, description, custom_id)
|
213
|
+
|
214
|
+
```ruby
|
215
|
+
content_owner = Yt::ContentOwner.new(...)
|
216
|
+
asset = content_owner.assets.where(id: 'A969176766549462', fetch_metadata: 'mine').first
|
217
|
+
asset.metadata_mine.title #=> "Master Final Neu La Anh Fix"
|
218
|
+
|
219
|
+
asset = content_owner.assets.where(id: 'A969176766549462', fetch_metadata: 'effective').first
|
220
|
+
asset.metadata_effective.title #=> "Neu la anh" (different due to ownership conflicts)
|
221
|
+
```
|
222
|
+
|
223
|
+
```ruby
|
224
|
+
asset = content_owner.assets.where(id: 'A125058570526569', fetch_ownership: 'effective').first
|
225
|
+
asset.ownership_effective.general_owners.first.owner # => "XOuN81q-MeEUVrsiZeK1lQ"
|
226
|
+
```
|
227
|
+
|
228
|
+
* to search for an asset
|
229
|
+
|
230
|
+
```ruby
|
231
|
+
content_owner.assets.where(labels: "campaign:cpiuwdz-8oc").size #=> 417
|
232
|
+
content_owner.assets.where(labels: "campaign:cpiuwdz-8oc").first.title #=> "Whoomp! (Supadupafly) (Xxl Hip House Mix)"
|
233
|
+
```
|
234
|
+
|
235
|
+
Yt::Claim
|
236
|
+
---------
|
237
|
+
|
238
|
+
Use [Yt::Claim](http://www.rubydoc.info/gems/yt/Yt/Models/Claim) to:
|
239
|
+
|
240
|
+
* read the attributes of a claim
|
241
|
+
* view the history of a claim
|
242
|
+
* update the attributes of an claim
|
243
|
+
|
244
|
+
```ruby
|
245
|
+
|
246
|
+
content_owner = Yt::ContentOwner.new owner_name: 'CMSname', access_token: 'ya29.1.ABCDEFGHIJ'
|
247
|
+
claim = Yt::Claim.new id: 'ABCD12345678', auth: content_owner
|
248
|
+
claim.video_id #=> 'va141cJga2'
|
249
|
+
claim.asset_id #=> 'A1234'
|
250
|
+
claim.content_type #=> 'audiovisual'
|
251
|
+
claim.active? #=> true
|
252
|
+
|
253
|
+
claim.claim_history #=> #<Yt::Models::ClaimHistory ...>
|
254
|
+
claim.claim_history.events[0].type #=> "claim_create"
|
255
|
+
|
256
|
+
claim.delete #=> true
|
257
|
+
|
258
|
+
data = {
|
259
|
+
is_manual_claim: true,
|
260
|
+
content_type: 'audiovisual',
|
261
|
+
asset_id: 'A123123123123123',
|
262
|
+
policy: { id: 'S123123123123123' },
|
263
|
+
video_id: 'myvIdeoIdYT',
|
264
|
+
match_info: {
|
265
|
+
match_segments: [
|
266
|
+
{
|
267
|
+
manual_segment: {
|
268
|
+
start: '00:00:20.000',
|
269
|
+
finish: '00:01:20.000'
|
270
|
+
}
|
271
|
+
},
|
272
|
+
{
|
273
|
+
manual_segment: {
|
274
|
+
start: '00:02:30.000',
|
275
|
+
finish: '00:03:50.000'
|
276
|
+
}
|
277
|
+
}
|
278
|
+
]
|
279
|
+
}
|
280
|
+
}
|
281
|
+
|
282
|
+
content_owner.claims.insert(data)
|
283
|
+
```
|
284
|
+
|
285
|
+
*The methods above require to be authenticated as the video’s content owner (see below).*
|
286
|
+
|
287
|
+
Yt::Ownership
|
288
|
+
-------------
|
289
|
+
|
290
|
+
Use [Yt::Ownership](http://www.rubydoc.info/gems/yt/Yt/Models/Ownership) to:
|
291
|
+
|
292
|
+
* update the ownership of an asset
|
293
|
+
|
294
|
+
```ruby
|
295
|
+
content_owner = Yt::ContentOwner.new owner_name: 'CMSname', access_token: 'ya29.1.ABCDEFGHIJ'
|
296
|
+
ownership = Yt::Ownership.new asset_id: 'ABCD12345678', auth: $content_owner
|
297
|
+
new_general_owner_attrs = {ratio: 100, owner: 'CMSname', type: 'include', territories: ['US', 'CA']}
|
298
|
+
ownership.update general: [new_general_owner_attrs]
|
299
|
+
```
|
300
|
+
|
301
|
+
*The methods above require to be authenticated as the video’s content owner (see below).*
|
302
|
+
|
303
|
+
Yt::AdvertisingOptionsSet
|
304
|
+
-------------------------
|
305
|
+
|
306
|
+
Use [Yt::AdvertisingOptionsSet](http://www.rubydoc.info/gems/yt/Yt/Models/AdvertisingOptionsSet) to:
|
307
|
+
|
308
|
+
* update the advertising settings of a video
|
309
|
+
|
310
|
+
```ruby
|
311
|
+
content_owner = Yt::ContentOwner.new owner_name: 'CMSname', access_token: 'ya29.1.ABCDEFGHIJ'
|
312
|
+
ad_options = Yt::AdvertisingOptionsSet.new video_id: 'jNQXAC9IVRw', auth: $content_owner
|
313
|
+
ad_options.update ad_formats: %w(standard_instream long) #=> true
|
314
|
+
```
|
315
|
+
|
316
|
+
*The methods above require to be authenticated as the video’s content owner (see below).*
|
317
|
+
|
318
|
+
Instrumentation
|
319
|
+
===============
|
320
|
+
|
321
|
+
Yt leverages [Active Support Instrumentation](http://edgeguides.rubyonrails.org/active_support_instrumentation.html) to provide a hook which developers can use to be notified when HTTP requests to YouTube are made. This hook may be used to track the number of requests over time, monitor quota usage, provide an audit trail, or track how long a specific request takes to complete.
|
322
|
+
|
323
|
+
Subscribe to the `request.yt` notification within your application:
|
324
|
+
|
325
|
+
```ruby
|
326
|
+
ActiveSupport::Notifications.subscribe 'request.yt' do |*args|
|
327
|
+
event = ActiveSupport::Notifications::Event.new(*args)
|
328
|
+
|
329
|
+
event.payload[:request_uri] #=> #<URI::HTTPS URL:https://www.googleapis.com/youtube/v3/channels?id=UCxO1tY8h1AhOz0T4ENwmpow&part=snippet>
|
330
|
+
event.payload[:method] #=> :get
|
331
|
+
event.payload[:response] #=> #<Net::HTTPOK 200 OK readbody=true>
|
332
|
+
|
333
|
+
event.end #=> 2014-08-22 16:57:17 -0700
|
334
|
+
event.duration #=> 141.867 (ms)
|
335
|
+
end
|
336
|
+
```
|
337
|
+
|
338
|
+
Configuring your app
|
339
|
+
====================
|
340
|
+
|
341
|
+
In order to use Yt you must register your app in the [Google Developers Console](https://console.developers.google.com).
|
342
|
+
|
343
|
+
If you don’t have a registered app, browse to the console and select "Create Project":
|
344
|
+
![01-create-project](https://cloud.githubusercontent.com/assets/7408595/3373043/4224c894-fbb0-11e3-9f8a-4d96bddce136.png)
|
345
|
+
|
346
|
+
When your project is ready, select APIs & Auth in the menu and individually enable Google+, YouTube Analytics and YouTube Data API:
|
347
|
+
![02-select-api](https://cloud.githubusercontent.com/assets/4453997/8442701/5d0f77f4-1f35-11e5-93d8-07d4459186b5.png)
|
348
|
+
![02a-enable google api](https://cloud.githubusercontent.com/assets/4453997/8442306/0f714cb8-1f33-11e5-99b3-f17a4b1230fe.png)
|
349
|
+
![02b-enable youtube api](https://cloud.githubusercontent.com/assets/4453997/8442304/0f6fd0e0-1f33-11e5-981a-acf90ccd7409.png)
|
350
|
+
![02c-enable youtube analytics api](https://cloud.githubusercontent.com/assets/4453997/8442305/0f71240e-1f33-11e5-9b60-4ecea02da9be.png)
|
351
|
+
|
352
|
+
The next step is to create an API key. Depending on the nature of your app, you should pick one of the following strategies.
|
353
|
+
|
354
|
+
Apps that do not require user interactions
|
355
|
+
------------------------------------------
|
356
|
+
|
357
|
+
If you are building a read-only app that fetches public data from YouTube, then
|
358
|
+
all you need is a **Public API access**.
|
359
|
+
|
360
|
+
Click on "Create new Key" in the Public API section and select "Server Key":
|
361
|
+
![03-create-key](https://cloud.githubusercontent.com/assets/7408595/3373045/42258fcc-fbb0-11e3-821c-699c8a3ce7bc.png)
|
362
|
+
![04-create-server-key](https://cloud.githubusercontent.com/assets/7408595/3373044/42251db2-fbb0-11e3-93f9-8f06f8390b4e.png)
|
363
|
+
|
364
|
+
Once the key for server application is created, copy the API key and add it
|
365
|
+
to your code with the following snippet of code (replacing with your own key):
|
366
|
+
|
367
|
+
```ruby
|
368
|
+
Yt.configure do |config|
|
369
|
+
config.api_key = 'AIzaSyAO8dXpvZcaP2XSDFBD91H8yQ'
|
370
|
+
end
|
371
|
+
```
|
372
|
+
|
373
|
+
Remember: this kind of app is not allowed to perform any destructive operation,
|
374
|
+
so you won’t be able to like a video, subscribe to a channel or delete a
|
375
|
+
playlist from a specific account. You will only be able to retrieve read-only
|
376
|
+
data.
|
377
|
+
|
378
|
+
Web apps that require user interactions
|
379
|
+
---------------------------------------
|
380
|
+
|
381
|
+
If you are building a web app that manages YouTube accounts, you need the
|
382
|
+
owner of each account to authorize your app. There are three scenarios:
|
383
|
+
|
384
|
+
Scenario 1. If you already have the account’s **access token**, then you are ready to go.
|
385
|
+
Just pass that access token to the account initializer, such as:
|
386
|
+
|
387
|
+
```ruby
|
388
|
+
account = Yt::Account.new access_token: 'ya29.1.ABCDEFGHIJ'
|
389
|
+
account.email #=> (retrieves the account’s e-mail address)
|
390
|
+
account.videos #=> (lists a video to an account’s playlist)
|
391
|
+
```
|
392
|
+
|
393
|
+
Scenario 2. If you don’t have the account’s access token, but you have the
|
394
|
+
**refresh token**, then it’s almost as easy.
|
395
|
+
In the [Google Developers Console](https://console.developers.google.com),
|
396
|
+
find the web application that was used to obtain the refresh token, copy the
|
397
|
+
Client ID and Client secret and add them to you code with the following snippet
|
398
|
+
of code (replacing with your own keys):
|
399
|
+
|
400
|
+
```ruby
|
401
|
+
Yt.configure do |config|
|
402
|
+
config.client_id = '1234567890.apps.googleusercontent.com'
|
403
|
+
config.client_secret = '1234567890'
|
404
|
+
end
|
405
|
+
```
|
406
|
+
Then you can manage a YouTube account by passing the refresh token to the
|
407
|
+
account initializer, such as:
|
408
|
+
|
409
|
+
```ruby
|
410
|
+
account = Yt::Account.new refresh_token: '1/1234567890'
|
411
|
+
account.email #=> (retrieves the account’s e-mail address)
|
412
|
+
account.videos #=> (lists a video to an account’s playlist)
|
413
|
+
```
|
414
|
+
|
415
|
+
Scenario 3. If you don’t have any account’s token, then you can get one by
|
416
|
+
having the user authorize your app through the Google OAuth page.
|
417
|
+
|
418
|
+
In the [Google Developers Console](https://console.developers.google.com),
|
419
|
+
click on "Create new Client ID" in the OAuth section and select "Web application":
|
420
|
+
![06-create-client-key](https://cloud.githubusercontent.com/assets/7408595/3373047/42379eba-fbb0-11e3-89c4-16b10e072de6.png)
|
421
|
+
|
422
|
+
Fill the "Authorized Redirect URI" textarea with the URL of your app where you
|
423
|
+
want to redirect users after they authorize their YouTube account.
|
424
|
+
|
425
|
+
Once the Client ID for web application is created, copy the Client ID and secret
|
426
|
+
and add them to your code with the following snippet of code (replacing with your own keys):
|
427
|
+
|
428
|
+
```ruby
|
429
|
+
Yt.configure do |config|
|
430
|
+
config.client_id = '49781862760-4t610gtk35462g.apps.googleusercontent.com'
|
431
|
+
config.client_secret = 'NtFHjZkJcwYZDfYVz9mp8skz9'
|
432
|
+
end
|
433
|
+
```
|
434
|
+
|
435
|
+
Finally, in your web app, add a link to the URL generated by running
|
436
|
+
|
437
|
+
```ruby
|
438
|
+
Yt::Account.new(scopes: scopes, redirect_uri: redirect_uri).authentication_url
|
439
|
+
```
|
440
|
+
|
441
|
+
where `redirect_uri` is the URL you entered in the form above, and `scopes` is
|
442
|
+
the list of YouTube scopes you want the user to authorize. Depending on the
|
443
|
+
nature of your app, you can pick one or more among `youtube`, `youtube.readonly` `userinfo.email`.
|
444
|
+
|
445
|
+
Every user who authorizes your app will be redirected to the `redirect_uri`
|
446
|
+
with an extra `code` parameter that looks something like `4/Ja60jJ7_Kw0`.
|
447
|
+
Just pass the code to the following method to authenticate and initialize the account:
|
448
|
+
|
449
|
+
```ruby
|
450
|
+
account = Yt::Account.new authorization_code: '4/Ja60jJ7_Kw0', redirect_uri: redirect_uri
|
451
|
+
account.email #=> (retrieves the account’s e-mail address)
|
452
|
+
account.videos #=> (lists a video to an account’s playlist)
|
453
|
+
```
|
454
|
+
|
455
|
+
Configuring with environment variables
|
456
|
+
--------------------------------------
|
457
|
+
|
458
|
+
As an alternative to the approach above, you can configure your app with
|
459
|
+
variables. Setting the following environment variables:
|
460
|
+
|
461
|
+
```bash
|
462
|
+
export YT_CLIENT_ID="1234567890.apps.googleusercontent.com"
|
463
|
+
export YT_CLIENT_SECRET="1234567890"
|
464
|
+
export YT_API_KEY="123456789012345678901234567890"
|
465
|
+
```
|
466
|
+
|
467
|
+
is equivalent to configuring your app with the initializer:
|
468
|
+
|
469
|
+
```ruby
|
470
|
+
Yt.configure do |config|
|
471
|
+
config.client_id = '1234567890.apps.googleusercontent.com'
|
472
|
+
config.client_secret = '1234567890'
|
473
|
+
config.api_key = '123456789012345678901234567890'
|
474
|
+
end
|
475
|
+
```
|
476
|
+
|
477
|
+
so use the approach that you prefer.
|
478
|
+
If a variable is set in both places, then `Yt.configure` takes precedence.
|
479
|
+
|
480
|
+
How to test
|
481
|
+
===========
|
482
|
+
|
483
|
+
To run tests:
|
484
|
+
|
485
|
+
```bash
|
486
|
+
rspec
|
487
|
+
```
|
488
|
+
|
489
|
+
We recommend RSpec >= 3.8.
|
490
|
+
|
491
|
+
Yt comes with two different sets of tests:
|
492
|
+
|
493
|
+
1. Unit tests in `spec/models`, `spec/collections` and `spec/errors`
|
494
|
+
2. Legacy integration tests in `spec/requests`
|
495
|
+
|
496
|
+
Coming soon will be a new set of high-level integration tests.
|
497
|
+
|
498
|
+
Integration tests are recorded with VCR. Some of the tests refer to
|
499
|
+
fixture data that an arbitrary account may not have access to. If you
|
500
|
+
need to modify one of these tests or re-record the cassette, we'd
|
501
|
+
suggest working against your own version of the testing setup. Then in
|
502
|
+
your pull request, we can help canonize your test/fixtures.
|
503
|
+
|
504
|
+
Some of the integration tests require authentication. These can be set
|
505
|
+
with the following environment variables:
|
506
|
+
|
507
|
+
* `YT_TEST_CLIENT_ID`
|
508
|
+
* `YT_TEST_CLIENT_SECRET`
|
509
|
+
* `YT_TEST_API_KEY`
|
510
|
+
* `YT_TEST_REFRESH_TOKEN`
|
511
|
+
|
512
|
+
How to release new versions
|
513
|
+
===========================
|
514
|
+
|
515
|
+
If you are a manager of this project, remember to upgrade the [Yt gem](http://rubygems.org/gems/yt)
|
516
|
+
whenever a new feature is added or a bug gets fixed.
|
517
|
+
|
518
|
+
Make sure all the tests are passing on [Travis CI](https://travis-ci.org/Fullscreen/yt),
|
519
|
+
document the changes in CHANGELOG.md and README.md, bump the version, then run
|
520
|
+
|
521
|
+
rake release
|
522
|
+
|
523
|
+
Remember that the yt gem follows [Semantic Versioning](http://semver.org).
|
524
|
+
Any new release that is fully backward-compatible should bump the *patch* version (0.0.x).
|
525
|
+
Any new version that breaks compatibility should bump the *minor* version (0.x.0)
|
526
|
+
|
527
|
+
How to contribute
|
528
|
+
=================
|
529
|
+
|
530
|
+
Yt needs your support!
|
531
|
+
The goal of Yt is to provide a Ruby interface for all the methods exposed by
|
532
|
+
the [YouTube Data API (v3)](https://developers.google.com/youtube/v3) and by
|
533
|
+
the [YouTube Analytics API](https://developers.google.com/youtube/analytics).
|
534
|
+
|
535
|
+
If you find that a method is missing, fork the project, add the missing code,
|
536
|
+
write the appropriate tests, then submit a pull request, and it will gladly
|
537
|
+
be merged!
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "juce"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/juce.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'lib/juce/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "juce"
|
5
|
+
spec.version = Juce::VERSION
|
6
|
+
spec.authors = ["Claudio B"]
|
7
|
+
spec.email = ["62914375+claudiooutput@users.noreply.github.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{A library to parse files exported by JUCE apps}
|
10
|
+
spec.description = %q{A set of Ruby helpers to import and export data
|
11
|
+
coming from apps built with JUCE (https://juce.com).}
|
12
|
+
spec.homepage = "https://github.com/outputinc/juce"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = "https://github.com/outputinc/juce"
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/outputinc/juce"
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/outputinc/juce/blob/master/CHANGELOG.md"
|
20
|
+
|
21
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
end
|
data/lib/juce.rb
ADDED
data/lib/juce/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: juce
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Claudio B
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-04-10 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |-
|
14
|
+
A set of Ruby helpers to import and export data
|
15
|
+
coming from apps built with JUCE (https://juce.com).
|
16
|
+
email:
|
17
|
+
- 62914375+claudiooutput@users.noreply.github.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- ".gitignore"
|
23
|
+
- ".rspec"
|
24
|
+
- ".travis.yml"
|
25
|
+
- Gemfile
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- bin/console
|
29
|
+
- bin/setup
|
30
|
+
- juce.gemspec
|
31
|
+
- lib/juce.rb
|
32
|
+
- lib/juce/version.rb
|
33
|
+
homepage: https://github.com/outputinc/juce
|
34
|
+
licenses:
|
35
|
+
- MIT
|
36
|
+
metadata:
|
37
|
+
homepage_uri: https://github.com/outputinc/juce
|
38
|
+
source_code_uri: https://github.com/outputinc/juce
|
39
|
+
changelog_uri: https://github.com/outputinc/juce/blob/master/CHANGELOG.md
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 2.3.0
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubygems_version: 3.1.2
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: A library to parse files exported by JUCE apps
|
59
|
+
test_files: []
|