Class: Purdie::Services::Vimeo

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Purdie::Service

#configure, included, #initialize

Class Method Details

.headersObject



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

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

.hostObject



49
50
51
# File 'lib/purdie/services/vimeo.rb', line 49

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

.matcherObject



45
46
47
# File 'lib/purdie/services/vimeo.rb', line 45

def self.matcher
  'vimeo.com'
end

.resolve(url) ⇒ Object



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

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



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

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



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

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'] == 'You must provide a valid authenticated access token.'
    raise CredentialsException.new self, 'missing and/or duff'
  else
    response
  end
end