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
12
13
14
15
16
17
18
19
20
# File 'lib/remocon/command/push_command.rb', line 8

def initialize(opts)
  @opts = opts

  @project_id = ENV.fetch('FIREBASE_PROJECT_ID')
  @token = ENV.fetch('REMOTE_CONFIG_ACCESS_TOKEN')
  @uri = URI.parse("https://firebaseremoteconfig.googleapis.com/v1/projects/#{@project_id}/remoteConfig")
  @source_filepath = @opts[:source]
  @etag = File.exist?(@opts[:etag]) ? File.open(@opts[:etag]).read : @opts[:etag] if @opts[:etag]
  @ignore_etag = @opts[:force]
  @dest_dir = File.join(@opts[:dest], @project_id) if @opts[:dest]

  @cmd_opts = { validate_only: false }
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



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

def uri
  @uri
end

Instance Method Details

#clientObject



27
28
29
30
31
32
33
34
# File 'lib/remocon/command/push_command.rb', line 27

def client
  return @client if @client

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

  @client = client
end

#requestObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/remocon/command/push_command.rb', line 36

def request
  return @request if @request

  raise 'etag should be specified. If you want to ignore this error, then add --force option' unless @etag || @ignore_etag

  headers = {
    'Authorization' => "Bearer #{@token}",
    'Content-Type' => 'application/json; UTF8'
  }
  headers['If-Match'] = @etag || '*'

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

  @request = request
end

#runObject



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

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