Class: TiendaNube::Auth
- Inherits:
-
Object
- Object
- TiendaNube::Auth
- Defined in:
- lib/tienda_nube/auth.rb
Constant Summary collapse
- Auth_URL =
{ :ar => "https://www.tiendanube.com/apps", :br => "https://www.nuvemshop.com.br/apps"}
Class Attribute Summary collapse
-
.client_id ⇒ Object
Returns the value of attribute client_id.
-
.client_secret ⇒ Object
Returns the value of attribute client_secret.
Class Method Summary collapse
Instance Method Summary collapse
- #authorize_url ⇒ Object
- #get_access_token(code) ⇒ Object
-
#initialize(country = :ar) ⇒ Auth
constructor
A new instance of Auth.
Constructor Details
#initialize(country = :ar) ⇒ Auth
Returns a new instance of Auth.
11 12 13 14 15 |
# File 'lib/tienda_nube/auth.rb', line 11 def initialize(country = :ar) @client_id = Auth.client_id @client_secret = Auth.client_secret @country = country end |
Class Attribute Details
.client_id ⇒ Object
Returns the value of attribute client_id.
4 5 6 |
# File 'lib/tienda_nube/auth.rb', line 4 def client_id @client_id end |
.client_secret ⇒ Object
Returns the value of attribute client_secret.
4 5 6 |
# File 'lib/tienda_nube/auth.rb', line 4 def client_secret @client_secret end |
Class Method Details
.config {|_self| ... } ⇒ Object
8 9 10 |
# File 'lib/tienda_nube/auth.rb', line 8 def self.config yield self end |
Instance Method Details
#authorize_url ⇒ Object
16 17 18 |
# File 'lib/tienda_nube/auth.rb', line 16 def [Auth_URL[@country], @client_id, "authorize"].join("/") end |
#get_access_token(code) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/tienda_nube/auth.rb', line 19 def get_access_token(code) params = { :client_id => @client_id, :client_secret => @client_secret, :grant_type => 'authorization_code', :code => code } uri = URI([Auth_URL[@country], 'authorize/token'].join('/')) request = Net::HTTP.post_form(uri ,params) if request.code != "200" return {:error => "server error"} else json = JSON.parse(request.body) if json["error_description"] {:error => json["error_description"]} else { :store_id => json["user_id"], :access_token => json["access_token"], :scope => json["scope"] } end end end |