Module: Sanity::Http::Publication

Included in:
Publish, Unpublish
Defined in:
lib/sanity/http/publication.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



23
24
25
# File 'lib/sanity/http/publication.rb', line 23

def args
  @args
end

Class Method Details

.included(base) ⇒ Object



10
11
12
13
14
# File 'lib/sanity/http/publication.rb', line 10

def included(base)
  base.extend(ClassMethods)
  base.extend(Forwardable)
  base.delegate(%i[project_id dataset token] => :"Sanity.config")
end

Instance Method Details

#body_keyObject



32
33
34
# File 'lib/sanity/http/publication.rb', line 32

def body_key
  "documentId"
end

#callObject



36
37
38
39
40
# File 'lib/sanity/http/publication.rb', line 36

def call
  Net::HTTP.post(uri, body.to_json, headers).then do |result|
    block_given? ? yield(result) : result
  end
end

#initialize(args) ⇒ Object



25
26
27
28
29
30
# File 'lib/sanity/http/publication.rb', line 25

def initialize(args)
  unless args.is_a?(String) || args.is_a?(Array)
    raise ArgumentError, "args must be a string or an array"
  end
  @args = Array.wrap(args)
end

#publication_pathObject



42
43
44
# File 'lib/sanity/http/publication.rb', line 42

def publication_path
  self.class.name.demodulize.underscore.camelize_lower
end