Class: CMSBinding::CMSSource

Inherits:
Object
  • Object
show all
Defined in:
lib/twm-cms-bindings.rb

Constant Summary collapse

CMS_AP =
"/cms"

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ CMSSource



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/twm-cms-bindings.rb', line 128

def initialize(config)
  if config[:site].nil?
    raise ArgumentError, ":site required"
  else
    @site = config[:site]
  end

  @server = config[:server] || 'cms.hostingoperationscentre.com'
  @port = config[:port] || '80'

  if config[:cache].nil?
    @cache_server = config[:cache_server] || nil
    unless @cache_server.nil?
      @mcache = MemCache.new(@cache_server)
      @cache_timeout = config[:cache_timeout] || 3600
    end
  else
    @mcache = config[:cache]
    @cache_timeout = config[:cache_timeout] || 3600
  end
end

Instance Method Details

#article(id) ⇒ Object



157
158
159
160
161
162
# File 'lib/twm-cms-bindings.rb', line 157

def article(id)
  xml = get_response( "#{base_url}xml/article/id/#{id}/full" )
  document = REXML::Document.new(xml)
  first_article = REXML::XPath.first( document, "articles/article")
  CMSBinding::Article.new(first_article, self, false)
end

#article_attachment_link(attachment) ⇒ Object



171
172
173
174
175
176
177
178
179
# File 'lib/twm-cms-bindings.rb', line 171

def article_attachment_link(attachment)
  if attachment.kind_of? CMSBinding::ArticleAttachment
    attachment_id = attachment.id
  else
    attachment_id = attachment.to_str
  end
  
  "#{base_url}binary/article/attachment/#{attachment_id}/normal"
end

#category(id) ⇒ Object



150
151
152
153
154
155
# File 'lib/twm-cms-bindings.rb', line 150

def category(id)
  xml = get_response( "#{base_url}xml/category/id/#{id}" )
  document = REXML::Document.new(xml);
  category = REXML::XPath.first( document, '/category' )
  CMSBinding::Category.new(category, self, false)
end

#queue(queue_name, queue_type) ⇒ Object



164
165
166
167
168
169
# File 'lib/twm-cms-bindings.rb', line 164

def queue(queue_name, queue_type)
  xml = get_response( "#{base_url}xml/article/#{queue_type}/#{queue_name}/all/full")
  document = REXML::Document.new(xml)
  articles = REXML::XPath.first( document, "articles")
  CMSBinding::Queue.new(articles, self, queue_name, queue_type)
end