Sha256: 2f441afb4e83c61bea367fa07b1965340c5d59313625e1b4ddb6e1cb22421a0e

Contents?: true

Size: 1.71 KB

Versions: 113

Compression:

Stored size: 1.71 KB

Contents

class Wco::Site
  include Mongoid::Document
  include Mongoid::Timestamps
  include Mongoid::Paranoia
  store_in collection: 'wco_sites'

  KIND_DRUPAL = 'drupal'
  KIND_IG     = 'instagram'
  KIND_WP     = 'wordpress'
  KINDS       = %w| drupal instagram wordpress |
  field :kind, type: :string
  def self.kinds_list
    [nil] + KINDS
  end

  has_many :publishers # , class_name: 'Wco::Publisher'
  has_many :headlines # , class_name: 'Wco::Newstitle'

  field :slug
  validates :slug, presence: true, uniqueness: true

  field :origin # http://pi.local
  validates :origin, presence: true, uniqueness: true

  field :post_path # /node?_format=hal_json
  field :username
  field :password

  def to_s
    origin
  end

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

  def body
    {
      "_links": {
        "type":{"href":"http://pi.local/rest/type/node/article"}
      },
      "title":[{"value":"Node +++ 123 bac +++" }],
      "body":[{"value": "<b>hello, wor</b>ld!", "format": "full_html" }],
      "type":[{"target_id":"article"}],
      "status": [{"value": 1}],
      "_embedded": {
        "http://pi.local/rest/relation/node/article/field_issue": [
          { "uuid": [{ "value": "56229a95-d675-43e1-99b1-f9e11b5579c5" }] }
        ],
        "http://pi.local/rest/relation/node/article/field_tags": [
          { "uuid": [{ "value": "45646a7d-1a16-42e8-b758-f6e1c8d976f7" }] },
          { "uuid": [{ "value": "834e34e2-05ae-498d-b876-453798872ce1" }] }
        ]
      }

    }
  end

  def do_post
    HTTParty.post( post_url,
      body: JSON.generate( body ),
      headers: { 'Content-Type' => 'application/hal+json' },
      basic_auth: { username: username, password: password },
    )
  end

end

Version data entries

113 entries across 113 versions & 1 rubygems

Version Path
wco_models-3.1.0.152 app/models/wco/site.rb
wco_models-3.1.0.151 app/models/wco/site.rb
wco_models-3.1.0.150 app/models/wco/site.rb
wco_models-3.1.0.149 app/models/wco/site.rb
wco_models-3.1.0.148 app/models/wco/site.rb
wco_models-3.1.0.147 app/models/wco/site.rb
wco_models-3.1.0.146 app/models/wco/site.rb
wco_models-3.1.0.145 app/models/wco/site.rb
wco_models-3.1.0.144 app/models/wco/site.rb
wco_models-3.1.0.143 app/models/wco/site.rb
wco_models-3.1.0.142 app/models/wco/site.rb
wco_models-3.1.0.141 app/models/wco/site.rb
wco_models-3.1.0.140 app/models/wco/site.rb
wco_models-3.1.0.139 app/models/wco/site.rb
wco_models-3.1.0.138 app/models/wco/site.rb
wco_models-3.1.0.137 app/models/wco/site.rb
wco_models-3.1.0.136 app/models/wco/site.rb
wco_models-3.1.0.135 app/models/wco/site.rb
wco_models-3.1.0.134 app/models/wco/site.rb
wco_models-3.1.0.133 app/models/wco/site.rb