Module: Braque::Model::ClassMethods

Includes:
Collection
Defined in:
lib/braque/model.rb

Instance Method Summary collapse

Instance Method Details

#clientObject



87
88
89
90
91
# File 'lib/braque/model.rb', line 87

def client
  Hyperclient.new(api_root) do |client|
    client.headers['Http-Authorization'] = api_token
  end
end

#collection_method_nameObject



79
80
81
# File 'lib/braque/model.rb', line 79

def collection_method_name
  name.tableize
end

#create(params = {}) ⇒ Object



74
75
76
77
# File 'lib/braque/model.rb', line 74

def create(params = {})
  response = client.method(collection_method_name).call._post("#{instance_method_name}" => params)
  new response
end

#find(options = {}) ⇒ Object



69
70
71
72
# File 'lib/braque/model.rb', line 69

def find(options = {})
  response = client.method(instance_method_name).call(options)
  new response
end

#instance_method_nameObject



83
84
85
# File 'lib/braque/model.rb', line 83

def instance_method_name
  collection_method_name.singularize
end

#list(options = {}) ⇒ Object



63
64
65
66
67
# File 'lib/braque/model.rb', line 63

def list(options = {})
  options = Hash[options.map { |k, v| [CGI.escape(k.to_s), v] }]
  response = client.method(collection_method_name).call(options)
  LinkedArray.new response, self
end