dailycred 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/dailycred.gemspec +1 -1
- data/lib/dailycred.rb +56 -10
- data/lib/generators/dailycred_generator.rb +3 -3
- data/lib/generators/templates/omniauth.rb +9 -10
- metadata +2 -1
data/dailycred.gemspec
CHANGED
data/lib/dailycred.rb
CHANGED
@@ -4,31 +4,77 @@ require "middleware/middleware"
|
|
4
4
|
|
5
5
|
class Dailycred
|
6
6
|
|
7
|
-
attr_accessor :client_id, :secret_key
|
7
|
+
attr_accessor :client_id, :secret_key, :options
|
8
8
|
|
9
|
-
|
9
|
+
# Initializes a dailycred object
|
10
|
+
# @param [String] client_id the client's daiycred client id
|
11
|
+
# @param [String] secret_key the clients secret key
|
12
|
+
# @param [Hash] opts a hash of options
|
13
|
+
def initialize(client_id, secret_key="", opts={})
|
10
14
|
@client_id = client_id
|
11
15
|
@secret_key = secret_key
|
16
|
+
@options = opts
|
12
17
|
end
|
13
18
|
|
14
19
|
URL = "https://www.dailycred.com"
|
15
20
|
|
21
|
+
# Generates a Dailycred event
|
22
|
+
# @param [String] user_id the user's dailycred user id
|
23
|
+
# @param [String] key the name of the event type
|
24
|
+
# @param [String] val the value of the event (optional)
|
16
25
|
def event(user_id, key, val="")
|
17
|
-
connection = Faraday::Connection.new Dailycred::URL, :ssl => { :ca_file => "/opt/local/share/curl/curl-ca-bundle.crt" }
|
18
26
|
opts = {
|
19
|
-
:client_id => @client_id,
|
20
|
-
:client_secret => @secret_key,
|
21
27
|
:key => key,
|
22
28
|
:valuestring => val,
|
23
29
|
:user_id => user_id
|
24
30
|
}
|
25
|
-
|
31
|
+
post "/admin/api/customevent.json", opts
|
26
32
|
end
|
27
33
|
|
28
|
-
|
34
|
+
# Tag a user in dailycred
|
35
|
+
# @param [String] user_id the user's dailycred user id
|
36
|
+
# @param [String] tag the desired tag to add
|
37
|
+
def tag(user_id, tag)
|
38
|
+
opts = {
|
39
|
+
:user_id => user_id,
|
40
|
+
:tag => tag
|
41
|
+
}
|
42
|
+
post "/admin/api/user/tag.json", opts
|
43
|
+
end
|
44
|
+
|
45
|
+
# Untag a user in dailycred
|
46
|
+
# (see #tag)
|
47
|
+
def untag(user_id, tag)
|
48
|
+
opts = {
|
49
|
+
:user_id => user_id,
|
50
|
+
:tag => tag
|
51
|
+
}
|
52
|
+
post "/admin/api/user/untag.json", opts
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def post(url, opts)
|
58
|
+
opts.merge! base_opts
|
59
|
+
get_conn.post url, opts
|
60
|
+
end
|
61
|
+
|
62
|
+
def ssl_opts
|
63
|
+
opts = {}
|
64
|
+
if @options[:client_options] && @options[:client_options][:ssl]
|
65
|
+
opts[:ssl] = @options[:client_options][:ssl]
|
66
|
+
end
|
67
|
+
opts
|
68
|
+
end
|
69
|
+
|
70
|
+
def base_opts
|
71
|
+
{
|
72
|
+
:client_id => @client_id,
|
73
|
+
:client_secret => @client_secret
|
74
|
+
}
|
75
|
+
end
|
29
76
|
|
30
|
-
|
31
|
-
|
32
|
-
# Your code goes here...
|
77
|
+
def get_conn
|
78
|
+
Faraday::Connection.new Dailycred::URL, ssl_opts
|
33
79
|
end
|
34
80
|
end
|
@@ -13,7 +13,7 @@ class DailycredGenerator < Rails::Generators::Base
|
|
13
13
|
EOS
|
14
14
|
|
15
15
|
APP_CONTROLLER_LINES =<<-EOS
|
16
|
-
helper_method :current_user, :login_path, :dailycred
|
16
|
+
helper_method :current_user, :login_path, :dailycred, :signup_path
|
17
17
|
|
18
18
|
private
|
19
19
|
|
@@ -33,8 +33,8 @@ class DailycredGenerator < Rails::Generators::Base
|
|
33
33
|
"/auth/dailycred"
|
34
34
|
end
|
35
35
|
|
36
|
-
def
|
37
|
-
"/auth/dailycred?action=
|
36
|
+
def login_path
|
37
|
+
"/auth/dailycred?action=signin"
|
38
38
|
end
|
39
39
|
|
40
40
|
def dailycred
|
@@ -4,18 +4,17 @@ Rails.configuration.DAILYCRED_SECRET_KEY = "<%= secret_key %>"
|
|
4
4
|
dc_id = Rails.configuration.DAILYCRED_CLIENT_ID
|
5
5
|
dc_secret = Rails.configuration.DAILYCRED_SECRET_KEY
|
6
6
|
|
7
|
-
|
8
|
-
provider :dailycred, dc_id, dc_secret
|
9
|
-
#if you get an error like this:
|
10
|
-
# => SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)
|
11
|
-
|
12
|
-
#use this for OS X
|
13
|
-
#provider :dailycred, dc_id, dc_secret, {:client_options => {:ssl => {:ca_file => '/opt/local/share/curl/curl-ca-bundle.crt'}}}
|
7
|
+
dc_options = { :client_options => {} }
|
14
8
|
|
15
|
-
|
16
|
-
|
9
|
+
if File.exists?('/etc/ssl/certs')
|
10
|
+
dc_options[:client_options][:ssl] = { :ca_path => '/etc/ssl/certs'}
|
11
|
+
end
|
12
|
+
if File.exists?('/opt/local/share/curl/curl-ca-bundle.crt')
|
13
|
+
dc_options[:client_options][:ssl] = { :ca_file => 'opt/local/share/curl/curl-ca-bundle.crt' }
|
14
|
+
end
|
17
15
|
|
18
|
-
|
16
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
17
|
+
provider :dailycred, dc_id, dc_secret, dc_options
|
19
18
|
end
|
20
19
|
|
21
20
|
Rails.application.config.middleware.use "Dailycred::Middleware", dc_id
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dailycred
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -96,3 +96,4 @@ summary: summary
|
|
96
96
|
test_files:
|
97
97
|
- spec/omniauth/strategies/dailycred_spec.rb
|
98
98
|
- spec/spec_helper.rb
|
99
|
+
has_rdoc:
|