cronofy 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45bf57c6a8beff0b87cba2a4f20ce39f2d346c08
4
- data.tar.gz: b44a0e902fdce56a5235777245da5401732c7e06
3
+ metadata.gz: d36dfd5dfa353d4d906d8ca54a6f5de39d584b13
4
+ data.tar.gz: 7b38f363878df9bf48df0cf16faba49c42379f67
5
5
  SHA512:
6
- metadata.gz: 1c9b7b89e732c1d5f2549e7490cdee7868fd8843b1fbe52dcda029452efad15aa201ed18a7fd2b3b21359a10e3d8beaa5e32754e530356264ded15bede98c491
7
- data.tar.gz: 27595f37ddb805069debcd433fa7c72aac23d6914dea8ccc57260b8ea4af28bfdcf44b4ff08d1d59bfddb60c38f9d0831ce9e308f87749c287b1108449559f8e
6
+ metadata.gz: 5025298994becd0ae491eaf498db26578535779bac1535fec7cf27b2e0ef3fdf4a89f71b172f01bb6a04f0c1ce804039fe465d403f5bc2ba7dbba839a17ac0dd
7
+ data.tar.gz: 28d0d9200ce72f96978309df3ec1bc9e908af2149b6279a3c7be9852ac4e82f635424f119ba865852aae23e283d54ef5ffd0d7bd5f81ea7dbf07bb0d9a26af2b
@@ -14,14 +14,28 @@ module Cronofy
14
14
 
15
15
  # Internal: generate a URL for authorizing the application with Cronofy
16
16
  #
17
- # redirect_uri String, the URI to return to after authorization
18
- # scope Array of String, the scope requested
17
+ # redirect_uri - A String specifing the URI to return the user to once they
18
+ # have completed the authorization steps.
19
+ # options - The Hash options used to refine the selection
20
+ # (default: {}):
21
+ # :scope - Array of scopes describing the access to request
22
+ # from the user to the users calendars (required).
23
+ # :state - String containing the state value to retain during
24
+ # the OAuth authorization process (optional).
19
25
  #
20
26
  # See http://www.cronofy.com/developers/api#authorization for reference.
21
27
  #
22
28
  # Returns the URL as a String.
23
- def user_auth_link(redirect_uri, scope)
24
- @auth_client.auth_code.authorize_url(redirect_uri: redirect_uri, response_type: 'code', scope: scope.join(' '))
29
+ def user_auth_link(redirect_uri, options = {})
30
+ raise ArgumentError.new(":scope is required") unless options[:scope]
31
+
32
+ params = options.merge(redirect_uri: redirect_uri, response_type: 'code')
33
+
34
+ # Reformat params as needed
35
+ params.delete(:state) if params[:state].nil?
36
+ params[:scope] = params[:scope].join(' ')
37
+
38
+ @auth_client.auth_code.authorize_url(params)
25
39
  end
26
40
 
27
41
  def get_token_from_code(code, redirect_uri)
@@ -268,17 +268,22 @@ module Cronofy
268
268
  # Public: Generates a URL to send the user to in order to perform the OAuth
269
269
  # 2.0 authorization process.
270
270
  #
271
- # redirect_url - A String specifing the URL to return the user to once they
271
+ # redirect_uri - A String specifing the URI to return the user to once they
272
272
  # have completed the authorization steps.
273
- # scope - Array of scopes describing the access to request from the
274
- # user to the users calendars (default:
275
- # DEFAULT_OAUTH_SCOPE).
273
+ # options - The Hash options used to refine the selection
274
+ # (default: {}):
275
+ # :scope - Array of scopes describing the access to request
276
+ # from the user to the users calendars
277
+ # (default: DEFAULT_OAUTH_SCOPE).
278
+ # :state - String containing the state value to retain during
279
+ # the OAuth authorization process (optional).
276
280
  #
277
281
  # See http://www.cronofy.com/developers/api#authorization for reference.
278
282
  #
279
283
  # Returns the URL as a String.
280
- def user_auth_link(redirect_url, scope = DEFAULT_OAUTH_SCOPE)
281
- @auth.user_auth_link(redirect_url, scope)
284
+ def user_auth_link(redirect_url, options = {})
285
+ options = { scope: DEFAULT_OAUTH_SCOPE }.merge(options)
286
+ @auth.user_auth_link(redirect_url, options)
282
287
  end
283
288
 
284
289
  # Public: Retrieves the OAuth credentials authorized for the given code and
@@ -1,3 +1,3 @@
1
1
  module Cronofy
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
@@ -78,6 +78,65 @@ describe Cronofy::Auth do
78
78
  )
79
79
  end
80
80
 
81
+ describe '#user_auth_link' do
82
+ let(:scope_array) { %w{read_events list_calendars create_event} }
83
+ let(:scheme) { 'https' }
84
+ let(:host) { 'app.cronofy.com' }
85
+ let(:path) { '/oauth/authorize' }
86
+ let(:default_params) do
87
+ {
88
+ 'client_id' => client_id,
89
+ 'redirect_uri' => redirect_uri,
90
+ 'response_type' => 'code',
91
+ 'scope' => scope
92
+ }
93
+ end
94
+
95
+ let(:auth) do
96
+ Cronofy::Auth.new(client_id, client_secret)
97
+ end
98
+
99
+ subject do
100
+ url = auth.user_auth_link(redirect_uri, scope: scope_array, state: state)
101
+ URI.parse(url)
102
+ end
103
+
104
+ shared_examples 'a user auth link provider' do
105
+ it 'contains the correct scheme' do
106
+ expect(subject.scheme).to eq scheme
107
+ end
108
+
109
+ it 'contains the correct host' do
110
+ expect(subject.host).to eq host
111
+ end
112
+
113
+ it 'contains the correct path' do
114
+ expect(subject.path).to eq path
115
+ end
116
+
117
+ it 'contains the correct query params' do
118
+ expect(Rack::Utils.parse_query(subject.query)).to eq params
119
+ end
120
+ end
121
+
122
+ context 'when no state' do
123
+ let(:state) { nil }
124
+ let(:params) { default_params }
125
+
126
+ it_behaves_like 'a user auth link provider'
127
+ end
128
+
129
+ context 'when state is passed' do
130
+ let(:state) { SecureRandom.hex }
131
+ let(:params) do
132
+ default_params['state'] = state
133
+ default_params
134
+ end
135
+
136
+ it_behaves_like 'a user auth link provider'
137
+ end
138
+ end
139
+
81
140
  shared_examples 'an authorization request' do
82
141
  context 'when succeeds' do
83
142
  it 'returns a correct Credentials object' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cronofy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergii Paryzhskyi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-29 00:00:00.000000000 Z
12
+ date: 2015-04-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oauth2