Class: TAPI::V3::GenericSearch
Instance Attribute Summary collapse
Instance Method Summary
collapse
inherited_validations, validate, validates_date_format_of, validates_numericality_of, validates_presence_of, validations
Methods included from Utils
append_query, coerce_date, parse_date, symbolize_keys
#config, included
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(key, *args) ⇒ Object
87
88
89
90
91
92
93
|
# File 'lib/tapi/v3/generic_search.rb', line 87
def method_missing(key, *args)
begin
@client.send(key, *args)
rescue NoMethodError
raise NoMethodError, "undefined method `#{key}' for #{self.class}", caller
end
end
|
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
8
9
10
|
# File 'lib/tapi/v3/generic_search.rb', line 8
def client
@client
end
|
#client_urls ⇒ Object
Returns the value of attribute client_urls.
8
9
10
|
# File 'lib/tapi/v3/generic_search.rb', line 8
def client_urls
@client_urls
end
|
#errors ⇒ Object
Returns the value of attribute errors.
9
10
11
|
# File 'lib/tapi/v3/generic_search.rb', line 9
def errors
@errors
end
|
#start_time ⇒ Object
Returns the value of attribute start_time.
8
9
10
|
# File 'lib/tapi/v3/generic_search.rb', line 8
def start_time
@start_time
end
|
#started_at ⇒ Object
Returns the value of attribute started_at.
8
9
10
|
# File 'lib/tapi/v3/generic_search.rb', line 8
def started_at
@started_at
end
|
Instance Method Details
#add_error(name, message) ⇒ Object
26
27
28
|
# File 'lib/tapi/v3/generic_search.rb', line 26
def add_error(name, message)
(errors[name] ||= []) << message
end
|
#api_key ⇒ Object
54
55
56
|
# File 'lib/tapi/v3/generic_search.rb', line 54
def api_key
config[:key]
end
|
#api_url ⇒ Object
49
50
51
52
|
# File 'lib/tapi/v3/generic_search.rb', line 49
def api_url
port = config[:port] == 80 ? '' : ":#{config[:port]}"
"http://#{ config[:host] }#{ port }#{ config[:path] }"
end
|
#get(path, options = {}) ⇒ Object
62
63
64
|
# File 'lib/tapi/v3/generic_search.rb', line 62
def get(path, options={})
TAPI::V3::Client.new_from_get(api_url + path + '.json', options.merge(:key => api_key)).first
end
|
#has_errors? ⇒ Boolean
40
41
42
|
# File 'lib/tapi/v3/generic_search.rb', line 40
def has_errors?
errors.any?
end
|
#id ⇒ Object
11
12
13
14
15
16
17
|
# File 'lib/tapi/v3/generic_search.rb', line 11
def id
if @id
@id
elsif @client and @client.respond_to?(:id)
@client.id
end
end
|
#id=(id) ⇒ Object
19
20
21
|
# File 'lib/tapi/v3/generic_search.rb', line 19
def id=(id)
@id = id
end
|
#load_client ⇒ Object
73
74
75
76
77
78
|
# File 'lib/tapi/v3/generic_search.rb', line 73
def load_client
if @client_urls
client, etag = TAPI::V3::Client.new_from_get(@client_urls[:search_url], {}, @etag)
@client, @etag = client.search, etag unless @etag == etag
end
end
|
#post_url ⇒ Object
58
59
60
|
# File 'lib/tapi/v3/generic_search.rb', line 58
def post_url
api_url + '/' + item_path + '/searches.json'
end
|
#reload ⇒ Object
44
45
46
47
|
# File 'lib/tapi/v3/generic_search.rb', line 44
def reload
load_client
self
end
|
#restart! ⇒ Object
80
81
82
83
84
85
|
# File 'lib/tapi/v3/generic_search.rb', line 80
def restart!
if @client_urls
TAPI::V3::Client.new_from_post(@client_urls[:restart_url], {})
load_client
end
end
|
#start! ⇒ Object
66
67
68
69
70
71
|
# File 'lib/tapi/v3/generic_search.rb', line 66
def start!
@started_at = Time.now
@client = TAPI::V3::Client.new_from_post(post_url, parameters).search
@start_time = Time.now - @started_at
@client_urls = @client.urls
end
|
#valid? ⇒ Boolean
30
31
32
33
34
35
36
37
38
|
# File 'lib/tapi/v3/generic_search.rb', line 30
def valid?
errors.clear
self.class.inherited_validations.each do |validation|
instance_eval(&validation)
end
errors.empty?
end
|