Class: Hci::Hit

Inherits:
Object
  • Object
show all
Defined in:
lib/hci/hit.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.hitsObject

Returns the value of attribute hits.



6
7
8
# File 'lib/hci/hit.rb', line 6

def hits
  @hits
end

Instance Attribute Details

#answer_optionsObject

Returns the value of attribute answer_options.



43
44
45
# File 'lib/hci/hit.rb', line 43

def answer_options
  @answer_options
end

#answer_typeObject

Returns the value of attribute answer_type.



44
45
46
# File 'lib/hci/hit.rb', line 44

def answer_type
  @answer_type
end

#directionsObject

Returns the value of attribute directions.



41
42
43
# File 'lib/hci/hit.rb', line 41

def directions
  @directions
end

#image_urlObject

Returns the value of attribute image_url.



42
43
44
# File 'lib/hci/hit.rb', line 42

def image_url
  @image_url
end

#nameObject

Returns the value of attribute name.



40
41
42
# File 'lib/hci/hit.rb', line 40

def name
  @name
end

#replaceObject

whether hits with the same resource id and name should be overwritten



46
47
48
# File 'lib/hci/hit.rb', line 46

def replace
  @replace
end

#responses_requiredObject

Returns the value of attribute responses_required.



45
46
47
# File 'lib/hci/hit.rb', line 45

def responses_required
  @responses_required
end

Class Method Details

.cancel(name, options) ⇒ Object



26
27
28
# File 'lib/hci/hit.rb', line 26

def cancel(name, options)
  @hits[name].cancel(options)
end

.clear!Object



34
35
36
# File 'lib/hci/hit.rb', line 34

def clear!
  @hits = {}
end

.define(name) {|hit| ... } ⇒ Object

Yields:

  • (hit)

Raises:



12
13
14
15
16
17
18
19
20
# File 'lib/hci/hit.rb', line 12

def define(name, &block)
  raise ConfigurationError, "Please set your Hci api key with Hci::Client.api_key = 'your-api-key-here'" unless Client.api_key
  raise ConfigurationError, "Please set your callback URL with Hci::Client.callback_host = 'www.your-domain-name.com'" unless Client.callback_host
  
  hit = self.new
  hit.name = name
  yield hit
  self.hits[name] = hit
end

.find(name) ⇒ Object



30
31
32
# File 'lib/hci/hit.rb', line 30

def find(name)
  self.hits[name]
end

.request(name, options) ⇒ Object



22
23
24
# File 'lib/hci/hit.rb', line 22

def request(name, options)
  @hits[name].request(options)
end

Instance Method Details

#cancel(options) ⇒ Object



57
58
59
60
# File 'lib/hci/hit.rb', line 57

def cancel(options)
  hit_request = HitRequest.new(self, options)
  hit_request.cancel
end

#complete!(results) ⇒ Object



81
82
83
# File 'lib/hci/hit.rb', line 81

def complete!(results)
  @on_complete_proc.call(results) if @on_complete_proc
end

#fail!(results) ⇒ Object



89
90
91
# File 'lib/hci/hit.rb', line 89

def fail!(results)
  @on_failure_proc.call(results) if @on_failure_proc
end

#on_completion(&block) ⇒ Object

Callbacks



77
78
79
# File 'lib/hci/hit.rb', line 77

def on_completion(&block)
  @on_complete_proc = block
end

#on_failure(&block) ⇒ Object



85
86
87
# File 'lib/hci/hit.rb', line 85

def on_failure(&block)
  @on_failure_proc = block
end

#request(options) ⇒ Object



52
53
54
55
# File 'lib/hci/hit.rb', line 52

def request(options)
  hit_request = HitRequest.new(self, options)
  hit_request.create
end

#to_hashObject



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/hci/hit.rb', line 62

def to_hash
  {
    :name=>name,
    :directions => directions,
    :image_url => image_url,
    :answer_options => answer_options,
    :responses_required => responses_required,
    :answer_type => answer_type.to_s,
    :callback_url => Client.callback_url,
    :replace => replace
  }
end