Class: Compete
Constant Summary collapse
- VALID_SIZES =
Valid size arguments for the for_domain call
['small', 'large']
- API_URL =
'http://api.compete.com/fast-cgi/MI'
- API_VERSION =
3
Instance Attribute Summary collapse
-
#domain ⇒ Object
readonly
other readers.
-
#metrics_count ⇒ Object
readonly
readers for metric data.
-
#metrics_date_range ⇒ Object
readonly
readers for metric data.
-
#metrics_icon ⇒ Object
readonly
readers for metric data.
-
#metrics_link ⇒ Object
readonly
readers for metric data.
-
#metrics_ranking ⇒ Object
readonly
readers for metric data.
-
#trust_level_icon ⇒ Object
readonly
readers for trust data.
-
#trust_level_link ⇒ Object
readonly
readers for trust data.
-
#trust_level_value ⇒ Object
readonly
readers for trust data.
-
#xml ⇒ Object
readonly
other readers.
Class Method Summary collapse
-
.for_domain(domain, size = 'small') ⇒ Object
Lookup the compete info for a domain.
Instance Method Summary collapse
-
#data_available? ⇒ Boolean
Is data available for this domain? If this method returns true.
-
#initialize(xml) ⇒ Compete
constructor
Creates a new Compete Object from the XML response of the compete API (as parsed by httparty).
Constructor Details
#initialize(xml) ⇒ Compete
Creates a new Compete Object from the XML response of the compete API (as parsed by httparty). Details see developer.compete.com/
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/compete.rb', line 21 def initialize(xml) @xml = xml @domain = @xml['ci']['dmn']['nm'] # metrics @metrics_ranking = to_integer(@xml['ci']['dmn']['metrics']['val']['uv']['ranking']) if data_available? @metrics_date_range = build_metrics_date_range() end # metrics @metrics_count = to_integer(@xml['ci']['dmn']['metrics']['val']['uv']['count']) @metrics_link = @xml['ci']['dmn']['metrics']['link'] @metrics_icon = @xml['ci']['dmn']['metrics']['icon'] # trust @trust_level_value = @xml['ci']['dmn']['trust']['val'] @trust_level_link = @xml['ci']['dmn']['trust']['link'] @trust_level_icon = @xml['ci']['dmn']['trust']['icon'] end |
Instance Attribute Details
#domain ⇒ Object (readonly)
other readers
15 16 17 |
# File 'lib/compete.rb', line 15 def domain @domain end |
#metrics_count ⇒ Object (readonly)
readers for metric data
13 14 15 |
# File 'lib/compete.rb', line 13 def metrics_count @metrics_count end |
#metrics_date_range ⇒ Object (readonly)
readers for metric data
13 14 15 |
# File 'lib/compete.rb', line 13 def metrics_date_range @metrics_date_range end |
#metrics_icon ⇒ Object (readonly)
readers for metric data
13 14 15 |
# File 'lib/compete.rb', line 13 def metrics_icon @metrics_icon end |
#metrics_link ⇒ Object (readonly)
readers for metric data
13 14 15 |
# File 'lib/compete.rb', line 13 def metrics_link @metrics_link end |
#metrics_ranking ⇒ Object (readonly)
readers for metric data
13 14 15 |
# File 'lib/compete.rb', line 13 def metrics_ranking @metrics_ranking end |
#trust_level_icon ⇒ Object (readonly)
readers for trust data
11 12 13 |
# File 'lib/compete.rb', line 11 def trust_level_icon @trust_level_icon end |
#trust_level_link ⇒ Object (readonly)
readers for trust data
11 12 13 |
# File 'lib/compete.rb', line 11 def trust_level_link @trust_level_link end |
#trust_level_value ⇒ Object (readonly)
readers for trust data
11 12 13 |
# File 'lib/compete.rb', line 11 def trust_level_value @trust_level_value end |
#xml ⇒ Object (readonly)
other readers
15 16 17 |
# File 'lib/compete.rb', line 15 def xml @xml end |
Class Method Details
.for_domain(domain, size = 'small') ⇒ Object
Lookup the compete info for a domain. the size argument is for the icon urls. VALID_SIZES specifies what you can give here. Make sure COMPETE_API_KEY is set before you call this method.
46 47 48 49 50 51 |
# File 'lib/compete.rb', line 46 def self.for_domain(domain, size = 'small') raise 'COMPETE_API_KEY is not defined' unless defined?(COMPETE_API_KEY) raise "Unknown size '#{size}'" unless VALID_SIZES.include?(size) info = get(API_URL, :query => {:d => domain, :ver => API_VERSION, :apikey => COMPETE_API_KEY, :size => size}) Compete.new(info) end |
Instance Method Details
#data_available? ⇒ Boolean
Is data available for this domain? If this method returns true
55 56 57 |
# File 'lib/compete.rb', line 55 def data_available? !!self.metrics_ranking end |