Class: Purdie::Services::Vimeo

Inherits:
Object
  • Object
show all
Includes:
Ingester
Defined in:
lib/purdie/services/vimeo.rb

Instance Attribute Summary

Attributes included from Ingester

#config, #matcher, #subconfig

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Ingester

#[], #configure, #each, included, #ingest, #initialize, #to_yaml, #write

Class Method Details

.headersObject



32
33
34
35
36
37
# File 'lib/purdie/services/vimeo.rb', line 32

def self.headers
  {
    'Authorization' => "bearer #{ENV['VIMEO_BEARER_TOKEN']}",
    'Accept' => 'application/json'
  }
end

.hostObject



51
52
53
# File 'lib/purdie/services/vimeo.rb', line 51

def self.host
  'https://api.vimeo.com'
end

.matcherObject



47
48
49
# File 'lib/purdie/services/vimeo.rb', line 47

def self.matcher
  'vimeo.com'
end

.resolve(url) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/purdie/services/vimeo.rb', line 39

def self.resolve url
  return [url] unless url =~ /\/albums?\//

  target = "#{Vimeo.host}/albums/#{Purdie.get_id url}/videos/"
  set = JSON.parse (HTTParty.get target, headers: Vimeo.headers).body
  set['data'].map { |video| video['uri'].sub '/videos', 'https://vimeo.com' }
end

Instance Method Details

#distill(url) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/purdie/services/vimeo.rb', line 20

def distill url
  video = get url

  results = {}
  results['title'] = video['name']
  results['id'] = @id

  results.attach_license self, video['license']

  results
end

#get(url) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/purdie/services/vimeo.rb', line 8

def get url
  @id = Purdie.get_id url
  target = "#{Vimeo.host}/videos/#{@id}"
  response = HTTParty.get target, headers: Vimeo.headers
  response = JSON.parse response.body
  if response['error'] == 'A valid user token must be passed.'
    raise CredentialsException.new self, 'missing and/or duff'
  else
    response
  end
end