Class: OwenWows::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/owen_wows/client.rb

Overview

Class for handling the API connection to the Owen Wilson Random Wow API

Constant Summary collapse

BASE_URL =
"https://owen-wilson-wow-api.herokuapp.com/wows/"
CURRENT_MOVIE_COUNT =
91

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter: Faraday.default_adapter) ⇒ Client

Returns a new instance of Client.



13
14
15
# File 'lib/owen_wows/client.rb', line 13

def initialize(adapter: Faraday.default_adapter)
  @adapter = adapter
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



11
12
13
# File 'lib/owen_wows/client.rb', line 11

def adapter
  @adapter
end

Instance Method Details

#all_directorsObject



63
64
65
# File 'lib/owen_wows/client.rb', line 63

def all_directors
  connection.get("directors").body
end

#all_moviesObject



59
60
61
# File 'lib/owen_wows/client.rb', line 59

def all_movies
  connection.get("movies").body
end

#connectionObject



17
18
19
20
21
22
23
24
# File 'lib/owen_wows/client.rb', line 17

def connection
  @connection ||= Faraday.new do |conn|
    conn.url_prefix = BASE_URL
    conn.request :json
    conn.response :json, content_type: "application/json"
    conn.adapter adapter
  end
end

#from_year(year, results: CURRENT_MOVIE_COUNT) ⇒ Object



41
42
43
44
# File 'lib/owen_wows/client.rb', line 41

def from_year(year, results: CURRENT_MOVIE_COUNT)
  wows = search(year: year, results: results)
  build_list(wows)
end

#in_movie(movie, exact: true, results: CURRENT_MOVIE_COUNT) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/owen_wows/client.rb', line 46

def in_movie(movie, exact: true, results: CURRENT_MOVIE_COUNT)
  wows = search(movie: movie, results: results)
  all = build_list(wows)
  return all unless exact

  all.select { |wow| wow["movie"] == movie }
end

#list(results: CURRENT_MOVIE_COUNT) ⇒ Object



26
27
28
29
# File 'lib/owen_wows/client.rb', line 26

def list(results: CURRENT_MOVIE_COUNT)
  wows = search(results: results)
  build_list(wows)
end

#random_wowObject



31
32
33
34
# File 'lib/owen_wows/client.rb', line 31

def random_wow
  wow = search
  build_list(wow)
end

#search(**kwargs) ⇒ Object



54
55
56
57
# File 'lib/owen_wows/client.rb', line 54

def search(**kwargs)
  wows = connection.get("random", **kwargs).body
  build_list(wows)
end

#with_director(director, results: CURRENT_MOVIE_COUNT) ⇒ Object



36
37
38
39
# File 'lib/owen_wows/client.rb', line 36

def with_director(director, results: CURRENT_MOVIE_COUNT)
  wows = search(director: director, results: results)
  build_list(wows)
end