jeudi 31 décembre 2020

Using Ruby to get email attachment ID

I am trying to loop through a set of emails, and get their email attachment ID. I can't seem to get down to the ID, though.

I've gotten this far:

class AccessEmailController < ApplicationController

def access_email

    client = Signet::OAuth2::Client.new(access_token: session[:access_token])
    service = Google::Apis::GmailV1::GmailService.new
    service.authorization = client

    user_id = 'me'

    email_list = service.list_user_messages('me', q: "subject:(CCC Data)")
    
    message = 'No Emails Found' if email_list.messages.empty?
   
    email_list.messages.each do |message|
        message_id = message.id
        @subject = service.get_user_message(user_id, message_id).payload.parts

    end
end

end

And, if I display @subject in a view, I get:

[#<Google::Apis::GmailV1::MessagePart:0x00007f8630c397a0 @headers=[#<Google::Apis::GmailV1::MessagePartHeader:0x00007f8630c344a8 @name="Content-Type", @value="multipart/alternative; boundary=\"00000000000020396d05b7ceda38\"">], @mime_type="multipart/alternative", @body=#<Google::Apis::GmailV1::MessagePartBody:0x00007f8630c39250 @size=0>, @filename="", @part_id="0", @parts=[#<Google::Apis::GmailV1::MessagePart:0x00007f8630c30588 @headers=[#<Google::Apis::GmailV1::MessagePartHeader:0x00007f8630c2d2e8 @name="Content-Type", @value="text/plain; charset=\"UTF-8\"">], @mime_type="text/plain", @body=#<Google::Apis::GmailV1::MessagePartBody:0x00007f8630c2ed50 @size=91, @data="-- \r\nKim Floyd (Davis)\r\n\r\nWeb Developer, EvenVision\r\n707.845.3073\r\nk.davis@evenvision.com\r\n">, @filename="", @part_id="0.0">, #<Google::Apis::GmailV1::MessagePart:0x00007f8630c2be98 @headers=[#<Google::Apis::GmailV1::MessagePartHeader:0x00007f8630c2a840 @name="Content-Type", @value="text/html; charset=\"UTF-8\"">, #<Google::Apis::GmailV1::MessagePartHeader:0x00007f8630c29ff8 @name="Content-Transfer-Encoding", @value="quoted-printable">], @mime_type="text/html", @body=#<Google::Apis::GmailV1::MessagePartBody:0x00007f8630c2b858 @size=344, @data="<div dir=\"ltr\"><br clear=\"all\"><div><br></div>-- <br><div dir=\"ltr\" class=\"gmail_signature\" data-smartmail=\"gmail_signature\"><div dir=\"ltr\">Kim Floyd (Davis)<div><br><div>Web Developer, EvenVision</div><div>707.845.3073</div><div><a href=\"mailto:k.davis@evenvision.com\" target=\"_blank\">k.davis@evenvision.com</a></div></div></div></div></div>\r\n">, @filename="", @part_id="0.1">]>, #<Google::Apis::GmailV1::MessagePart:0x00007f8630c28f68 @headers=[#<Google::Apis::GmailV1::MessagePartHeader:0x00007f8630c27b90 @name="Content-Type", @value="image/png; name=\"image.png\"">, #<Google::Apis::GmailV1::MessagePartHeader:0x00007f8630c26fd8 @name="Content-Disposition", @value="attachment; filename=\"image.png\"">, #<Google::Apis::GmailV1::MessagePartHeader:0x00007f8630c266f0 @name="Content-Transfer-Encoding", @value="base64">, #<Google::Apis::GmailV1::MessagePartHeader:0x00007f8630c25d40 @name="X-Attachment-Id", @value="f_kjdr80n00">, #<Google::Apis::GmailV1::MessagePartHeader:0x00007f8630c25250 @name="Content-ID", @value="<f_kjdr80n00>">], @mime_type="image/png", @body=#<Google::Apis::GmailV1::MessagePartBody:0x00007f8630c28a90 @size=459005, @attachment_id="ANGjdJ9LKnYW-GChtR3_oaBWnwi0DjHG4I8ZeDuMskuJ6htxLGmwNaB-v3x0k_cP94ybJFg0HLPO0AkSLWb-zXvF25qaGyhA20R89kwPSC9j3ttVEsBhByEAxrPkJQVwKuf3H8EblPhNNfPA7iYEJ7zT56do8-_UbMbDuXo-fVU445mtPHSYHWOEX_4z8aUyNTU3MCzNY8EHz90mJRpJnseelK3whaZdcJ2E98XmxQ">, @filename="image.png", @part_id="1">]

Which, does contain the attachment I am looking for. How can I get down to that attachment, though, and get it's ID?

mercredi 30 décembre 2020

run ruby file from ajax or on button click event

i am new in ruby. so i have html code which includes one input field and button and i want when user click on that button i have to run one ruby file which has system() method.

index.html


     <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
     </head>
     <body>
        <form method="post" action="/runMethod">
           <input type="text" name="name" value="whatever">
           <input class='btn btn-primary' type='submit' value='click'>
        </form>
     </body>

   

app.rb

 system("wayback_machine_downloader userInput")

this is my two files code. i just want that if i click on button app.rb file should run with given input. is it possible?

mardi 29 décembre 2020

dimanche 27 décembre 2020

Does anyone know why IRB gives the syntax error in block?

It's just plain ruby. Any ideas why the code below throws syntax error?

irb(main):001:0> def count_valid_policies(input)
irb(main):002:1>   counter = 0
irb(main):003:1>   policies = input.split("\n")
irb(main):004:1>   policies.each do |policy|
irb(main):005:2*     valid?(policy) && counter++
irb(main):006:2*   end
irb(main):007:1>
irb(main):008:1>   puts counter
irb(main):009:1> end
Traceback (most recent call last):
        1: from /usr/local/bin/irb:11:in `<main>'
SyntaxError ((irb):6: syntax error, unexpected keyword_end)
  end
  ^~~
(irb):9: syntax error, unexpected end-of-input, expecting keyword_end

lundi 21 décembre 2020

How can I make a Rails which can auto locate place and display as google map?

I am trying to make a simple program which can locate your place, for example when you enter your place my program will display your map as google map.

When I search by google, they said that I can use Gmaps4rails, but unfortunately that it seems obsolete and I can not use it anymore.

Could you please give me any idea? Or some link ?

Thank you very much.

Fetch an image file kept at server using JS in rails

I am using rails v 3.2 and ruby v - 1.9. I have been trying to work this out and after a lot of googling can't find a solution. If there are certain files created at runtime at the server side, how do i fetch them and show them to the user i'e; the client side using JS. please note that there can be any number of files and are mainly images and all of them need to be shown at once. any help would be great.

vendredi 18 décembre 2020

ruby on rails ails with couldn't find file jquery.ui.all

couldn't find file 'jquery.ui.all' which is a known issue, I added *=require jquery.ui.all to application.css and //= require jquery.ui.all to application.js but still get the error.

I already installed "jquery-ui-rails" and "jquery-rails"

mercredi 16 décembre 2020

Why I can not delete object when click destroy in Rails?

I am trying to click link destroy but it going to in the page details? I use CRUD default of rails Here is the code :

tbody>
    <% @posts.each do |post| %>
      <tr>
        <td><%= post.tittle %></td>
        <td><%= post.body %></td>
        <td><%= link_to 'Show', post %></td>
        <td><%= link_to 'Edit', edit_post_path(post) %></td>
        <td><%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %></td>
      </tr>
    <% end %>
  </tbody>

Why I can not delete object when click destroy in ruby on rails [closed]

Please me ask why when I click link destroy but it going to in the page details? I use CRUD defaut of rails Here is the code:

<p id="notice"><%= notice %></p>

<h1>Posts</h1>

<table>
  <thead>
    <tr>
      <th>Tittle</th>
      <th>Body</th>
      <th colspan="3"></th>
   </tr>
 </thead>

  <tbody>
    <% @posts.each do |post| %>
      <tr>
        <td><%= post.tittle %></td>
        <td><%= post.body %></td>
        <td><%= link_to 'Show', post %></td>
        <td><%= link_to 'Edit', edit_post_path(post) %></td>
        <td><%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %>
        </td>
      </tr>
    <% end %>
  </tbody>
</table>

<br>

<%= link_to 'New Post', new_post_path %>

Thank you everyone

lundi 14 décembre 2020

Ruby efficient each loop

Is there a better way to write this? markdown is a StringIO

coverage_hash_arr.each do |the_hash|
    markdown << "------- Status on #{the_hash[:Module]} -------\n"
    the_hash.delete(:Module)
    the_hash.each {|key, value| markdown << "- #{key}: #{value} \n"} 
    markdown << "----------------------------------------------\n"
end

samedi 12 décembre 2020

JWT Auth giving error when attempting to login user

Im using JWT with a Rails backend/React frontend. Im attempting to have my user redirected when they log into their account to the /home page of the site. The error I am receiving is

TypeError: Cannot read property 'push' of undefined
Login.<anonymous>
src/components/Login.js:20
 17 |   if(res.user){
 18 |     localStorage.token = res.token
 19 |     this.setState({user:{id:res.user.id, username:res.user.username, token:res.token}, home:res.user.home}, () => {
> 20 |     this.props.history.push('/home')
    | ^  21 |   })
 22 | } else {
 23 |     alert(res.error)

Ive did make a change, to the home component but since reverted back to what it was but still having issues....

my controllers...

class ApplicationController < ActionController::API
  def encode_token(payload)
      JWT.encode(payload, "coffee")
  end 

def auth_header
  # { Authorization: 'Bearer <token>' }
  request.headers['Authorization']
end

def decoded_token
  if auth_header
    token = auth_header.split(' ')[1]
    # header: { 'Authorization': 'Bearer <token>' }
    begin
      JWT.decode(token,'coffee', true, algorithm: 'HS256')
    rescue JWT::DecodeError
      nil
    end
  end
end

def current_user
  if decoded_token
    user_id = decoded_token[0]['user_id']
    @user = User.find_by(id: user_id)
  end
end

def logged_in?
  !!current_user
end

def authorized
  render json: { message: 'Please log in' }, status: :unauthorized unless logged_in?
end
end
----
class UsersController < ApplicationController
    before_action :authorized, only:[:persist]

    def create
        @user = User.create(user_params)
        if @user.valid?
            token = encode_token({user_id: @user.id})   
            render json: @user
        else 
            render json: {error:'failed to create a user'}
        end
    end 

    def login
        @user = User.find_by(username:params[:username])
        if @user && @user.authenticate(params[:password])
            token = encode_token({user_id: @user.id})
            render json: {user:UserSerializer.new(@user), token:token}
        else
            render json: {error:"wrong user or password"}
        end 
        
    end 
    
    def index 
        @user = User.all
        render json: @user
    end
    def persist
        token = encode_token({user_id: @user.id})
        render json: {user:UserSerializer.new(@user), token:token} 
    end 

    private 
    def user_params
        params.permit(:username, :password)
    end 
end

my user_serializer...

class UserSerializer < ActiveModel::Serializer
    attributes :id, :username
    has_many :favorites
    has_many :favorite_coffee_shops, through: :favorites, source: :coffee_shop
    has_many :reviews
    has_many :coffee_shops, through: :reviews
  end

my login component...

import React from 'react';
import SignUp from './SignUp';

class Login extends React.Component{

    state={
      user:{
        id:0,
        username:"",
        token:""
      },
      home:[]
    }
     

       handleAuthResponse = (res) => {
         if(res.user){
           localStorage.token = res.token
           this.setState({user:{id:res.user.id, username:res.user.username, token:res.token}, home:res.user.home}, () => {
           this.props.history.push('/home')
         })
       } else {
           alert(res.error)
         }
       }

       handleLogin = (e, userInfo) =>{
        e.preventDefault()
        console.log(e)
     
        fetch('http://localhost:3000/login',{
         method:"POST",
         headers:{
           'Content-Type':'application/json'
         },
         body:JSON.stringify(userInfo)
       })
       .then(res => res.json())
       .then(json => {
         console.log(json)
         if(!json.error){
           this.handleAuthResponse(json)
         }else {
           alert(json.error)
         }
       })
       .catch(err => console.log(err))
      }
     
      
handleChange = (e) => {
  let {name, value} = e.target
  this.setState({
    [name]: value
  })
}


render(){
  return (
    <div className="login">Welcome Back!
     <form onSubmit={(e) => this.handleLogin(e, this.state)}>
       <div>
         <label>UserName</label>
         <br></br>
         <input type="text" name="username" value={this.state.username} onChange={this.handleChange}/>
         </div>
         <div>
         <label>Password</label>
         <br></br>
         <input type="password" name="password" value={this.state.password} onChange={this.handleChange}/>
         </div>
         <input type="submit" value="Submit" className="sl-btn" />
      </form>
      <div></div>
      <SignUp />
    </div>
  );
}
}

export default Login;

and my home component im attempting to push the user to once logged-in

import React from 'react'
import MapContainer  from '../containers/MapContainer'
import NavBar from './NavBar'
import FavoritesContainer  from './FavoritesContainer'

class Home extends React.Component {

    state = {
        reviews: [],
        favorites: [],
    }

    componentDidMount(){
    fetch('http://localhost:3000/reviews')
    .then(res => res.json())
    .then(reviews => this.setState({ reviews }))
    }
              
    addReview = (review) => {
        fetch('http://localhost:3000/reviews',{
            method: "POST",
            headers: {
                "Content-Type" : "application/json",
                Accept: "application/json",
                Authorization: `bearer ${localStorage.token}`
            },
            body: JSON.stringify({ review: review }
            ),
        })
        .then(res => res.json())
        .then(( json => {
            this.setState(prevState => ({
                reviews: [...prevState.reviews, json ]
               }))
        }))
    }
  
    render() {
        return (
               <div className="home">
                   <NavBar />
                   <MapContainer />
                   <FavoritesContainer />
           </div>
        )
}
}

export default Home

I am pretty new dev, please let me know if there is anymore info needed to help diagnose the problem. any advice would be helpful, thank you!!

jeudi 10 décembre 2020

Uploading .heic images in Rails 3.2 using paperclip gem

Users are unable to upload .heic images. Doesn't seem to be as simple as adding "images/heic" to content_type validations or just changing the file type to .jpg or .png. Is there a way to get this done using paperclip or should we use an API to convert the .heic image to .jpg or .png before attaching and uploading?

mercredi 9 décembre 2020

Questions and Simple Problems using ruby on rails?

I'm going to attend the final round of interview. They said they will ask the simple problems on ruby on rails from the below topics and bit deep fundamentals on these topics.

Senior Programmers in ruby on rails kindly suggest me some problems and question from these topics that you will ask to the candidate when you interview them?. It helps me a lot during this pandemic to get job.

SECTION: THE RUBY PROGRAMMING LANGUAGE.

  • TOPICS: ▪ Working with strings. ▪ Working with numbers. ▪ Methods. ▪ Branching if/elsif/else/end. ▪ Operators. ▪ Array and Iterators. ▪ Hashes. ▪ Object Oriented Programming. ▪ Attributes, getters, setters. ▪ ‘Self’ notation for method names.

• SECTION: INTRODUCTION TO RUBY ON RAILS.

  • TOPICS: ▪ Model, View and Controller. ▪ Rail App Structure. ▪ Root route, controller, more MVC. ▪ Structure of Rails Application. ▪ Front-End: Learn basic HTML, CSS. ▪ Add about Page. ▪ The back-end: Database and tables. ▪ The back-end: CRUD scaffold.

• SECTION: CRUD OPERATION IN RUBY ON RAILS.

  • TOPICS: ▪ Tables. Migration and naming convention. ▪ Models and rails console. ▪ CRUD operation from rails console. ▪ Validations. ▪ Route, action, view. ▪ Index, new article form.
    ▪ Create action. ▪ Edit and update existing. ▪ Delete. ▪ User Interface. ▪ DRY code.

mardi 8 décembre 2020

Trying to get reviews for a specfic game

Im attempting to see reviews for a specific game that ive created. Right now my reviews/index show for all games, not just the specific game im looking for. Im assuming its just something im missing in my params but not sure...

these my are controllers...

class ReviewsController < ApplicationController
  before_action :set_review, only: [:show, :edit, :update, :destroy]
  before_action :authenticate_user!, except:[:index, :show]
  before_action :correct_user, only: [:edit, :update, :destroy]

  def index
    @reviews = Review.all
  end

  def show
    @review = Review.find(params[:id])
  end 
...
class GamesController < ApplicationController
  before_action :set_game, only: [:show, :edit, :update, :destroy]
 
  def index
    @games = Game.all
  end


  def show
  end

my routes ...

reviews#index
                                      POST   /games/:game_id/reviews(.:format)                                                        reviews#create
                      new_game_review GET    /games/:game_id/reviews/new(.:format)                                                    reviews#new
                     edit_game_review GET    /games/:game_id/reviews/:id/edit(.:format)                                               reviews#edit
                          game_review GET    /games/:game_id/reviews/:id(.:format)                                                    reviews#show
                                      PATCH  /games/:game_id/reviews/:id(.:format)                                                    reviews#update
                                      PUT    /games/:game_id/reviews/:id(.:format)                                                    reviews#update
                                      DELETE /games/:game_id/reviews/:id(.:format)                                                    reviews#destroy
                                games GET    /games(.:format)                                                                         games#index
                                      POST   /games(.:format)                                                                         games#create
                             new_game GET    /games/new(.:format)                                                                     games#new
                            edit_game GET    /games/:id/edit(.:format)                                                                games#edit
                                 game GET    /games/:id(.:format)                                                                     games#show
                                      PATCH  /games/:id(.:format)                                                                     games#update
                                      PUT    /games/:id(.:format)                                                                     games#update
                                      DELETE /games/:id(.:format)                                                                     games#destroy
                                 root GET    /                                                                                        games#index

this is how im attempting to do my link_to but its showing all the games reviews in my seeds not just a single game and all its reviews...

<%= link_to 'reviews', game_reviews_path(game_id: @game.id), @reviews %>

first RoR prj on my own, any help would be great!!

thanks!

lundi 7 décembre 2020

Unable to get my edit button to work with form_with helper

I'm attempting to create an Edit action with form_with in Rails.... My other CRUD actions are working ok, so something to do with my form_with...

<%= form_with(model: [@game, @review], local:true) do |form| %>

this is the tag im attempting to create, yet when I do i get this error

undefined method `review_path' for #<#<Class:0x00007fedfa8befd0>:0x00007fedfa8bd298>
Did you mean?  view_paths

directing me back to the tag, this is my controller

def new
   @game = Game.find(params[:game_id])
   @review = current_user.reviews.new
  end

  # GET /reviews/1/edit
  def edit
  end

  # POST /reviews
  # POST /reviews.json
  def create
    @review = current_user.reviews.new(review_params)
    @game = Game.find(params[:game_id])
    @review.game_id = @game.id

    respond_to do |format|
      if @review.save
        format.html { redirect_to game_reviews_path(@review), notice: 'Review was successfully created.' }
        format.json { render :show, status: :created, location: @review }
      else
        format.html { render :new }
        format.json { render json: @review.errors, status: :unprocessable_entity }
      end
    end
  end
  # <%= link_to "New Review", new_game_review_path(game_id: @game.id) %>


  # PATCH/PUT /reviews/1
  # PATCH/PUT /reviews/1.json
  def update
    @review = current_user.reviews.update(review_params)
    @game = Game.find(params[:game_id])
    @review.game_id = @game.id

    respond_to do |format|
      if @review.update(review_params)
        format.html { redirect_to @review, notice: 'Review was successfully updated.' }
        format.json { render :show, status: :ok, location: @review }
      else
        format.html { render :edit }
        format.json { render json: @review.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /reviews/1
  # DELETE /reviews/1.json
  def destroy
    @review.destroy
    respond_to do |format|
      format.html { redirect_to game_reviews_path(@review), notice: 'Review was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  def correct_user
    @review = current_user.reviews.find_by(id: params[:id])
    redirect_to reviews_path, notice:" Not Authorized to Edit This Review" if @review.nil?
    end

Still pretty new to Rails, any help would be great!

Thanks

Trix editor rails

I am creating an article and on the index page I want to show the table in which I'll give the list of the particular article's attachments. How can I get the list of attachments for a particular article I have created. I have searched many things and unable to find any solution.

Action-text-editor-validation in rails

If in a blog I have 2 action text editors. Say one for comments and one for articles. If I wanted to handle the attachments for only of comments editor i.e. I want to pass only image in comments attachments and the article trix editor should be same. How to implement this. I used this but it is getting implemented with both editors.

comment_form

<%= form_with model: @comment do |f| %>
            <div class="class="card mb-2"">
              <div class="card-body">
            <h4><%= f.label :Comment %></h4>
              <%= f.rich_text_area :body %>
            </div>
            </div>
              <%= f.submit 'Comment', :class => 'pull-right btn-info btn-lg'%>
          <% end %>


<script type="text/javascript">
  window.addEventListener("trix-file-accept", function(event) {
  event.preventDefault()
  alert("File attachment not supported!")
})
</script>

jeudi 3 décembre 2020

SQLite3::SQLException: near "at": syntax error

I keep getting this error when trying to loop through the jobs i have , here is the code :

- @jobs.each do |job|
  %h2= job.title
  %p= job.company 

this exception the :"SQLite3::SQLException: near "at": syntax error" its not identifying the "-" at the beginning of the line. My file is a .html.haml file.

mercredi 2 décembre 2020

how to export csv file checkbox value into table in rails?

I want to checkbox value with csv file.I was tried under code

student.rb def self.to_csv attributes = %w{id status email temp_registration_date full_name full_name_kana main_registration_date email2 postal_code1 postal_code2 address1 address2 tel_main tel_sub sex school_type school_name school_name_initial department_name faculty_type graduation_month industry_id industry_most_id occupation_id occupation_most_id desired_work_region_code club_flg school_club_name school_club_type club_name lab_name major_field research_subject_title research_subject_summary interested_companies personal_summary how_known how_known_other mail_magazine_flg}

CSV.generate(headers: true) do |csv|
csv << attributes

all.each do |student|
    
    csv << [student.id,student.status,
 student.sex, if (student.school_type == 1)
    大学
 elsif (student.school_type == 2)
    大学院(修士)
 elsif (student.school_type == 3)
    大学院(博士)
 elsif (student.school_type == 4)
    短大
 elsif (student.school_type == 5)
    専門学校
 elsif (student.school_type == 6)
    高専
 end]
end
end

Correct Installation of Google Analytics on Ruby on Rails

I have a friend who has a developer working on this site: https://www.cannasaver.com/

When I access different pages on the site the UA code seems to duplicate over and over again according to the Google Tag Manager extension.

enter image description here

The developer is saying this is normal implementation and there there is nothing wrong. However on the other sites they own such as this: http://cannapages.com/ -- this does not seem to be the case.

I am wondering if the Google Analytics code is correctly implemented on https://www.cannasaver.com/ -- Any help you have as to if it is correctly added or what to do to fix it would be great appreciated!

mardi 1 décembre 2020

Writing crawler in ruby

I am writing a crawler in ruby, for the movie section of bsvalue website. https://bsvalue.com/category/5f74877a50e0c79d5d58b8a4;categoryTitle=Movies I am able to get the json, but i don't have idea how to save/print that all the movies name , id, cast etc, one by one using parmas . Can anyone help me in this.

here is the starting of my code which gives me json response

require "net/http"

url = URI("https://blacksheepapi.com/app-v2/api/mobile/home/category/5f74877a50e0c79d5d58b8a4/with-videos?offset=0&limit=40")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Get.new(url)
request["authority"] = "blacksheepapi.com"
request["pragma"] = "no-cache"
request["cache-control"] = "no-cache"
request["accept"] = "application/json, text/plain, */*"
request["authorization"] = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7ImlkIjoiNWZhM2EzYWZmNmRhY2MxMjVkOTQ3ZDlmIiwidXNlclR5cGUiOjIsImlzUHJlbWl1bVVzZXIiOmZhbHNlfSwiaWF0IjoxNjA2NzMxMTAwLCJleHAiOjE2MDkzMjMxMDB9.gv7iOF8s6aKBqiTMw1q-mdkxRjnfPnivuG4orBg2T0c"
request["user-agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.67 Safari/537.36"
request["origin"] = "https://bsvalue.com"
request["sec-fetch-site"] = "cross-site"
request["sec-fetch-mode"] = "cors"
request["sec-fetch-dest"] = "empty"
request["referer"] = "https://bsvalue.com/"
request["accept-language"] = "en-GB,en-US;q=0.9,en;q=0.8"

response = https.request(request)
puts response.read_body

json = JSON.parse(response.body)

This is the json response I'm getting

    "isVisible" => true,
    "isDeleted" => false,
    "videoIds" => [{
        "isPremiumVideo" => false,
        "ageLimit" => 6,
        "_id" => "5fa01e17d7f2c12af4b03cf8",
        "title" => "Anjaneya",
        "images" => {
            "_id" => "5fb3b34f367224583e2f1ff4", "mobileBannar" => "5fa01e17d7f2c12af4b03cf8/assets/450_270.jpg?160561236759778053", "mobileThumbMedium" => "5fa01e17d7f2c12af4b03cf8/assets/370_500.jpg?160561236759790246", "tvDetailBannar" => "5fa01e17d7f2c12af4b03cf8/assets/1280_720.jpg?160561236759773244", "videoLogo" => "5fa01e17d7f2c12af4b03cf8/assets/600_200.png?160561236759760443", "posterUrl" => "5fa01e17d7f2c12af4b03cf8/assets/video-poster.jpg?160561236759725158"
        },
        "cast" => "Ajith Kumar, Meera Jasmine, Raghuvaran, Seetha, Jaya Prakash Reddy.",
        "categoryId" => "5f74877a50e0c79d5d58b8a4",
        "description" => "ACP Paramaguru (Ajith Kumar) is an efficient police officer who fights with the scum of the society. He later masquerades as a thief to infiltrate into the underworld. The bad guys are surprised to find that Paramguru is the ACP and is out to get them, so they all gang up against him. In this process, a thrilling encounter takes place between the good and the evil. Paramaguru is helped in his fight against injustice by Divya (Meera Jasmine), who falls in love with him.\n\nAnjaneya is a 2003 Indian Tamil-language action film directed by N. Maharajan. ",
        "miniPreviewUrl" => "5fa01e17d7f2c12af4b03cf8/assets/mini_preview.mp4",
        "sourceVideoQuality" => "1080p",
        "timeCode" => "2hr 54min 18sec",
        "videoType" => "ORIGINAL"
    }, {
        "isPremiumVideo" => false,
        "ageLimit" => 6,
        "_id" => "5fa29daad7f2c12af4b0adba",
        "title" => " Agni Natchathiram",
        "images" => {
            "_id" => "5fb3b35c367224583e2f2d6b", "mobileBannar" => "5fa29daad7f2c12af4b0adba/assets/450_270.jpg?160561238048172958", "mobileThumbMedium" => "5fa29daad7f2c12af4b0adba/assets/370_500.jpg?160561238048143726", "tvDetailBannar" => "5fa29daad7f2c12af4b0adba/assets/1280_720.jpg?160561238048193416", "videoLogo" => "5fa29daad7f2c12af4b0adba/assets/600_200.png?160561238048128347", "posterUrl" => "5fa29daad7f2c12af4b0adba/assets/video-poster.jpg?160561238048142775"
        },
        "cast" => "Prabhu , Karthik , Amala",
        "categoryId" => "5f74877a50e0c79d5d58b8a4",
        "description" => "Agni Natchathiram (transl. Scorching Star) is a 1988 Indian Tamil-language action drama film written and directed by Mani Ratnam. The film stars Prabhu, Karthik, Amala and newcomer Nirosha, with Vijayakumar, Jayachitra, Sumithra, Tara, S. N. Lakshmi and G. Umapathy in pivotal roles. It revolves around two half-brothers who come into conflict with each other in their claim for legitimacy as sons of a common father.",
        "miniPreviewUrl" => "5fa29daad7f2c12af4b0adba/assets/mini_preview.mp4",
        "sourceVideoQuality" => "1080p",
        "timeCode" => "2hr 19min 23sec",
        "videoType" => "ORIGINAL"
    }, {
        "isPremiumVideo" => false,
        "ageLimit" => 6,
        "_id" => "5fa670c76785a54d2d96f9d5",
        "title" => " Vaanchinathan",
        "images" => {
            "_id" => "5fb3b365367224583e2f3968", "mobileBannar" => "5fa670c76785a54d2d96f9d5/assets/450_270.jpg?16056123899617075", "mobileThumbMedium" => "5fa670c76785a54d2d96f9d5/assets/370_500.jpg?160561238996146991", "tvDetailBannar" => "5fa670c76785a54d2d96f9d5/assets/1280_720.jpg?160561238996144346", "videoLogo" => "5fa670c76785a54d2d96f9d5/assets/600_200.png?160561238996173272", "posterUrl" => "5fa670c76785a54d2d96f9d5/assets/video-poster.jpg?160561238996137035"
        },
        "cast" => "vijaykanth , ramyakrishnan",
        "categoryId" => "5f74877a50e0c79d5d58b8a4",
        "description" => "Vanchinathan (Vijayakanth) is naturally the supercop who has been transferred from Gujarat. He is someone who is not averse to using the law in his own ways by killing someone and picking a suitable alibi, as long as the person is evil and will not be punished by the law.",
        "miniPreviewUrl" => "5fa670c76785a54d2d96f9d5/assets/mini_preview.mp4",
        "sourceVideoQuality" => "1080p",
        "timeCode" => "2hr 47min 55sec",
        "videoType" => "ORIGINAL"
    }, {
        "isPremiumVideo" => false,
        "ageLimit" => 6,
        "_id" => "5fa6719d6785a54d2d96f9d8",
        "title" => " Periyanna",
        "images" => {
            "_id" => "5fb3b370367224583e2f46c3", "mobileBannar" => "5fa6719d6785a54d2d96f9d8/assets/450_270.jpg?160561240070856606", "mobileThumbMedium" => "5fa6719d6785a54d2d96f9d8/assets/370_500.jpg?160561240070824901", "tvDetailBannar" => "5fa6719d6785a54d2d96f9d8/assets/1280_720.jpg?160561240070872441", "videoLogo" => "5fa6719d6785a54d2d96f9d8/assets/600_200.png?160561240070832853", "posterUrl" => "5fa6719d6785a54d2d96f9d8/assets/video-poster.jpg?160561240070845895"
        },
        "cast" => "surya , meena",
        "categoryId" => "5f74877a50e0c79d5d58b8a4",
        "description" => "periyana",
        "miniPreviewUrl" => "5fa6719d6785a54d2d96f9d8/assets/mini_preview.mp4",
        "sourceVideoQuality" => "1080p",
        "timeCode" => "2hr 22min 42sec",
        "videoType" => "ORIGINAL"
    }, {
        "isPremiumVideo" => false,
        "ageLimit" => 6,
        "_id" => "5fa924d16785a54d2d96fd64",
        "title" => "Villain",
        "images" => {
            "_id" => "5fb3b37b367224583e2f534c", "mobileBannar" => "5fa924d16785a54d2d96fd64/assets/450_270.jpg?160561241118737975", "mobileThumbMedium" => "5fa924d16785a54d2d96fd64/assets/370_500.jpg?160561241118769411", "tvDetailBannar" => "5fa924d16785a54d2d96fd64/assets/1280_720.jpg?160561241118738963", "videoLogo" => "5fa924d16785a54d2d96fd64/assets/600_200.png?160561241118799290", "posterUrl" => "5fa924d16785a54d2d96fd64/assets/video-poster.jpg?160561241118758637"
        },
        "cast" => " Ajith & Meena,Kiran. Sujatha, FEFSI Vijayan, Karunaas , Ramesh Khanna",
        "categoryId" => "5f74877a50e0c79d5d58b8a4",
        "description" => "\nVillain is a 2002 Indian Tamil-language action masala film written and directed by K. S. Ravikumar and produced by S. S. Chakravarthy",
        "miniPreviewUrl" => "5fa924d16785a54d2d96fd64/assets/mini_preview.mp4",
        "sourceVideoQuality" => "1080p",
        "timeCode" => "2hr 44min 36sec",
        "videoType" => "ORIGINAL"
    }],```

Crawler in ruby

I am writing a crawler in ruby, for the movie section of bsvalue website. https://bsvalue.com/category/5f74877a50e0c79d5d58b8a4;categoryTitle=Movies I am able to get the json, but i don't have idea how to save/print that all the movies name , id, cast etc, one by one using parmas . Can anyone help me in this.

here is the starting of my code which gives me json response

require "net/http"

url = URI("https://blacksheepapi.com/app-v2/api/mobile/home/category/5f74877a50e0c79d5d58b8a4/with-videos?offset=0&limit=40")

https = Net::HTTP.new(url.host, url.port);
https.use_ssl = true

request = Net::HTTP::Get.new(url)
request["authority"] = "blacksheepapi.com"
request["accept"] = "application/json, text/plain, */*"
request["authorization"] = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7ImlkIjoiNWZhYjk0NmIxZmVmZWQxN2I1Njc5ZWY4IiwidXNlclR5cGUiOjIsImlzUHJlbWl1bVVzZXIiOmZhbHNlfSwiaWF0IjoxNjA2NzMxMTgzLCJleHAiOjE2MDkzMjMxODN9.bgE8acYdOz5E7pqGLfOEP9D-No8AhJzj_ruYtygLkRU"
request["user-agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36"
request["origin"] = "https://bsvalue.com"
request["sec-fetch-site"] = "cross-site"
request["sec-fetch-mode"] = "cors"
request["sec-fetch-dest"] = "empty"
request["referer"] = "https://bsvalue.com/"
request["accept-language"] = "en-GB,en-US;q=0.9,en;q=0.8"
request["if-none-match"] = "W/\"7b13-8sXFO/kqq7iWIQEBPNiEsg35CNQ\""

response = https.request(request)
puts response.read_body

json = JSON.parse(response.body)