Skip to content

Commit fe18746

Browse files
committed
Implement ability to specify OAuth scopes
1 parent 346e868 commit fe18746

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Version History
33
* All Version bumps are required to update this file as well!!
44
----
55

6+
* 0.7.0 - Implement ability to specify OAuth scopes
67
* 0.6.1 - Update various dependencies
7-
* 0.6.0 - Implemented ETag-based caching flow for all endpoints
8+
* 0.6.0 - Implement ETag-based caching flow for all endpoints
89
* 0.5.0 - Update OAuth2 gem to 1.0.0

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Alternatively, cortex-client will handle OAuth2 authentication for you:
2222
```ruby
2323
require 'cortex-client'
2424

25-
client = Cortex::Client.new(key: 'my-app-id', secret: 'secrey-key-ssh', base_url: 'base_url')
25+
client = Cortex::Client.new(key: 'my-app-id', secret: 'secrey-key-ssh', base_url: 'base_url', scopes: 'view:posts view:media')
2626

2727
client.posts.query().each do |post|
2828
puts post
@@ -51,5 +51,4 @@ Cortex::Client will return a Cortex::Result object. The following methods are av
5151
- *Webpages* - feed
5252

5353
### TODO
54-
- Handle pagination
55-
- /media
54+
- Support *Media* endpoint

lib/cortex/client.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Client
1414
attr_accessor :access_token, :base_url, :auth_method
1515
@key = ''
1616
@secret = ''
17+
@scopes = ''
1718

1819
include Cortex::Connection
1920
include Cortex::Request
@@ -25,6 +26,7 @@ def initialize(hasharg)
2526
else
2627
@key = hasharg[:key]
2728
@secret = hasharg[:secret]
29+
@scopes ||= hasharg[:scopes]
2830
@access_token = get_cc_token
2931
end
3032
@posts = Cortex::Posts.new(self)
@@ -35,7 +37,7 @@ def initialize(hasharg)
3537
def get_cc_token
3638
begin
3739
client = OAuth2::Client.new(@key, @secret, site: @base_url)
38-
client.client_credentials.get_token
40+
client.client_credentials.get_token({scope: @scopes})
3941
rescue Faraday::ConnectionFailed
4042
raise Cortex::Exceptions::ConnectionFailed.new(base_url: @base_url)
4143
end

lib/cortex/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Cortex
2-
VERSION = '0.6.1'
2+
VERSION = '0.7.0'
33
end

spec/client_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
let(:access_token) { '123' }
66
let(:base_url) { 'http://localhost:3000' }
7+
let(:scopes) { 'view:posts view:media' }
78
let(:client) do
8-
Cortex::Client.new(access_token: access_token, base_url: base_url)
9+
Cortex::Client.new(access_token: access_token, base_url: base_url, scopes: scopes)
910
end
1011

1112
it 'should preserve settings' do

0 commit comments

Comments
 (0)