Class: Dailycred::Client
- Inherits:
-
Object
- Object
- Dailycred::Client
- Defined in:
- lib/dailycred/client.rb
Constant Summary collapse
- URL =
"https://www.dailycred.com"
- ROUTES =
{ :signup => "/user/api/signup.json", :login => "/user/api/signin.json" }
Instance Attribute Summary collapse
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#options ⇒ Object
Returns the value of attribute options.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#event(user_id, key, val = "") ⇒ Object
Generates a Dailycred event.
-
#initialize(client_id, secret_key = "", opts = {}) ⇒ Client
constructor
Initializes a dailycred object.
- #login(opts = {}) ⇒ Object
-
#post(url, opts, secure = true) ⇒ Object
A wildcard for making any post requests to dailycred.
-
#reset_password(user) ⇒ Object
Send a reset password email.
- #signup(opts = {}) ⇒ Object
-
#tag(user_id, tag) ⇒ Object
Tag a user in dailycred.
-
#untag(user_id, tag) ⇒ Object
Untag a user in dailycred (see #tag).
Constructor Details
#initialize(client_id, secret_key = "", opts = {}) ⇒ Client
Initializes a dailycred object
-
@param [String] client_id the client’s daiycred client id
-
@param [String] secret_key the clients secret key
-
@param [Hash] opts a hash of options
18 19 20 21 22 23 24 |
# File 'lib/dailycred/client.rb', line 18 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::Client::URL end |
Instance Attribute Details
#client_id ⇒ Object
Returns the value of attribute client_id.
4 5 6 |
# File 'lib/dailycred/client.rb', line 4 def client_id @client_id end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/dailycred/client.rb', line 4 def @options end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
4 5 6 |
# File 'lib/dailycred/client.rb', line 4 def secret_key @secret_key end |
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'lib/dailycred/client.rb', line 4 def url @url end |
Instance Method Details
#event(user_id, key, val = "") ⇒ Object
Generates a Dailycred event
-
@param [String] user_id the user’s dailycred user id
-
@param [String] key the name of the event type
-
@param [String] val the value of the event (optional)
31 32 33 34 35 36 37 38 |
# File 'lib/dailycred/client.rb', line 31 def event(user_id, key, val="") opts = { :key => key, :valuestring => val, :user_id => user_id } post "/admin/api/customevent.json", opts end |
#login(opts = {}) ⇒ Object
72 73 74 75 |
# File 'lib/dailycred/client.rb', line 72 def login opts={} opts[:pass] ||= opts[:password] post "/user/api/signin.json", opts end |
#post(url, opts, secure = true) ⇒ Object
A wildcard for making any post requests to dailycred. client_id and client_secret are automatically added to the request
-
@param [string] url
-
@param [hash] opts
-
@param [boolean] secure whether the client_secret should be passed. Defaults to true
88 89 90 91 |
# File 'lib/dailycred/client.rb', line 88 def post(url, opts, secure=true) opts.merge! base_opts(secure) Dailycred::Response.new(get_conn.post url, opts) end |
#reset_password(user) ⇒ Object
Send a reset password email
-
@param [string] user the user’s email or username
65 66 67 68 69 70 |
# File 'lib/dailycred/client.rb', line 65 def reset_password(user) opts = { :user => user } post "/password/api/reset", opts end |
#signup(opts = {}) ⇒ Object
77 78 79 80 |
# File 'lib/dailycred/client.rb', line 77 def signup opts={} opts[:pass] ||= opts[:password] post "/user/api/signup.json", opts end |
#tag(user_id, tag) ⇒ Object
Tag a user in dailycred
-
@param [String] user_id the user’s dailycred user id
-
@param [String] tag the desired tag to add
44 45 46 47 48 49 50 |
# File 'lib/dailycred/client.rb', line 44 def tag(user_id, tag) opts = { :user_id => user_id, :tag => tag } post "/admin/api/user/tag.json", opts end |
#untag(user_id, tag) ⇒ Object
Untag a user in dailycred (see #tag)
54 55 56 57 58 59 60 |
# File 'lib/dailycred/client.rb', line 54 def untag(user_id, tag) opts = { :user_id => user_id, :tag => tag } post "/admin/api/user/untag.json", opts end |