Class: Restulicious::Coordinator

Inherits:
Object
  • Object
show all
Defined in:
lib/restulicious/coordinator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klazz, api_options) ⇒ Coordinator



6
7
8
9
10
11
# File 'lib/restulicious/coordinator.rb', line 6

def initialize(klazz, api_options)
  @klazz = klazz
  api_options(api_options)
  @request_options ||= {}
  @headers ||= {}
end

Instance Attribute Details

#headers(header_hash) ⇒ Object

Returns the value of attribute headers.



4
5
6
# File 'lib/restulicious/coordinator.rb', line 4

def headers
  @headers
end

#request_optionsObject

Returns the value of attribute request_options.



4
5
6
# File 'lib/restulicious/coordinator.rb', line 4

def request_options
  @request_options
end

Instance Method Details

#all(&block) ⇒ Object



59
60
61
# File 'lib/restulicious/coordinator.rb', line 59

def all(&block)
  adapter.get(query_interface.all_url, query_interface.params, &block)
end

#api_options(options) ⇒ Object



86
87
88
89
90
91
# File 'lib/restulicious/coordinator.rb', line 86

def api_options(options)
  option ||= {}
  @url  = options[:url]
  @type = options[:type]
  @key  = options[:key]
end

#basic_auth(username, password) ⇒ Object



17
18
19
20
21
# File 'lib/restulicious/coordinator.rb', line 17

def basic_auth(username, password)
  request_options[:username] = username
  request_options[:password] = password
  self
end

#create(&block) ⇒ Object



63
64
65
# File 'lib/restulicious/coordinator.rb', line 63

def create(&block)
  adapter.post(query_interface.all_url, query_interface.params, &block)
end

#first(&block) ⇒ Object



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

def first(&block)
  adapter.get(query_interface.first_url, query_interface.params, &block)
end

#from(*args) ⇒ Object



35
36
37
38
# File 'lib/restulicious/coordinator.rb', line 35

def from(*args)
  query_interface.from(*args)
  self
end

#limit(*args) ⇒ Object



40
41
42
43
# File 'lib/restulicious/coordinator.rb', line 40

def limit(*args)
  query_interface.limit(*args)
  self
end

#offset(*args) ⇒ Object



45
46
47
48
# File 'lib/restulicious/coordinator.rb', line 45

def offset(*args)
  query_interface.offset(*args)
  self
end

#on_complete(&block) ⇒ Object



81
82
83
84
# File 'lib/restulicious/coordinator.rb', line 81

def on_complete(&block)
  adapter.on_complete(&block)
  self
end

#on_failure(&block) ⇒ Object



71
72
73
74
# File 'lib/restulicious/coordinator.rb', line 71

def on_failure(&block)
  adapter.on_failure(&block)
  self
end

#on_success(&block) ⇒ Object



76
77
78
79
# File 'lib/restulicious/coordinator.rb', line 76

def on_success(&block)
  adapter.on_success(&block)
  self
end

#query_interfaceObject



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

def query_interface
  @query_interface ||= Restulicious::QueryInterface.new(@url)
end

#select(*args) ⇒ Object



50
51
52
53
# File 'lib/restulicious/coordinator.rb', line 50

def select(*args)
  query_interface.select(*args)
  self
end

#update(&block) ⇒ Object



67
68
69
# File 'lib/restulicious/coordinator.rb', line 67

def update(&block)
  adapter.put(query_interface.first_url, query_interface.params, &block)
end

#where(*args) ⇒ Object



30
31
32
33
# File 'lib/restulicious/coordinator.rb', line 30

def where(*args)
  query_interface.where(*args)
  self
end