AI prompts
base on Vimeo API v3 wrapper for Ruby # VimeoMe2
[![Travis badge](https://travis-ci.org/bo-oz/vimeo_me2.svg?branch=master)](https://travis-ci.org/bo-oz/vimeo_me2)
A very basic wrapper for the Vimeo API. OAuth2 is not included in the code. You can easily write your own OAuth2 workflow with a gem like [OAuth2](https://github.com/intridea/oauth2). All you need is a Vimeo access token in order to easily make calls to their API using this gem.
A simple alternative method is to generate your own token, dedicated to your application, which can be clearly convenient in case of script use.
The procedure is to go in your app created on vimeo [https://developer.vimeo.com/](https://developer.vimeo.com/apps/xxxxxxx#authentication) and find the `Authentication` tab (it's next to the `Details` tab),
at the end, you'll find `Generate an Access Token`, customize as you wish, then click `send`. Your token is created and you are ready to use it.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'vimeo_me2', :git => "https://github.com/bo-oz/vimeo_me2.git"
```
And then execute:
$ bundle
## Usage
This gem consists of two classes that can access a user or a video object from Vimeo. Using the gem's methods requires having a Vimeo access token: [vimeo.com](https://developer.vimeo.com). When calling the classes, put in the access token and call the various methods.
### Making any call to Vimeo
Use utility methods to make any call to Vimeo. You can see the full list of endpoints in the Vimeo documentation on [vimeo.com](https://developer.vimeo.com).
```ruby
# Set up a client for making calls to Vimeo:
vimeo = VimeoMe2::VimeoObject.new('12345hjhsjdshasd')
# '12345hjhsjdshasd' must be replaced with a valid token.
# Make any GET request, by providing only the API endpoint:
vimeo.get('/me')
# Make any POST request, including a body.
# Don't forget to set the expected response code.
# You can also set additional headers.
body = "whatever"
vimeo.post('/videos/12344', body:body, headers:{'Content-Type': 'video/mp4'}, code:201)
# Delete items:
vimeo.delete('/videos/12344', code:204)
```
### Accessing a User
Take a look at the files under /lib/vimeo_me2/user/ for available methods.
```ruby
# Access your own user object:
vimeo_user = VimeoMe2::User.new('12345hjhsjdshasd')
# Access a different user's object:
vimeo_user = VimeoMe2::User.new('12345hjhsjdshasd','username')
```
#### Like
Get a list of likes. Like or unlike videos.
```ruby
# Fetch all likes for a user:
vimeo_user.view_all_likes
# Like a specific video:
vimeo_user.like_video 1234455
# Check if a video is liked:
vimeo_user.check_if_liked 1234455
# Returns true if liked, false if not liked.
# Unlike a video:
vimeo_user.unlike_video 1234455
```
### Uploading a video
#### Utilizing an upload form in Rails
At this moment there are two ways of uploading videos to Vimeo. The first one works in Rails and uploads an ActionDispatch::Http::UploadedFile object to Vimeo, like so:
```ruby
# RoR Example
# Set up a model like this:
class Videofile < ActiveRecord::Base
attr_accessor :video_file
before_create :upload_to_vimeo
def upload_to_vimeo
# connect to Vimeo as your own user, this requires upload scope
# in your OAuth2 token
vimeo_client = VimeoMe2::User.new('12345hjhsjdshasd')
# upload the video by passing the ActionDispatch::Http::UploadedFile
# to the upload_video() method. The data_url in this model stores
# the location of the uploaded video on Vimeo.
video = vimeo_client.upload_video(video_file)
self.data_url = video['uri']
true
rescue VimeoMe2::RequestFailed => e
errors.add(:video_file, e.message)
false
end
end
```
#### Uploading from plain Ruby
You can also upload a Video File through plain ruby:
```ruby
# Example in Plain Ruby
video = File.open('video.mp4')
vimeo_client = VimeoMe2::User.new('12345hjhsjdshasd')
vimeo_client.upload_video(video)
```
#### Utilizing the Vimeo Pull Request
The second method is using the Pull Upload method that's offered through the Vimeo Api. This method basically fetches video content from any accessible URL and uploads it to Vimeo
```ruby
# connect to Vimeo as your own user, this requires upload scope
# in your OAuth2 token
vimeo_client = VimeoMe2::User.new('12345hjhsjdshasd')
vimeo_client.pull_upload 'new name of the video', 'http://www.somelocation.com/video_content.mp4'
```
### Accessing a video
Take a look at the files under /lib/vimeo_me2/video/ for available methods.
```ruby
# Get access to a video (both options are valid)
vimeo_video = VimeoMe2::Video.new('12345hjhsjdshasd','196277011')
vimeo_video = VimeoMe2::Video.new('12345hjhsjdshasd','/videos/196277011')
# Or with an uploaded video like with the model
# in the above code fragment
videofile = Videofile.last
vimeo_video = VimeoMe2::Video.new('12345hjhsjdshasd',videofile.data_url)
# Get comments on the video:
vimeo_video.comments
# Get the name of the video:
vimeo_video.name
# Set the name of the video:
vimeo_video.name = "New name"
# Update the video:
vimeo_video.update
# Delete the video (if you have access to do that):
vimeo_video.destroy
```
At this moment the gem only returns the raw JSON response received from Vimeo. I do plan on extending this to also include a player embed method. But this is still a work in progress.
## TODO
* Write tests
* Include all parameters in the various API calls
* Write methods for every Vimeo API endpoint
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/bo-oz/vimeo_me2. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
## Changelog
### 1.2.0
* Updated the upload code to use the new 3.4 spec for uploading: https://developer.vimeo.com/api/upload/videos#resumable-guide
* The result of an upload is no longer the video URL, but the entire video JSON response
* Did some refactoring to the HTTP Request class
## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
", Assign "at most 3 tags" to the expected json: {"id":"10599","tags":[]} "only from the tags list I provide: [{"id":77,"name":"3d"},{"id":89,"name":"agent"},{"id":17,"name":"ai"},{"id":54,"name":"algorithm"},{"id":24,"name":"api"},{"id":44,"name":"authentication"},{"id":3,"name":"aws"},{"id":27,"name":"backend"},{"id":60,"name":"benchmark"},{"id":72,"name":"best-practices"},{"id":39,"name":"bitcoin"},{"id":37,"name":"blockchain"},{"id":1,"name":"blog"},{"id":45,"name":"bundler"},{"id":58,"name":"cache"},{"id":21,"name":"chat"},{"id":49,"name":"cicd"},{"id":4,"name":"cli"},{"id":64,"name":"cloud-native"},{"id":48,"name":"cms"},{"id":61,"name":"compiler"},{"id":68,"name":"containerization"},{"id":92,"name":"crm"},{"id":34,"name":"data"},{"id":47,"name":"database"},{"id":8,"name":"declarative-gui "},{"id":9,"name":"deploy-tool"},{"id":53,"name":"desktop-app"},{"id":6,"name":"dev-exp-lib"},{"id":59,"name":"dev-tool"},{"id":13,"name":"ecommerce"},{"id":26,"name":"editor"},{"id":66,"name":"emulator"},{"id":62,"name":"filesystem"},{"id":80,"name":"finance"},{"id":15,"name":"firmware"},{"id":73,"name":"for-fun"},{"id":2,"name":"framework"},{"id":11,"name":"frontend"},{"id":22,"name":"game"},{"id":81,"name":"game-engine "},{"id":23,"name":"graphql"},{"id":84,"name":"gui"},{"id":91,"name":"http"},{"id":5,"name":"http-client"},{"id":51,"name":"iac"},{"id":30,"name":"ide"},{"id":78,"name":"iot"},{"id":40,"name":"json"},{"id":83,"name":"julian"},{"id":38,"name":"k8s"},{"id":31,"name":"language"},{"id":10,"name":"learning-resource"},{"id":33,"name":"lib"},{"id":41,"name":"linter"},{"id":28,"name":"lms"},{"id":16,"name":"logging"},{"id":76,"name":"low-code"},{"id":90,"name":"message-queue"},{"id":42,"name":"mobile-app"},{"id":18,"name":"monitoring"},{"id":36,"name":"networking"},{"id":7,"name":"node-version"},{"id":55,"name":"nosql"},{"id":57,"name":"observability"},{"id":46,"name":"orm"},{"id":52,"name":"os"},{"id":14,"name":"parser"},{"id":74,"name":"react"},{"id":82,"name":"real-time"},{"id":56,"name":"robot"},{"id":65,"name":"runtime"},{"id":32,"name":"sdk"},{"id":71,"name":"search"},{"id":63,"name":"secrets"},{"id":25,"name":"security"},{"id":85,"name":"server"},{"id":86,"name":"serverless"},{"id":70,"name":"storage"},{"id":75,"name":"system-design"},{"id":79,"name":"terminal"},{"id":29,"name":"testing"},{"id":12,"name":"ui"},{"id":50,"name":"ux"},{"id":88,"name":"video"},{"id":20,"name":"web-app"},{"id":35,"name":"web-server"},{"id":43,"name":"webassembly"},{"id":69,"name":"workflow"},{"id":87,"name":"yaml"}]" returns me the "expected json"