Permalink
Browse files

using method_missing for generating api urls

Signed-off-by: Akash Manohar J <akash@akash.im>
  • Loading branch information...
1 parent de60790 commit fdc6491b31f3b2a7fdfa04f11e69a650d9c73b6a @HashNuke HashNuke committed Sep 12, 2011
Showing with 9 additions and 12 deletions.
  1. +1 −1 lib/bushido.rb
  2. +1 −1 lib/bushido/base.rb
  3. +7 −10 lib/bushido/user.rb
View
2 lib/bushido.rb
@@ -10,7 +10,7 @@ module Bushido #:nodoc:
require "action_dispatch"
require "rails/routes"
require "bushido/config"
- require "bushido/actionmailer"
+ require "bushido/action_mailer"
require "bushido/base"
require "bushido/hooks"
require "bushido/platform"
View
2 lib/bushido/base.rb
@@ -16,7 +16,7 @@ def method_missing(method, *args)
end
def api_url(path)
- "#{path[:prefix]}/#{Bushido::Config.api_version}/#{path[:method]}"
+ "#{Bushido::Platform.host}/#{path[:prefix]}/#{Bushido::Config.api_version}/#{path[:method]}"
end
end
end
View
17 lib/bushido/user.rb
@@ -1,18 +1,15 @@
module Bushido
# Bushido User enables user validation against Bushido's server
- class User
+ class User < Base
class << self
- def unity_url #:nodoc:
- "#{Bushido::Platform.host}/unity/v1"
- end
-
+
# Checks whether user an email and password correspond to a valid bushido
# user. Returns nil if false, or the Bushido user's ID if true.
def valid?(email, pass)
params = {}
params[:email] = email
params[:pass] = pass
- Bushido::Command.post_command("#{unity_url}/valid", params)
+ Bushido::Command.post_command(valid_unity_url, params)
end
@@ -21,30 +18,30 @@ def valid?(email, pass)
def exists?(email)
params = {}
params[:email] = email
- Bushido::Command.post_command("#{unity_url}/exists", params)
+ Bushido::Command.post_command(exists_unity_url, params)
end
# send a Bushido invite with a short description of the app (also a box of chocolates, if he's a Kryptonian)
# Bushido::User.invite("clark@kent-on-krypton.com")
def invite(email)
params = {}
params[:email] = email
- Bushido::Command.post_command("#{unity_url}/invite", params)
+ Bushido::Command.post_command(invite_unity_url, params)
end
# List all pending invites
# Bushido::User.pending_invites
def pending_invites
params = {}
- Bushido::Command.get_command("#{unity_url}/pending_invites", params)
+ Bushido::Command.get_command(pending_invites_unity_url, params)
end
# To remove a user from an application
# Bushido::User.remove("5z325f4knbm2f")
def remove(ido_id)
params = {}
params[:ido_id] = ido_id
- Bushido::Command.post_command("#{unity_url}/remove", params)
+ Bushido::Command.post_command(remove_unity_url, params)
end
end

0 comments on commit fdc6491

Please sign in to comment.