-
Notifications
You must be signed in to change notification settings - Fork 2
/
demo_oauth.rb
45 lines (31 loc) · 1.22 KB
/
demo_oauth.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#
# BlueVia is a global iniciative of Telefonica delivered by Movistar and O2.
# Please, check out www.bluevia.com and if you need more information
# contact us at mailto:support@bluevia.com
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
require 'bluevia'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
#
# (c) Bluevia (mailto:support@bluevia.com)
#
class DemoOauth
include Bluevia
begin
consumer_key= "xxxxxx"
consumer_secret= "yyyyyyy"
mode= BVMode::SANDBOX
# To create client
@bc = BVOauth.new(mode, consumer_key, consumer_secret)
# In order to authorize application
request_token = @bc.get_request_token
puts "To get access token and secret, we need you to finish the authorization process following this url: "+request_token.auth_url
puts "Please, introduce the obtained pin code:"
STDOUT.flush
pin_code= gets.chomp
# To get access tokens
access_token = @bc.get_access_token(pin_code, request_token.token, request_token.secret)
puts "Your access token and secret for the selected application are " +access_token.token+ " and "+access_token.secret
rescue BlueviaError => e
puts "received Exception: #{e}" #do whatever
end
end