omniauth-wrike 0.2.1 → 1.0.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: f7cadd09c0de366c36a34551b964659b3aafc47f
4
- data.tar.gz: 0c56acbf9e7b6ed493a8a8a1d1a545234ffa7a0b
3
+ metadata.gz: 5753890e4845aaccb00fb6a419197bfc1386f019
4
+ data.tar.gz: 581d832271d05720613876fa7b775f7b27e2382d
5
5
  SHA512:
6
- metadata.gz: 20a87f97ca409045e66450ef6985e532a5070859e849004e442b4bc0e47223d0998bcb4736e8c2cc42fdb88f57ff3f69bcc8bdf06920b9ae47e528cf2917a95c
7
- data.tar.gz: 4f00c2c21244335854249e1ddf54f01531651697b97296be06bc53024a56fb2b50b280220af814de4e40961a351233e4aa02fdf681e574e6a6930f9c32539aad
6
+ metadata.gz: f24dbd30ae49ebc7ff34084f769bf14561752bba8c66e0735874ce630286c5d5ff619f13bbd6981479b6c4ce4cd04bb878aca9f17171f6514073a1ccb33fb860
7
+ data.tar.gz: 2c624b0f6f4cdc172d5c2cc05c885acfb65aa43f7f3c8149b91afdd0381e508e98038cff8c414a2544c539f11442428414de27ab90637a1426584633d0586921
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Gemfile CHANGED
@@ -2,3 +2,11 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in omniauth-wrike.gemspec
4
4
  gemspec
5
+
6
+ gem 'rake'
7
+
8
+ group :test do
9
+ gem 'rspec'
10
+ gem 'rack-test'
11
+ gem 'webmock'
12
+ end
data/README.md CHANGED
@@ -21,7 +21,9 @@ end
21
21
 
