Class: Elance::Authentication
- Inherits:
-
Object
- Object
- Elance::Authentication
- Defined in:
- lib/elance/authentication.rb
Constant Summary collapse
"https://api.elance.com/api2/oauth/authorize"- @@access_token_url =
"https://api.elance.com/api2/oauth/token"
Instance Method Summary collapse
- #exec_request(url, access_token) ⇒ Object
- #get_access_token(auth_code) ⇒ Object
- #init_curl(url) ⇒ Object
-
#initialize(client_id, client_secret) ⇒ Authentication
constructor
A new instance of Authentication.
- #request_access_code(redirect_url) ⇒ Object
Constructor Details
#initialize(client_id, client_secret) ⇒ Authentication
Returns a new instance of Authentication.
13 14 15 16 17 18 |
# File 'lib/elance/authentication.rb', line 13 def initialize(client_id, client_secret) @client_id = client_id @client_secret = client_secret @curl_headers = [] @response_code = 0 end |
Instance Method Details
#exec_request(url, access_token) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/elance/authentication.rb', line 42 def exec_request(url, access_token) c = self.init_curl( url ) c.headers['Authorization'] = "Basic "+ access_token c.perform c.body_str end |
#get_access_token(auth_code) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/elance/authentication.rb', line 32 def get_access_token(auth_code) c = self.init_curl( @@access_token_url ) c.headers['Authorization'] = "Basic "+ Base64.encode64(@client_id + ":" + @client_secret) c.http_post(Curl::PostField.content('code', URI.escape(auth_code)), Curl::PostField.content('grant_type', 'authorization_code')) res = c.perform ap res res end |
#init_curl(url) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/elance/authentication.rb', line 24 def init_curl(url) c = Curl::Easy.new( url ) c.set(:ENCODING, 1) c.set(:SSL_VERIFYPEER, false) c.set(:CAINFO, "/etc/ssl/certs/ca-certificates.crt") c end |
#request_access_code(redirect_url) ⇒ Object
20 21 22 |
# File 'lib/elance/authentication.rb', line 20 def request_access_code(redirect_url) @@authorize_url + "?client_id=" + @client_id + "&response_type=code&redirect_uri=" + redirect_url end |