Class: Oauth::Contacts::Live

Inherits:
OAuth2 show all
Defined in:
lib/oauth/contacts/live.rb

Constant Summary

Constants inherited from OAuth2

OAuth2::VERSION

Instance Attribute Summary

Attributes inherited from OAuth2

#code

Attributes inherited from Base

#access_token, #callback_url, #consumer

Instance Method Summary collapse

Methods inherited from OAuth2

#version

Constructor Details

#initializeLive

Returns a new instance of Live.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/oauth/contacts/live.rb', line 10

def initialize
  super
  @callback_url = Settings.oauth.contacts.live.callback_url

  opts = { key: Settings.oauth.contacts.live.key, secret: Settings.oauth.contacts.live.secret,
    extra: { site: 'https://oauth.live.com',
      authorize_url: '/authorize',
      token_url: '/token',
      max_redirects: 5,
      raise_errors: true,
      token_method: :post,
      connection_opts: {} # [Hash] :connection_opts ({}) Hash of connection options to pass to initialize Faraday with
    } }

  @consumer = ::OAuth2::Client.new(opts[:key], opts[:secret], opts[:extra])
end

Instance Method Details

#authorize_urlObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/oauth/contacts/live.rb', line 27

def authorize_url
  # Scopes and permissions http://msdn.microsoft.com/en-us/library/hh243646.aspx
  scopes = Settings.oauth.contacts.live.scopes

  extra_params = { scope: scopes.join(' '),
    redirect_uri: callback_url,
    response_type: 'code',
    state: 'live' }

  consumer.auth_code.authorize_url( extra_params )
end

#contactsObject



40
41
42
43
44
45
# File 'lib/oauth/contacts/live.rb', line 40

def contacts
  token!

  request = 'https://apis.live.net/v5.0/me/contacts'
  @contacts = normalize(MultiJson.decode(access_token.get(request, parse: :json).body))
end