Class: Compete

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/compete.rb

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

Class Method Summary collapse

Instance Method Summary collapse

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

#domainObject (readonly)

other readers



15
16
17
# File 'lib/compete.rb', line 15

def domain
  @domain
end

#metrics_countObject (readonly)

readers for metric data



13
14
15
# File 'lib/compete.rb', line 13

def metrics_count
  @metrics_count
end

#metrics_date_rangeObject (readonly)

readers for metric data



13
14
15
# File 'lib/compete.rb', line 13

def metrics_date_range
  @metrics_date_range
end

#metrics_iconObject (readonly)

readers for metric data



13
14
15
# File 'lib/compete.rb', line 13

def metrics_icon
  @metrics_icon
end

readers for metric data



13
14
15
# File 'lib/compete.rb', line 13

def metrics_link
  @metrics_link
end

#metrics_rankingObject (readonly)

readers for metric data



13
14
15
# File 'lib/compete.rb', line 13

def metrics_ranking
  @metrics_ranking
end

#trust_level_iconObject (readonly)

readers for trust data



11
12
13
# File 'lib/compete.rb', line 11

def trust_level_icon
  @trust_level_icon
end

readers for trust data



11
12
13
# File 'lib/compete.rb', line 11

def trust_level_link
  @trust_level_link
end

#trust_level_valueObject (readonly)

readers for trust data



11
12
13
# File 'lib/compete.rb', line 11

def trust_level_value
  @trust_level_value
end

#xmlObject (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

Returns:

  • (Boolean)


55
56
57
# File 'lib/compete.rb', line 55

def data_available?
  !!self.metrics_ranking
end