Module: Braque::Model::ClassMethods

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_rootObject

Returns the value of attribute api_root.



49
50
51
# File 'lib/braque/model.rb', line 49

def api_root
  @api_root
end

#api_tokenObject

Returns the value of attribute api_token.



50
51
52
# File 'lib/braque/model.rb', line 50

def api_token
  @api_token
end

Instance Method Details

#clientObject



76
77
78
79
80
# File 'lib/braque/model.rb', line 76

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

#collection_method_nameObject



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

def collection_method_name
  name.tableize
end

#create(params = {}) ⇒ Object



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

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

#find(options = {}) ⇒ Object



58
59
60
61
# File 'lib/braque/model.rb', line 58

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

#instance_method_nameObject



72
73
74
# File 'lib/braque/model.rb', line 72

def instance_method_name
  collection_method_name.singularize
end

#list(options = {}) ⇒ Object



52
53
54
55
56
# File 'lib/braque/model.rb', line 52

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