Class: Wco::Publisher

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Paranoia, Mongoid::Timestamps
Defined in:
app/models/wco/publisher.rb

Constant Summary collapse

KIND_ARTICLE =
'article'
KIND_IMAGE =
'image'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#propsObject

Returns the value of attribute props.



24
25
26
# File 'app/models/wco/publisher.rb', line 24

def props
  @props
end

Class Method Details

.listObject



66
67
68
# File 'app/models/wco/publisher.rb', line 66

def self.list
  [[nil,nil]] + all.map { |p| [p, p.id] }
end

Instance Method Details

#do_runObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/wco/publisher.rb', line 26

def do_run
  @site    = site
  @headers = {}
  @ctx     = OpenStruct.new

  puts! context_eval, 'context_eval'
  eval( context_eval )
  puts! @ctx, '@ctx'

  tmpl = ERB.new post_body_tmpl
  body = JSON.parse tmpl.result(binding)
  puts! body, 'body'

  out = Wco::HTTParty.post( "#{@site.origin}#{post_path}", {
    body: body.to_json,
    headers: @headers,
    basic_auth: { username: @site.username, password: @site.password },
  })
  puts! out.response, 'publisher httparty response'
  puts! out.body,     'publisher httparty body'
  if out.code != 201
    puts! out.body, "publisher#do_run non-201 status"
    ::ExceptionNotifier.notify_exception(
      Exception.new,
      data: {
        httparty_body: out.body,
        httparty: out,
        label: "publisher#do_run non-201 status",
      } )
    raise out.body
  end

  eval( after_eval ) if after_eval.present?
end

#to_sObject



62
63
64
# File 'app/models/wco/publisher.rb', line 62

def to_s
  "#{slug}: #{kind} => #{site}"
end