Class: Resizing::Video::Client

Inherits:
Object
  • Object
show all
Includes:
Configurable, Constants, HttpClientable
Defined in:
lib/resizing/video/client.rb

Constant Summary

Constants included from Constants

Constants::HTTP_STATUS_CREATED, Constants::HTTP_STATUS_NOT_FOUND, Constants::HTTP_STATUS_OK

Instance Method Summary collapse

Methods included from HttpClientable

#handle_faraday_error, #handle_timeout_error, #http_client

Methods included from Configurable

included, #initialize_config

Constructor Details

#initialize(*attrs) ⇒ Client

Returns a new instance of Client.



10
11
12
# File 'lib/resizing/video/client.rb', line 10

def initialize(*attrs)
  initialize_config(*attrs)
end

Instance Method Details

#build_prepare_urlObject



58
59
60
# File 'lib/resizing/video/client.rb', line 58

def build_prepare_url
  "#{config.video_host}/projects/#{config.project_id}/upload/videos/prepare"
end

#delete(response_or_url) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/resizing/video/client.rb', line 36

def delete response_or_url
  url = url_from response_or_url, 'destroy_url'

  response = handle_faraday_error do
    http_client.put(url) do |request|
      request.headers['X-ResizingToken'] = config.generate_auth_header
    end
  end
  handle_upload_completed_response response
end

#metadata(response_or_url) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/resizing/video/client.rb', line 47

def  response_or_url
  url = url_from response_or_url, 'self_url'

  response = handle_faraday_error do
    http_client.get(url) do |request|
      request.headers['X-ResizingToken'] = config.generate_auth_header
    end
  end
   response
end

#prepareObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/resizing/video/client.rb', line 14

def prepare
  url = build_prepare_url

  response = handle_faraday_error do
    http_client.post(url) do |request|
      request.headers['X-ResizingToken'] = config.generate_auth_header
    end
  end
  handle_prepare_response response
end

#upload_completed(response_or_url) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/resizing/video/client.rb', line 25

def upload_completed response_or_url
  url = url_from response_or_url, 'upload_completed_url'

  response = handle_faraday_error do
    http_client.put(url) do |request|
      request.headers['X-ResizingToken'] = config.generate_auth_header
    end
  end
  handle_upload_completed_response response
end