class TiendaNube::Auth

Constants

Auth_URL

Attributes

client_id[RW]
client_secret[RW]

Public Class Methods

config() { |self| ... } click to toggle source
# File lib/tienda_nube/auth.rb, line 8
def self.config
  yield self
end
new(country = :ar) click to toggle source
# 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

Public Instance Methods

authorize_url() click to toggle source
# File lib/tienda_nube/auth.rb, line 16
def authorize_url
  [Auth_URL[@country], @client_id, "authorize"].join("/")  
end
get_access_token(code) click to toggle source
# 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