Class: Jani::ConverterClient::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/jani/converter_client/connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(base_url) ⇒ Connection

Returns a new instance of Connection.



6
7
8
# File 'lib/jani/converter_client/connection.rb', line 6

def initialize(base_url)
  @base_url = base_url
end

Instance Method Details

#connectionObject



37
38
39
# File 'lib/jani/converter_client/connection.rb', line 37

def connection
  @connection ||= Faraday.new(url: @base_url)
end

#get_movie(uuid) ⇒ Object



10
11
12
13
14
# File 'lib/jani/converter_client/connection.rb', line 10

def get_movie(uuid)
  Jani::ConverterClient::Response.new(
    connection.get("uuid/#{uuid}.json")
  )
end

#post_movie(movie_data: {}, callback_url: "") ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/jani/converter_client/connection.rb', line 16

def post_movie(movie_data: {}, callback_url: "")
  Jani::ConverterClient::Response.new(
    connection.post() do |req|
      req.url "#{@base_url}.json"
      req.headers['Content-Type'] = 'application/json'
      req.body = {
        movie: {
          fps: movie_data[:fps],
          frame_height: movie_data[:frame_height],
          frame_width: movie_data[:frame_width],
          remote_movie_url: movie_data[:remote_movie_url],
          postroll_banner_attributes: movie_data[:postroll_banner],
          loading_banner_attributes: movie_data[:loading_banner],
          tracking_events: movie_data[:tracking_events],
        },
        callback_url: callback_url
      }.to_json
    end
  )
end