From fdd87a8e14d3fcbf0f2fd91d6f2280e0128c73cf Mon Sep 17 00:00:00 2001 From: Marc Florisson Date: Wed, 5 Dec 2012 18:32:07 +0100 Subject: add more controllers in api/V1 --- app/models/api/v1/api_key.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 app/models/api/v1/api_key.rb (limited to 'app/models/api') diff --git a/app/models/api/v1/api_key.rb b/app/models/api/v1/api_key.rb new file mode 100644 index 000000000..af029e5f7 --- /dev/null +++ b/app/models/api/v1/api_key.rb @@ -0,0 +1,32 @@ +module Api + module V1 + class ApiKey + def initialize(token) + @organisation_id, @referential_id = token.split('-') + end + def self.create( organisation, referential) + ApiKey.new( "#{organisation.id}-#{referential.id}") + end + def token + "#{@organisation_id}-#{@referential_id}" + end + def exists? + organisation && referential + end + def referential_slug + referential.slug + end + def referential + @referential ||= organisation.referentials.find_by_id @referential_id + end + def eql?(other) + other.token == self.token + end + private + def organisation + @organisation ||= Organisation.find_by_id @organisation_id + end + end + end +end + -- cgit v1.2.3