class SKP::Gateway

Attributes

domain[RW]

Public Class Methods

new(domain, key) click to toggle source
# File lib/skp/gateway.rb, line 8
def initialize(domain, key)
  @domain = domain
  @key = key
end

Public Instance Methods

authenticate_key(key) click to toggle source
# File lib/skp/gateway.rb, line 15
def authenticate_key(key)
  Excon.get(domain + "/license", user: key).status == 200
end
download_content(content, folder:) click to toggle source
# File lib/skp/gateway.rb, line 29
def download_content(content, folder:)
  ::CLI::UI::Progress.progress do |bar|
    downloaded_file = File.open("#{folder}/#{content["s3_key"]}.partial", "w")
    streamer = lambda do |chunk, remaining_bytes, total_bytes|
      downloaded_file.write(chunk)
      bar.tick(set_percent: 1 - (remaining_bytes.to_f / total_bytes).round(2))
    end
    response = Excon.get(content["url"], response_block: streamer)
    unless response.status == 200
      puts response.inspect
      raise Error.new("Server problem: #{response.status}")
    end
    downloaded_file.close
    File.rename(downloaded_file, "#{folder}/#{content["s3_key"]}")
    bar.tick(set_percent: 1)
  end
end
latest_version?() click to toggle source
# File lib/skp/gateway.rb, line 47
def latest_version?
  resp = Excon.get("https://rubygems.org/api/v1/gems/skp.json")
  data = JSON.parse resp.body
  Gem::Version.new(SKP::VERSION) >= Gem::Version.new(data["version"])
end
list_content() click to toggle source
# File lib/skp/gateway.rb, line 19
def list_content
  response = Excon.get(domain + "/contents?product=sip", user: @key)
  if response.status == 200
    JSON.parse(response.body)
  else
    puts response.inspect
    raise Error, "There was a problem fetching this content."
  end
end
register_email(email) click to toggle source
# File lib/skp/gateway.rb, line 53
def register_email(email)
  Excon.put(domain + "/license?email=#{email}&key=#{@key}").status == 200
end