class Zapnito::Cli::Services::Zapnito

Public Class Methods

new(api_token, basepath) click to toggle source
# File lib/zapnito/cli/services/zapnito.rb, line 5
def initialize(api_token, basepath)
  @api_token = api_token
  @basepath = basepath
end

Public Instance Methods

build_release(theme) click to toggle source
# File lib/zapnito/cli/services/zapnito.rb, line 19
def build_release(theme)
  put_json("/themes/#{theme.tenant_slug}/releases/#{theme.revision}")
end
s3_upload_urls_for_theme(theme) click to toggle source
# File lib/zapnito/cli/services/zapnito.rb, line 15
def s3_upload_urls_for_theme(theme)
  post_json("/themes/#{theme.tenant_slug}/uploads", build_payload(theme))
end
tenant_slugs() click to toggle source
# File lib/zapnito/cli/services/zapnito.rb, line 10
def tenant_slugs
  tenants = get_json("/theme_tenants.json")["tenants"]
  tenants.map { |t| t["slug"] }.sort
end

Private Instance Methods

authorization_header() click to toggle source
# File lib/zapnito/cli/services/zapnito.rb, line 71
def authorization_header
  "Token token=\"#{@api_token}\""
end
build_payload(theme) click to toggle source
# File lib/zapnito/cli/services/zapnito.rb, line 29
def build_payload(theme)
  JSON.dump({
    revision: theme.revision,
    resources: theme.files.each_with_object({}) do |theme_file, resources|
      resources[theme_file] = { "contentType" => theme.mime_type_for(theme_file) }
    end
  })
end
get_json(path) click to toggle source
# File lib/zapnito/cli/services/zapnito.rb, line 48
def get_json(path)
  response = RestClient.get(
    url(path),
    content_type: :json,
    accept: :json,
    "AUTHORIZATION" => authorization_header
  )

  JSON.parse(response)
end
post_json(path, payload) click to toggle source
# File lib/zapnito/cli/services/zapnito.rb, line 59
def post_json(path, payload)
  response = RestClient.post(
    url(path),
    payload,
    content_type: :json,
    accept: :json,
    "AUTHORIZATION" => authorization_header
  )

  JSON.parse(response)
end
put_json(path) click to toggle source
# File lib/zapnito/cli/services/zapnito.rb, line 38
def put_json(path)
  RestClient.put(
    url(path),
    nil,
    content_type: :json,
    accept: :json,
    "AUTHORIZATION" => authorization_header
  )
end
url(path) click to toggle source
# File lib/zapnito/cli/services/zapnito.rb, line 75
def url(path)
  "#{@basepath}#{path}"
end