Class: Cortex::Snippets::Webpage

Inherits:
Object
  • Object
show all
Defined in:
lib/cortex/snippets/webpage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cortex_client, url) ⇒ Webpage

Returns a new instance of Webpage.



6
7
8
9
10
11
# File 'lib/cortex/snippets/webpage.rb', line 6

def initialize(cortex_client, url)
  @url = url
  @response = cortex_client.webpages.get_feed(url)
  @status = @response.status
  @contents = @response.contents
end

Instance Attribute Details

#contentsObject (readonly)

Returns the value of attribute contents.



4
5
6
# File 'lib/cortex/snippets/webpage.rb', line 4

def contents
  @contents
end

#responseObject (readonly)

Returns the value of attribute response.



4
5
6
# File 'lib/cortex/snippets/webpage.rb', line 4

def response
  @response
end

#statusObject (readonly)

Returns the value of attribute status.



4
5
6
# File 'lib/cortex/snippets/webpage.rb', line 4

def status
  @status
end

#urlObject (readonly)

Returns the value of attribute url.



4
5
6
# File 'lib/cortex/snippets/webpage.rb', line 4

def url
  @url
end

Instance Method Details

#accordion_group_widget_dataObject



101
102
103
# File 'lib/cortex/snippets/webpage.rb', line 101

def accordion_group_widget_data
  JSON.parse(@contents[:accordion_group_widget_json] || 'null', quirks_mode: true)
end

#accordion_group_widget_data_for(section_name) ⇒ Object



105
106
107
# File 'lib/cortex/snippets/webpage.rb', line 105

def accordion_group_widget_data_for(section_name)
  accordion_group_widget_data&.[](section_name) || []
end

#buy_box_widget_dataObject



113
114
115
# File 'lib/cortex/snippets/webpage.rb', line 113

def buy_box_widget_data
  JSON.parse(@contents[:buy_box_widget_json] || 'null', quirks_mode: true)
end

#card_group_widget_dataObject



93
94
95
# File 'lib/cortex/snippets/webpage.rb', line 93

def card_group_widget_data
  JSON.parse(@contents[:card_group_widget_json] || 'null', quirks_mode: true)
end

#card_group_widget_data_for(section_name) ⇒ Object



97
98
99
# File 'lib/cortex/snippets/webpage.rb', line 97

def card_group_widget_data_for(section_name)
  card_group_widget_data&.[](section_name)
end

#carousels_widget_dataObject



69
70
71
# File 'lib/cortex/snippets/webpage.rb', line 69

def carousels_widget_data
  JSON.parse(@contents[:carousels_widget_json] || 'null', quirks_mode: true)
end

#carousels_widget_data_for(section_name) ⇒ Object



73
74
75
# File 'lib/cortex/snippets/webpage.rb', line 73

def carousels_widget_data_for(section_name)
  carousels_widget_data&.[](section_name)
end

#charts_widget_dataObject



109
110
111
# File 'lib/cortex/snippets/webpage.rb', line 109

def charts_widget_data
  JSON.parse(@contents[:charts_widget_json] || 'null', quirks_mode: true)
end

#charts_widget_data_for(section_name) ⇒ Object



117
118
119
# File 'lib/cortex/snippets/webpage.rb', line 117

def charts_widget_data_for(section_name)
  charts_widget_data&.[](section_name) || {}
end

#form_configsObject



125
126
127
# File 'lib/cortex/snippets/webpage.rb', line 125

def form_configs
  @form_configs ||= JSON.parse(@contents[:form_configs_json] || 'null', quirks_mode: true)
end

#galleries_widget_dataObject



77
78
79
# File 'lib/cortex/snippets/webpage.rb', line 77

def galleries_widget_data
  JSON.parse(@contents[:galleries_widget_json] || 'null', quirks_mode: true)
end

#galleries_widget_data_for(section_name) ⇒ Object



81
82
83
# File 'lib/cortex/snippets/webpage.rb', line 81

def galleries_widget_data_for(section_name)
  galleries_widget_data&.[](section_name)
end

#noarchiveObject



53
54
55
# File 'lib/cortex/snippets/webpage.rb', line 53

def noarchive
  @contents[:noarchive]
end

#nofollowObject



41
42
43
# File 'lib/cortex/snippets/webpage.rb', line 41

def nofollow
  @contents[:nofollow]
end

#noimageindexObject



57
58
59
# File 'lib/cortex/snippets/webpage.rb', line 57

def noimageindex
  @contents[:noimageindex]
end

#noindexObject



37
38
39
# File 'lib/cortex/snippets/webpage.rb', line 37

def noindex
  @contents[:noindex]
end

#noodpObject



45
46
47
# File 'lib/cortex/snippets/webpage.rb', line 45

def noodp
  @contents[:noodp]
end

#nosnippetObject



49
50
51
# File 'lib/cortex/snippets/webpage.rb', line 49

def nosnippet
  @contents[:nosnippet]
end

#product_dataObject



121
122
123
# File 'lib/cortex/snippets/webpage.rb', line 121

def product_data
  @product_data ||= JSON.parse(@contents[:product_data_json] || 'null', quirks_mode: true)
end

#seo_descriptionObject



17
18
19
# File 'lib/cortex/snippets/webpage.rb', line 17

def seo_description
  @contents[:seo_description]
end

#seo_keywordsObject



21
22
23
# File 'lib/cortex/snippets/webpage.rb', line 21

def seo_keywords
  @contents[:seo_keyword_list]
end

#seo_robotsObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cortex/snippets/webpage.rb', line 25

def seo_robots
  robot_information = []
  index_options = [:noindex, :nofollow, :noodp, :nosnippet, :noarchive, :noimageindex]

  index_options.each do |index_option|
    robot_information << index_option if @contents[index_option]
  end

  robot_information = index_options unless Rails.env.production? || Rails.env.failover?
  robot_information
end

#seo_titleObject



13
14
15
# File 'lib/cortex/snippets/webpage.rb', line 13

def seo_title
  @contents[:seo_title]
end

#slider_widget_dataObject



85
86
87
# File 'lib/cortex/snippets/webpage.rb', line 85

def slider_widget_data
  JSON.parse(@contents[:slider_widget_json] || 'null', quirks_mode: true)
end

#slider_widget_data_for(section_name) ⇒ Object



89
90
91
# File 'lib/cortex/snippets/webpage.rb', line 89

def slider_widget_data_for(section_name)
  slider_widget_data&.[](section_name)
end

#snippetsObject



129
130
131
# File 'lib/cortex/snippets/webpage.rb', line 129

def snippets
  @contents[:snippets]
end

#tables_widget_dataObject



61
62
63
# File 'lib/cortex/snippets/webpage.rb', line 61

def tables_widget_data
  JSON.parse(@contents[:tables_widget_json] || 'null', quirks_mode: true)
end

#tables_widget_data_for(section_name) ⇒ Object



65
66
67
# File 'lib/cortex/snippets/webpage.rb', line 65

def tables_widget_data_for(section_name)
  tables_widget_data&.[](section_name) || []
end