Class: RubyPushNotifications::WNS::WNSAccess

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-push-notifications/wns/wns_access.rb

Overview

This class is responsible for get access auth token for sending pushes

Defined Under Namespace

Classes: Response

Constant Summary collapse

GRANT_TYPE =
'client_credentials'.freeze
SCOPE =
'notify.windows.com'.freeze
ACCESS_TOKEN_URL =
'https://login.live.com/accesstoken.srf'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sid, secret) ⇒ WNSAccess

Parameters:

  • type (String)

    . Sid

  • type (String)

    . Secret



56
57
58
59
# File 'lib/ruby-push-notifications/wns/wns_access.rb', line 56

def initialize(sid, secret)
  @sid = sid
  @secret = secret
end

Instance Attribute Details

#secretString (readonly)

Returns . Secret token.

Returns:

  • (String)

    . Secret token



50
51
52
# File 'lib/ruby-push-notifications/wns/wns_access.rb', line 50

def secret
  @secret
end

#sidString (readonly)

Returns . Sid.

Returns:

  • (String)

    . Sid



47
48
49
# File 'lib/ruby-push-notifications/wns/wns_access.rb', line 47

def sid
  @sid
end

Instance Method Details

#get_tokenObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/ruby-push-notifications/wns/wns_access.rb', line 64

def get_token
  body = {
    grant_type: GRANT_TYPE,
    client_id: sid,
    client_secret: secret,
    scope: SCOPE
  }

  url = URI.parse ACCESS_TOKEN_URL
  http = Net::HTTP.new url.host, url.port
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
  response = http.post url.request_uri, URI.encode_www_form(body)

  Response.new response
end