Sha256: 3476133fa012e6264fe501e0bdb36fa9bee92777389e0c6ee1d9c72d8e51dd6f

Contents?: true

Size: 1.32 KB

Versions: 5

Compression:

Stored size: 1.32 KB

Contents

require 'json'

module AuthenticationHelper

  # using password grant get an access token
  def AuthenticationHelper.get_access_token
    oauth_path = 'https://api.rhapsody.com/oauth/token'
    yaml = ConfigHelper.load
    config_variables = yaml['config_variables']
    api_key = config_variables['API_KEY']
    api_secret = config_variables['API_SECRET']
    username = config_variables['USERNAME']
    password = config_variables['PASSWORD']

    connection = Faraday.new(:url => Rhapsody::HOST_URL) do |faraday|
      faraday.request  :url_encoded
      faraday.basic_auth(api_key, api_secret)
      faraday.adapter  Faraday.default_adapter
    end

    post_hash = {
      username: username,
      password: password,
      grant_type: 'password'
    }

    raw_response = connection.post(oauth_path, post_hash)
    json_response = JSON.parse(raw_response.env[:body])
    access_token = json_response['access_token']
  end

  # typical post hash
  def AuthenticationHelper.post_hash
    yaml = ConfigHelper.load
    config_variables = yaml['config_variables']
    api_key = config_variables['API_KEY']
    api_secret = config_variables['API_SECRET']

    options = {
      api_key: api_key,
      api_secret: api_secret,
      auth_code: 'fakeauthcode',
      redirect_url: 'http://api.soundtracking.dev:3000/auth/rhapsody/authorize'
    }
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rhapsody-0.0.8 spec/helpers/authentication_helper.rb
rhapsody-0.0.8.beta3 spec/helpers/authentication_helper.rb
rhapsody-0.0.8.beta2 spec/helpers/authentication_helper.rb
rhapsody-0.0.8.beta1 spec/helpers/authentication_helper.rb
rhapsody-0.0.7 spec/helpers/authentication_helper.rb