22
22
  To get your Wrike client ID and Secret, you must [request them here](https://developers.wrike.com/getting-started/).
23
23
 
24
- [Wrike API 3.0 Documentation](https://developers.wrike.com/documentation/api/overview)
24
+ [Wrike API 3.0 Documentation](https://developers.wrike.com/documentation-v3/api/overview)
25
+ [Wrike API 4.0 Documentation](https://developers.wrike.com/documentation/api/overview)
26
+ [Wrike migration from API v3 to API v4 Documentation](https://developers.wrike.com/documentation/api/migrations)
25
27
 
26
28
  ## TODO
27
29
 
@@ -30,4 +32,3 @@ To get your Wrike client ID and Secret, you must [request them here](https://dev
30
32
  ## Contributing
31
33
 
32
34
  Bug reports and pull requests are welcome on GitHub at https://github.com/Jpuelpan/omniauth-wrike
33
-
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module Wrike
3
- VERSION = '0.2.1'
3
+ VERSION = '1.0.0'
4
4
  end
5
- end
5
+ end
@@ -6,38 +6,38 @@ module OmniAuth
6
6
  option :name, 'wrike'
7
7
 
8
8
  option :client_options, {
9
- :site => 'https://www.wrike.com/api/v3',
10
- :authorize_url => 'https://www.wrike.com/oauth2/authorize',
11
- :token_url => 'https://www.wrike.com/oauth2/token'
9
+ site: 'https://www.wrike.com/api/v4',
10
+ authorize_url: 'https://www.wrike.com/oauth2/authorize/v4',
11
+ token_url: 'https://www.wrike.com/oauth2/token'
12
12
  }
13
13
 
14
14
  uid { raw_info['id'] }
15
15
 
16
16
  info do
17
17
  {
18
- 'uid' => raw_info['id'],
19
- 'name' => raw_info['name']
18
+ uid: raw_info['id'],
19
+ name: "#{raw_info['firstName']} #{raw_info['lastName']}",
20
+ email: user_email
20
21
  }
21
22
  end
22
23
 
23
24
  extra do
24
- {
25
- 'raw_info' => raw_info,
26
- 'accounts' => accounts
25
+ {
26
+ raw_info: raw_info
27
27
  }
28
28
  end
29
29
 
30
- def raw_info
31
- @raw_info ||= first_account
30
+ def user_email
31
+ raw_info['profiles'].first['email']
32
32
  end
33
33
 
34
- def accounts
35
- @accounts ||= access_token.get('accounts').parsed['data']
34
+ def user_data_url
35
+ @url ||= URI::HTTPS.build(host: access_token.params['host'], path: '/api/v4/contacts', query: 'me=true').to_s
36
36
  end
37
37
 
38
- def first_account
39
- @first_account ||= accounts.first
38
+ def raw_info
39
+ @raw_info ||= access_token.get(user_data_url).parsed['data'].first
40
40
  end
41
41
  end
42
42
  end
43
- end
43
+ end
@@ -0,0 +1,111 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::Wrike do
4
+ let(:request) { double('Request', params: {}, cookies: {}, env: {}) }
5
+ let(:profile) { raw_info_hash['profiles'].first }
6
+
7
+ subject do
8
+ args = ['appid', 'secret', @options || {}].compact
9
+ OmniAuth::Strategies::Wrike.new(*args).tap do |strategy|
10
+ allow(strategy).to receive(:request) {
11
+ request
12
+ }
13
+ end
14
+ end
15
+
16
+ describe 'client options' do
17
+ it 'has correct name' do
18
+ expect(subject.options.name).to eq('wrike')
19
+ end
20
+
21
+ it 'has correct site' do
22
+ expect(subject.options.client_options.site).to eq('https://www.wrike.com/api/v4')
23
+ end
24
+
25
+ it 'has correct authorize url' do
26
+ expect(subject.options.client_options.authorize_url).to eq('https://www.wrike.com/oauth2/authorize/v4')
27
+ end
28
+ end
29
+
30
+ describe 'info' do
31
+ before do
32
+ allow(subject).to receive(:raw_info).and_return(raw_info_hash)
33
+ end
34
+
35
+ it 'contains strict list of attrs' do
36
+ expect(subject.info.keys).to contain_exactly(:uid, :name, :email)
37
+ end
38
+
39
+ it 'returns the uid' do
40
+ expect(subject.info[:uid]).to eq(raw_info_hash['id'])
41
+ end
42
+
43
+ it 'returns the name' do
44
+ expect(subject.info[:name]).to eq("#{raw_info_hash['firstName']} #{raw_info_hash['lastName']}")
45
+ end
46
+
47
+ it 'returns the email' do
48
+ expect(subject.info[:email]).to eq(profile['email'])
49
+ end
50
+ end
51
+
52
+ describe 'user_email' do
53
+ before do
54
+ allow(subject).to receive(:raw_info).and_return(raw_info_hash)
55
+ end
56
+
57
+ it 'returns user email from first profile' do
58
+ expect(subject.user_email).to eq(profile['email'])
59
+ end
60
+ end
61
+
62
+ describe 'request_phase' do
63
+ context 'with a specified callback_url in the params' do
64
+ before do
65
+ params = { 'callback_url' => 'http://foo.dev/auth/wrike/foobar' }
66
+ allow(subject).to receive(:request) do
67
+ double('Request', params: params)
68
+ end
69
+ allow(subject).to receive(:session) do
70
+ double('Session', :[] => { 'callback_url' => params['callback_url'] })
71
+ end
72
+ end
73
+
74
+ it 'returns the correct callback_path' do
75
+ expect(subject.callback_path).to eq '/auth/wrike/callback'
76
+ end
77
+ end
78
+
79
+ context 'with no callback_url set' do
80
+ it 'returns the default callback_path value' do
81
+ expect(subject.callback_path).to eq '/auth/wrike/callback'
82
+ end
83
+ end
84
+ end
85
+ end
86
+
87
+ private
88
+
89
+ def raw_info_hash
90
+ {
91
+ "id" => "KUAJ25LC",
92
+ "firstName" => "Test",
93
+ "lastName" => "User",
94
+ "type" => "Person",
95
+ "profiles" => [
96
+ {
97
+ "accountId" => "IEAGIITR",
98
+ "email" => "test.user@myapp.com",
99
+ "role" => "User",
100
+ "external" => false,
101
+ "admin" => false,
102
+ "owner" => true
103
+ }
104
+ ],
105
+ "avatarUrl" => "https://www.wrike.com/avatars//7E/A2/Box_ffdf2a2e_84-84_v1.png",
106
+ "timezone" => "Europe/Moscow",
107
+ "locale" => "en",
108
+ "deleted" => false,
109
+ "me" => true
110
+ }
111
+ end
@@ -0,0 +1,16 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'rspec'
4
+ require 'rack/test'
5
+ require 'webmock/rspec'
6
+ require 'omniauth'
7
+ require 'omniauth-wrike'
8
+
9
+ RSpec.configure do |config|
10
+ config.include WebMock::API
11
+ config.include Rack::Test::Methods
12
+ config.extend OmniAuth::Test::StrategyMacros, type: :strategy
13
+ config.expect_with :rspec do |c|
14
+ c.syntax = :expect
15
+ end
16
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-wrike
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Puelpan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-17 00:00:00.000000000 Z
11
+ date: 2018-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth-oauth2
@@ -32,12 +32,15 @@ extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
34
  - ".gitignore"
35
+ - ".rspec"
35
36
  - Gemfile
36
37
  - README.md
37
38
  - lib/omniauth-wrike.rb
38
39
  - lib/omniauth-wrike/version.rb
39
40
  - lib/omniauth/strategies/wrike.rb
40
41
  - omniauth-wrike.gemspec
42
+ - spec/omniauth/strategies/wrike_spec.rb
43
+ - spec/spec_helper.rb
41
44
  homepage: https://github.com/Jpuelpan/omniauth-wrike
42
45
  licenses:
43
46
  - MIT
@@ -63,3 +66,4 @@ signing_key:
63
66
  specification_version: 4
64
67
  summary: Wrike strategy for Omniauth.
65
68
  test_files: []
69
+ has_rdoc: