Class: RokuBuilder::RokuAPI

Inherits:
Util
  • Object
show all
Extended by:
Plugin
Defined in:
lib/roku_builder/plugins/rokuapi.rb

Overview

Load/Unload/Build roku applications

Constant Summary collapse

HOST =
"https://apipub.roku.com"

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Plugin

commands, dependencies, parse_options, validate

Methods inherited from Util

#initialize

Constructor Details

This class inherits a constructor from RokuBuilder::Util

Class Method Details

.commandsObject



14
15
16
17
18
19
# File 'lib/roku_builder/plugins/rokuapi.rb', line 14

def self.commands
  {
    submit: {source: false},
    publish: {}
  }
end

.dependenciesObject



41
42
43
# File 'lib/roku_builder/plugins/rokuapi.rb', line 41

def self.dependencies
  []
end

.parse_options(parser:, options:) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/roku_builder/plugins/rokuapi.rb', line 21

def self.parse_options(parser:, options:)
  parser.separator "Commands:"
  parser.on("--submit", 'Submit a package to the Roku Portal') do
    options[:submit] = true
  end
  parser.on("--publish", 'Publish an app on the Roku Portal') do
    options[:publish] = true
  end
  parser.separator "Options:"
  parser.on("--channel-id ID", 'ID of the channel to submit to/publish') do |id|
    options[:channel_id] = id
  end
  parser.on("--api-key KEY", 'The API key to use to submit/publish') do |key|
    options[:api_key] = key
  end
  parser.on("--no-publish", 'Prevent the channel from being automatically published when submitted') do
    options[:no_publish] = true
  end 
end

Instance Method Details

#initObject



11
12
# File 'lib/roku_builder/plugins/rokuapi.rb', line 11

def init
end

#publish(options:) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/roku_builder/plugins/rokuapi.rb', line 60

def publish(options:)
  raise RokuBuilder::InvalidOptions, "Missing channel id" unless options[:channel_id]
  @logger.info "Publish to channel #{options[:channel_id]}"
  @api_key = options[:api_key]
  response = get_channel_versions(options[:channel_id])
  raise RokuBuilder::ExecutionError unless response.first["channelState"] == "Unpublished"
  response = publish_channel_version(options[:channel_id], response.first["id"])
  raise RokuBuilder::ExecutionError, "Request failed: #{response.reason_phrase}" unless response.success?
  JSON.parse(response.body)
end

#submit(options:) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/roku_builder/plugins/rokuapi.rb', line 45

def submit(options:)
  raise RokuBuilder::InvalidOptions, "Missing channel id" unless options[:channel_id]
  @logger.info "Submit to channel #{options[:channel_id]}"
  @api_key = options[:api_key]
  @no_publish = !!options[:no_publish]
  response = get_channel_versions(options[:channel_id])
  if response.first["channelState"] == "Unpublished"
    response = update_channel_version(options[:channel_id], get_package(options), response.last["id"])
  else
    response = create_channel_version(options[:channel_id], get_package(options))
  end
  raise RokuBuilder::ExecutionError, "Request failed: #{response.reason_phrase}" unless response.success?
  JSON.parse(response.body)
end