Class: Sibling::Instruction

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/sibling/instruction.rb

Class Method Summary collapse

Class Method Details

.async_consume_feedObject



31
32
33
# File 'app/models/sibling/instruction.rb', line 31

def async_consume_feed
  Resque.enqueue(SiblingInstructionConsumer)
end

.consume_feedObject



23
24
25
26
27
28
29
# File 'app/models/sibling/instruction.rb', line 23

def consume_feed
  feed.entries.map do |hentry|
    find_or_create_from_hentry(hentry) if targets_me?(hentry)
  end.compact
rescue OpenURI::HTTPError => e
  raise e unless /304 Not Modified/ =~ e.message
end

.feedObject



19
20
21
# File 'app/models/sibling/instruction.rb', line 19

def feed
  Microformats2.parse(feed_url)
end

.feed_urlObject



15
16
17
# File 'app/models/sibling/instruction.rb', line 15

def feed_url
  ENV["G5_CONFIGURATOR_FEED_URL"]
end

.find_or_create_from_hentry(hentry) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'app/models/sibling/instruction.rb', line 44

def find_or_create_from_hentry(hentry)
  find_or_create_by(uid: hentry.uid.to_s) do |instruction|
    hcard = instruction(hentry)
    instruction.name = hcard.name.to_s
    instruction.published_at = hentry.updated.value
    if hentry.try(:g5_updated_app_kinds).present?
      instruction.updated_app_kinds = hentry.g5_updated_app_kinds.map(&:to_s)
    end
  end
end

.instruction(hentry) ⇒ Object



40
41
42
# File 'app/models/sibling/instruction.rb', line 40

def instruction(hentry)
  Microformats2.parse(hentry.content.to_s).card
end

.targets_me?(hentry) ⇒ Boolean



35
36
37
38
# File 'app/models/sibling/instruction.rb', line 35

def targets_me?(hentry)
  targets = instruction(hentry).g5_targets.map { |t| t.format.uid.to_s }
  targets && targets.include?(Sibling.main_app_uid)
end