Class: Swivel::Graph

Inherits:
Response show all
Defined in:
lib/swivel.rb

Instance Attribute Summary

Attributes inherited from Response

#disable_auto_refresh, #hash_doc, #refreshed_at

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Response

#[], #id, #initialize, #method_missing, #to_param, #to_s, #to_xml

Constructor Details

This class inherits a constructor from Swivel::Response

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Swivel::Response

Class Method Details

.resourceObject



514
515
516
# File 'lib/swivel.rb', line 514

def self.resource
  'graph'
end

Instance Method Details

#image_url(options = Hash.new) ⇒ Object



517
518
519
520
521
522
523
524
525
# File 'lib/swivel.rb', line 517

def image_url options = Hash.new
  host, port = @connection.config[:host], @connection.config[:port]
  port = port == 80 ? '' : ":#{port}"
  if variant == 'transient'
    "http://#{host}#{port}/graphs/get/#{digest}"
  else
    "http://#{host}#{port}/graphs/image/#{id}"
  end
end

#save!Object

Swivel::Connection#create_graph returns a transient graph that must be saved in order for it to persist at Swivel. Only persistent graphs have page urls at Swivel.

call save on a transient graph in order to do this.

# create a transient graph
transient_graph = swivel.create_graph {...}
transient_graph.variant # => 'transient'
transient_graph.id.blank? # => true

# persist the transient graph
persisted_graph = transient_graph.save
persisted_graph.variant # => 'default'
persisted_graph.id.blank? # false

# now, you can grab it from swivel whenever
g = swivel.graph persisted_graph.id
g.name == persisted_graph.name # => true


547
548
549
550
551
552
553
554
555
556
557
558
# File 'lib/swivel.rb', line 547

def save!
  return self unless variant == 'transient'
  options = {:save => 'true', :digest => self.digest}
  # PUT /graphs/0 denotes updating a transient graph.  Swivel
  # will read the digest and save the transient graph that matches
  # that digest.
  saved_graph = @connection.call '/graphs/0', options, :put
  @doc = saved_graph.instance_variable_get :@doc
  @refreshed_at = nil
  @retried = false
  self
end