Class: Movlog::OmdbApi

Inherits:
Object
  • Object
show all
Defined in:
lib/movlog/omdb_api.rb

Overview

Service for all OMDB API calls

Constant Summary collapse

OMDB_URL =
'http://www.omdbapi.com/'

Class Method Summary collapse

Class Method Details

.location(movie_id) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/movlog/omdb_api.rb', line 42

def self.location(movie_id)
  location_arr = []
  doc = Nokogiri::HTML(open(location_url(movie_id)))
  doc.search('//div[@class="soda sodavote odd"]/dt/a').each { |link| location_arr << link.content.gsub(/\n/, '') }
  doc.search('//div[@class="soda sodavote even"]/dt/a').each { |link| location_arr <<  link.content.gsub(/\n/, '') }
  JSON.parse(location_arr.to_json)
end

.location_url(imdb_id) ⇒ Object



52
53
54
# File 'lib/movlog/omdb_api.rb', line 52

def self.location_url(imdb_id)
   "http://www.imdb.com/title/#{imdb_id}/locations?ref_=tt_dt_dt"
end

.movie_info(t) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/movlog/omdb_api.rb', line 16

def self.movie_info(t)
  movie_response = HTTP.get(
    OMDB_URL,
    params: {
      t: t,
      y: '',
      plot: 'short',
      type: 'movie',
      r: 'json'
    }
  )
  JSON.parse(movie_response.to_s)
end

.search_movie(s) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/movlog/omdb_api.rb', line 30

def self.search_movie(s)
  movie_response = HTTP.get(
    OMDB_URL,
    params: {
      s: s,
      type: 'movie',
      r: 'json'
    }
  )
  JSON.parse(movie_response.to_s)
end