Class: Sproutvideo::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/sproutvideo/resource.rb

Direct Known Subclasses

AccessGrant, Account, Analytics, Login, Playlist, Tag, UploadToken, Video

Class Method Summary collapse

Class Method Details

.api_keyObject



3
4
5
# File 'lib/sproutvideo/resource.rb', line 3

def self.api_key
  Sproutvideo.api_key
end

.base_urlObject



6
7
8
# File 'lib/sproutvideo/resource.rb', line 6

def self.base_url
  Sproutvideo.base_url
end

.delete(path, options = {}) ⇒ Object



75
76
77
78
79
80
81
82
83
84
# File 'lib/sproutvideo/resource.rb', line 75

def self.delete(path, options = {})
  begin
    resp = RestClient.delete(
      "#{base_url}#{path}",
      {'SproutVideo-Api-Key' => api_key, :params => options.dup})
  rescue => e
    resp = e.response
  end
  Response.new(resp)
end

.get(path, options = {}) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/sproutvideo/resource.rb', line 51

def self.get(path, options = {})
  begin
    resp = RestClient.get(
      "#{base_url}#{path}",
      {'SproutVideo-Api-Key' => api_key, :params => options.dup})
  rescue => e
    resp = e.response
  end
  Response.new(resp)
end

.post(path, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/sproutvideo/resource.rb', line 10

def self.post(path, options={})
  body = MultiJson.encode(options.dup)
  begin
    resp = RestClient.post(
      "#{base_url}#{path}",
      body,
      {'SproutVideo-Api-Key' => api_key})
  rescue => e
    resp = e.response
  end
  Response.new(resp)
end

.put(path, options = {}) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/sproutvideo/resource.rb', line 62

def self.put(path, options = {})
  body = MultiJson.encode(options.dup)
  begin
    resp = RestClient.put(
      "#{base_url}#{path}",
      body,
      {'SproutVideo-Api-Key' => api_key})
  rescue => e
    resp = e.response
  end
  Response.new(resp)
end

.upload(path, file_path, options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/sproutvideo/resource.rb', line 23

def self.upload(path, file_path, options = {})
  resp = nil
  
  method = options.delete(:method) == :PUT ? :PUT : :POST

  File.open(file_path) do |file|
    
    if method == :POST
      body = {:source_video => file}.merge(options.dup)
    else
      body = {:custom_poster_frame => file}
    end

    begin
      resp = RestClient.send(
        method == :POST ? 'post' : 'put',
        "#{base_url}#{path}",
        body,
        {'SproutVideo-Api-Key' => api_key, :timeout => 18000})
    rescue => e
      puts e
      resp = e.response
    end
  end
  
  Response.new(resp)
end