Class: Mirror::Api::OAuth
- Inherits:
-
Object
- Object
- Mirror::Api::OAuth
- Defined in:
- lib/mirror-api/oauth.rb
Instance Attribute Summary collapse
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
readonly
Returns the value of attribute client_secret.
-
#refresh_token ⇒ Object
readonly
Returns the value of attribute refresh_token.
Instance Method Summary collapse
- #get_access_token ⇒ Object
-
#initialize(client_id, client_secret, refresh_token) ⇒ OAuth
constructor
A new instance of OAuth.
Constructor Details
#initialize(client_id, client_secret, refresh_token) ⇒ OAuth
Returns a new instance of OAuth.
5 6 7 8 9 |
# File 'lib/mirror-api/oauth.rb', line 5 def initialize(client_id, client_secret, refresh_token) @client_id = client_id @client_secret = client_secret @refresh_token = refresh_token end |
Instance Attribute Details
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
4 5 6 |
# File 'lib/mirror-api/oauth.rb', line 4 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
4 5 6 |
# File 'lib/mirror-api/oauth.rb', line 4 def client_secret @client_secret end |
#refresh_token ⇒ Object (readonly)
Returns the value of attribute refresh_token.
4 5 6 |
# File 'lib/mirror-api/oauth.rb', line 4 def refresh_token @refresh_token end |
Instance Method Details
#get_access_token ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mirror-api/oauth.rb', line 11 def get_access_token req = Net::HTTP::Post.new("/o/oauth2/token") req.set_form_data(client_id: self.client_id, client_secret: self.client_secret, refresh_token: self.refresh_token, grant_type: "refresh_token") res = Net::HTTP.start("accounts.google.com", use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE) { |http| http.request(req) } result = JSON.parse(res.body) if result if result["access_token"] result["access_token"] elsif result["error"] raise "Error in get_access_token #{result["error"]}" end end end |