dailycred.rb |
|
---|---|
require "omniauth-dailycred/version"
require "omniauth/strategies/dailycred"
require "middleware/middleware"
class Dailycred
attr_accessor :client_id, :secret_key, :options, :url
URL = "https://www.dailycred.com"
ROUTES = {
:signup => "/user/api/signup.json",
:login => "/user/api/signin.json"
} |
|
Initializes a dailycred object
|
def initialize(client_id, secret_key="", opts={})
@client_id = client_id
@secret_key = secret_key
@options = opts
opts[:client_options] ||= {}
@url = opts[:client_options][:site] || Dailycred::URL
end |
Generates a Dailycred event
|
def event(user_id, key, val="")
opts = {
:key => key,
:valuestring => val,
:user_id => user_id
}
post "/admin/api/customevent.json", opts
end |
Tag a user in dailycred
|
def tag(user_id, tag)
opts = {
:user_id => user_id,
:tag => tag
}
post "/admin/api/user/tag.json", opts
end |
Untag a user in dailycred (see #tag) |
def untag(user_id, tag)
opts = {
:user_id => user_id,
:tag => tag
}
post "/admin/api/user/untag.json", opts
end |
Send a reset password email
|
def passReset(user)
opts = {
:user => user
}
post "/password/api/reset", opts
end |
A wildcard for making any post requests to dailycred. clientid and clientsecret are automatically added to the request
|
def post(url, opts, secure=true)
opts.merge! base_opts(secure)
response = get_conn.post url, opts
end
private
def ssl_opts
opts = {}
if @options[:client_options] && @options[:client_options][:ssl]
opts[:ssl] = @options[:client_options][:ssl]
end
opts
end
def base_opts secure=true
opts = {:client_id => @client_id}
opts[:client_secret] = @secret_key if secure
opts
end
def get_conn
Faraday::Connection.new @url, ssl_opts
end
end |