Class: MainController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- MainController
show all
- Includes:
- RailsDribbbleOauth
- Defined in:
- app/controllers/main_controller.rb
Constant Summary
RailsDribbbleOauth::VERSION
Instance Method Summary
collapse
#clear_dribbble_user, #current_dribbble_user
Instance Method Details
#callback ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'app/controllers/main_controller.rb', line 22
def callback
params = {
"client_id" => ENV["DRIBBBLE_CLIENT_ID"],
"client_secret" => ENV["DRIBBBLE_CLIENT_SECRET"],
"code" => request.env["QUERY_STRING"][5..-1],
"button1" => "Submit"
}
uri = URI.parse("https://dribbble.com/oauth/token")
request = Net::HTTP.post_form(uri, params)
token = JSON.parse(request.response.body)["access_token"]
params = {"access_token" => token}
uri = URI.parse("https://api.dribbble.com/v1/user")
uri.query = URI.encode_www_form(params)
response = Net::HTTP.get(uri)
data = {
success: true,
status: "200 OK",
message: nil,
user_id: current_dribbble_user,
user_data: nil
}
response = JSON.parse(response)
if request.code != "200"
data[:success] = false
data[:status] = "204 No Content"
data[:message] = "No user data returned from Dribbble. Reason provided by Dribbble: '#{response["message"]}'"
else
data[:user_data] = response
end
clear_dribbble_user
redirect_to dribbble_information_path(data)
end
|
#oauth_request ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'app/controllers/main_controller.rb', line 4
def oauth_request
id = request.env["QUERY_STRING"].split("=").last.to_i
session[:current_dribbble_user] = id > 0 ? id : nil
dribbble = "https://dribbble.com/oauth/authorize"
params = {"client_id" => ENV["DRIBBBLE_CLIENT_ID"]}
redirect_to "#{dribbble}?#{params.to_query}"
end
|