Module: Percy::Client::Snapshots

Included in:
Percy::Client
Defined in:
lib/percy/client/snapshots.rb

Instance Method Summary collapse

Instance Method Details

#create_snapshot(build_id, resources, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/percy/client/snapshots.rb', line 4

def create_snapshot(build_id, resources, options = {})
  if !resources.respond_to?(:each)
    raise ArgumentError.new(
      'resources argument must be an iterable of Percy::Client::Resource objects')
  end

  widths = options[:widths] || config.default_widths
  data = {
    'data' => {
      'type' => 'snapshots',
      'attributes' => {
        'name' => options[:name],
        'enable-javascript' => options[:enable_javascript],
        'widths' => widths,
      },
      'relationships' => {
        'resources' => {
          'data' => resources.map { |r| r.serialize },
        },
      },
    },
  }
  post("#{config.api_url}/builds/#{build_id}/snapshots/", data)
end

#finalize_snapshot(snapshot_id) ⇒ Object



29
30
31
# File 'lib/percy/client/snapshots.rb', line 29

def finalize_snapshot(snapshot_id)
  post("#{config.api_url}/snapshots/#{snapshot_id}/finalize", {})
end