Class: PagiiiApi::Asset

Inherits:
Object
  • Object
show all
Defined in:
lib/pagiii_api/asset.rb

Class Method Summary collapse

Class Method Details

.create(theme_id:, asset_key:, content:) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pagiii_api/asset.rb', line 4

def create(theme_id:, asset_key:, content:)
  conn = Pagiii.create_connection

  ext = File.extname(asset_key)
  if [".png", ".jpg", ".jpeg", ".gif"].include?(ext)
    data = Base64.encode64(content)
  else
    data = content
  end

  response = conn.post("/api/v1/admin/themes/#{theme_id}/assets") do |req|
    req.body = {
      key: asset_key,
      data: data
    }.to_json
  end
  Pagiii.build_response(response)
end

.list(page = 1) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/pagiii_api/asset.rb', line 23

def list(page = 1)
  conn = Pagiii.create_connection

  response = conn.get("/api/v1/admin/themes/#{theme_id}/assets") do |req|
    req.params['page'] = page
  end

  Pagiii.build_response(response)
end