Class: Remocon::Command::Push

Inherits:
Object
  • Object
show all
Defined in:
lib/remocon/command/push_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Push

Returns a new instance of Push.



8
9
10
11
# File 'lib/remocon/command/push_command.rb', line 8

def initialize(opts)
  @config = Remocon::Config.new(opts)
  @cmd_opts = { validate_only: false }
end

Instance Attribute Details

#cmd_optsObject (readonly)

Returns the value of attribute cmd_opts.



6
7
8
# File 'lib/remocon/command/push_command.rb', line 6

def cmd_opts
  @cmd_opts
end

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/remocon/command/push_command.rb', line 6

def config
  @config
end

Instance Method Details

#clientObject



18
19
20
21
22
23
24
25
# File 'lib/remocon/command/push_command.rb', line 18

def client
  return @client if @client

  client = Net::HTTP.new(uri.host, uri.port)
  client.use_ssl = true

  @client = client
end

#requestObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/remocon/command/push_command.rb', line 27

def request
  return @request if @request

  raise "etag should be specified. If you want to ignore this error, then add --force option" unless config.etag

  headers = {
    "Authorization" => "Bearer #{config.token}",
    "Content-Type" => "application/json; UTF8",
    "If-Match" => config.etag,
  }

  request = Net::HTTP::Put.new(uri.request_uri, headers)
  request.body = ""
  request.body << File.read(config.config_json_file_path).delete("\r\n")

  @request = request
end

#runObject



13
14
15
16
# File 'lib/remocon/command/push_command.rb', line 13

def run
  # to prevent a real request in spec
  do_request
end