Class: APDM::DesignElements::API
- Inherits:
-
Object
- Object
- APDM::DesignElements::API
- Defined in:
- lib/apdm/design_elements/api.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #fetch_css ⇒ Object
- #fetch_css_files ⇒ Object
- #fetch_html(element) ⇒ Object
- #fetch_site_stat(category) ⇒ Object
-
#initialize(url, options = {}) ⇒ API
constructor
A new instance of API.
Constructor Details
#initialize(url, options = {}) ⇒ API
Returns a new instance of API.
9 10 11 12 13 |
# File 'lib/apdm/design_elements/api.rb', line 9 def initialize(url, = {}) @url = url @api_key = [:api_key] @version = DesignElements::VERSION end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
8 9 10 |
# File 'lib/apdm/design_elements/api.rb', line 8 def api_key @api_key end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
8 9 10 |
# File 'lib/apdm/design_elements/api.rb', line 8 def url @url end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
8 9 10 |
# File 'lib/apdm/design_elements/api.rb', line 8 def version @version end |
Instance Method Details
#fetch_css ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/apdm/design_elements/api.rb', line 25 def fetch_css css = '' fetch_css_files.each do |href| css << resolve_css(href) if include_css?(href) end css.force_encoding(Encoding::UTF_8) end |
#fetch_css_files ⇒ Object
20 21 22 23 |
# File 'lib/apdm/design_elements/api.rb', line 20 def fetch_css_files path = '//head/link[@rel = "stylesheet"]/@href' Nokogiri::HTML(fetch_html("head")).xpath(path).map(&:to_s) end |
#fetch_html(element) ⇒ Object
15 16 17 18 |
# File 'lib/apdm/design_elements/api.rb', line 15 def fetch_html(element) html = Curl::Easy.http_get(endpoint(element)).body_str valid_fragment?(html) ? html.force_encoding(Encoding::UTF_8) : nil end |
#fetch_site_stat(category) ⇒ Object
33 34 35 |
# File 'lib/apdm/design_elements/api.rb', line 33 def fetch_site_stat(category) fetch_html("traffic&counterName=#{category}").force_encoding(Encoding::UTF_8) end |