-
Notifications
You must be signed in to change notification settings - Fork 6
3 Resources
SergeyMell edited this page Jan 3, 2018
·
6 revisions
As long as not all the API endpoints are implemented in "Ruby Way" you can make any request with a universal wrapper i.e
Vimeo.resource.get('/api/resource/id/etc')
Available actions are get
, post
, put
, patch
and delete
For example
# Get all videos a user has liked
Vimeo.resource.get('/me/likes')
# Add video to an album
Vimeo.resource.put("/me/albums/#{album_id}/videos/#{video_id}")
# Delete a channel
Vimeo.resource.delete("/channels/#{channel_id}")
Vimeo API workflow is based on a different resources such as users, videos, albums, comments etc. Each resource has its own uri and methods. Almost all of them has standard Create Read Update Destroy actions.
You can build a resource on the basis of its uri and call appropriate action:
# Get all albums of user with ID 12345
Vimeo.album('/users/12345/albums').index
# Delete my album with ID 67890
Vimeo.album('/me/albums/67890').destroy
Resource may have some specific actions, i.e.
# Add videos to my album
Vimeo.album('/me/albums/67890').add_videos(['11111', '22222', '33333'])
As you can see the resources are nested. For example, user can have many albums, video can have many comments and so on. Using this, you can rewrite actions above in more natural way:
# Get all albums of user with ID 12345
Vimeo.user('12345').albums.index
# Delete my album with ID 67890
Vimeo.user.album('67890').destroy
# Add videos to my album
Vimeo.user.album('67890').add_videos(['11111', '22222', '33333'])