Class: Dailycred::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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



17
18
19
20
21
22
23
# File 'lib/dailycred/client.rb', line 17

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_idObject

Returns the value of attribute client_id.



3
4
5
# File 'lib/dailycred/client.rb', line 3

def client_id
  @client_id
end

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/dailycred/client.rb', line 3

def options
  @options
end

#secret_keyObject

Returns the value of attribute secret_key.



3
4
5
# File 'lib/dailycred/client.rb', line 3

def secret_key
  @secret_key
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/dailycred/client.rb', line 3

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)



30
31
32
33
34
35
36
37
# File 'lib/dailycred/client.rb', line 30

def event(user_id, key, val="")
  opts = {
    :key => key,
    :valuestring => val,
    :user_id => user_id
  }
  post "/admin/api/customevent.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



77
78
79
80
# File 'lib/dailycred/client.rb', line 77

def post(url, opts, secure=true)
  opts.merge! base_opts(secure)
  response = get_conn.post url, opts
end

#reset_password(user) ⇒ Object

Send a reset password email

  • @param [string] user the user’s email or username



64
65
66
67
68
69
# File 'lib/dailycred/client.rb', line 64

def reset_password(user)
  opts = {
    :user => user
  }
  post "/password/api/reset", 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



43
44
45
46
47
48
49
# File 'lib/dailycred/client.rb', line 43

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)



53
54
55
56
57
58
59
# File 'lib/dailycred/client.rb', line 53

def untag(user_id, tag)
  opts = {
    :user_id => user_id,
    :tag => tag
  }
  post "/admin/api/user/untag.json", opts
end