Class: Assonnato::Show

Inherits:
Object
  • Object
show all
Includes:
Parser
Defined in:
lib/assonnato/api/show.rb

Instance Method Summary collapse

Methods included from Parser

#parse

Constructor Details

#initialize(client) ⇒ Show

Returns a new instance of Show.



13
14
15
# File 'lib/assonnato/api/show.rb', line 13

def initialize(client)
  @client = client
end

Instance Method Details

#all(status = :ongoing, options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/assonnato/api/show.rb', line 17

def all(status = :ongoing, options = {})
  filters = ''.tap { |str|
    if options.has_key? :fansub
      str << by_fansub(options[:fansub])
    elsif options.has_key? :user
      if options.has_key?  :role
        str << by_role(options[:user], options[:role])
      else
        str << by_staff(options[:user])
      end
    end
  }

  parse @client.get("/api/v1/#{filters}/shows/all/#{status}")
end

#edit(name, episode, fields) ⇒ Object



45
46
47
48
49
50
# File 'lib/assonnato/api/show.rb', line 45

def edit(name, episode, fields)
  path = '/api/v1/episode/edit'
  data = { name: name, episode: episode, _csrf: @client.user.csrf_token }.merge fields

  @client.post path, data
end

#get(show_name) ⇒ Object



33
34
35
# File 'lib/assonnato/api/show.rb', line 33

def get(show_name)
  search(show_name).select { |show| show.name == show_name }
end

#last!(status) ⇒ Object

Raises:

  • (NotImplementedError)


37
38
39
# File 'lib/assonnato/api/show.rb', line 37

def last!(status)
  raise NotImplementedError, 'Show#last is not implemented'
end

#search(keyword) ⇒ Object



41
42
43
# File 'lib/assonnato/api/show.rb', line 41

def search(keyword)
  parse @client.get("/api/v1/shows/search/#{URI.escape keyword}")
end