Class: JugemKey::Auth
- Inherits:
-
Object
- Object
- JugemKey::Auth
- Defined in:
- lib/jugem_key/auth.rb
Constant Summary collapse
- JUGEMKEY_URL =
'https://secure.jugemkey.jp'
- AUTH_API_URL =
'https://api.jugemkey.jp/api/auth'
Instance Method Summary collapse
-
#initialize(params) ⇒ Auth
constructor
A new instance of Auth.
- #token(frob) ⇒ Object
- #uri_to_login(params) ⇒ Object
- #user(token) ⇒ Object
Constructor Details
#initialize(params) ⇒ Auth
Returns a new instance of Auth.
13 14 15 16 |
# File 'lib/jugem_key/auth.rb', line 13 def initialize(params) @api_key = params[:api_key] @secret = params[:secret] end |
Instance Method Details
#token(frob) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/jugem_key/auth.rb', line 37 def token(frob) sig = api_sig({ api_key: @api_key, created: Time.now.iso8601, frob: frob }) atom = fetch_atom('http://api.jugemkey.jp/api/auth/token', { "X-JUGEMKEY-API-CREATED" => Time.now.iso8601, "X-JUGEMKEY-API-KEY" => @api_key, "X-JUGEMKEY-API-FROB" => frob, "X-JUGEMKEY-API-SIG" => sig }) token = REXML::Document.new(atom).elements['entry/token'].text require 'pp' pp token token end |
#uri_to_login(params) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/jugem_key/auth.rb', line 18 def uri_to_login(params) sig = api_sig({ api_key: @api_key, callback_url: params[:callback_url], perms: "auth" }) query = { mode: "auth_issue_frob", api_key: @api_key, perms: "auth", api_sig: sig }.merge(params).map { |k, v| k.to_s + "=" + CGI.escape(v) }.join('&') URI(JUGEMKEY_URL + '?' + query) end |
#user(token) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/jugem_key/auth.rb', line 56 def user(token) sig = api_sig({ api_key: @api_key, created: Time.now.iso8601, token: token }) atom = fetch_atom('http://api.jugemkey.jp/api/auth/user', { "X-JUGEMKEY-API-CREATED" => Time.now.iso8601, "X-JUGEMKEY-API-KEY" => @api_key, "X-JUGEMKEY-API-TOKEN" => token, "X-JUGEMKEY-API-SIG" => sig }) user = REXML::Document.new(atom).elements['entry/title'].text require 'pp' pp user user end |