cortex-client 0.8.2 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -1
- data/README.md +5 -1
- data/lib/cortex/result.rb +5 -5
- data/lib/cortex/version.rb +1 -1
- data/spec/result_spec.rb +26 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ae9160a1f77ff75bbdd94a1dd24c2158dd24dd2
|
4
|
+
data.tar.gz: 32696a70d36bfb41f7b3769ef6d8c86f71ad7c1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6bd08c5ae793a6aaac1e5bb8c320164cd2c776a1515a76f7860b305c7daacf59fc30a175f8d2383f2fa3bd99dcb90777fe4aee13408114adfae60aebcffc6fd
|
7
|
+
data.tar.gz: 4342fc1a3198dda90259324c55b0f7bc821300eb9f7a1f98e8d461b909acc6e8e8949ba9ca13c0545afba720ae01ad617832c16c230600a488bc8629061a0595
|
data/CHANGELOG.md
CHANGED
@@ -3,7 +3,7 @@ Version History
|
|
3
3
|
* All Version bumps are required to update this file as well!!
|
4
4
|
----
|
5
5
|
|
6
|
-
* 0.
|
6
|
+
* 0.9.0 - Add total pages, next page, and prev page to result object
|
7
7
|
* 0.8.0 - Revert ETag caching flow implementation
|
8
8
|
* 0.7.0 - Implement ability to specify OAuth scopes
|
9
9
|
* 0.6.1 - Update various dependencies
|
data/README.md
CHANGED
@@ -22,13 +22,17 @@ Alternatively, cortex-client will handle OAuth2 authentication for you:
|
|
22
22
|
```ruby
|
23
23
|
require 'cortex-client'
|
24
24
|
|
25
|
-
client = Cortex::Client.new(key: 'my-app-id', secret: '
|
25
|
+
client = Cortex::Client.new(key: 'my-app-id', secret: 'my-app-secret', base_url: 'base_url', scopes: 'view:posts view:media')
|
26
26
|
|
27
27
|
client.posts.query().each do |post|
|
28
28
|
puts post
|
29
29
|
end
|
30
30
|
```
|
31
31
|
|
32
|
+
## Authorization
|
33
|
+
|
34
|
+
For more information about `scopes` and how to obtain an application `key` and `secret`, check [Cortex's authorization documentation](https://github.com/cbdr/cortex#authorization).
|
35
|
+
|
32
36
|
## Result object
|
33
37
|
|
34
38
|
Cortex::Client will return a Cortex::Result object. The following methods are available:
|
data/lib/cortex/result.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
require 'hashie'
|
2
2
|
module Cortex
|
3
3
|
class Result
|
4
|
-
attr_reader :raw_headers, :contents, :total_items, :page, :per_page, :errors, :range_start, :range_end, :range, :status
|
4
|
+
attr_reader :raw_headers, :contents, :total_items, :page, :per_page, :errors, :range_start, :range_end, :range, :status, :total_pages, :next_page, :prev_page
|
5
5
|
|
6
6
|
def initialize(body, headers, status)
|
7
7
|
@contents = parse(body)
|
8
8
|
@raw_headers = headers
|
9
9
|
@status = status
|
10
|
-
@total_items = headers['x-total-items'] unless headers['x-total-items'].nil?
|
11
10
|
parse_headers(headers)
|
12
11
|
@errors = find_errors
|
13
12
|
end
|
@@ -20,15 +19,16 @@ module Cortex
|
|
20
19
|
|
21
20
|
def parse_headers(headers)
|
22
21
|
if headers['X-Total']
|
22
|
+
@total_items = headers['X-Total']
|
23
23
|
@count = headers['X-Total'].to_i
|
24
|
-
end
|
25
|
-
if headers['X-Total']
|
26
24
|
@page = headers['X-Page'].to_i
|
27
25
|
@per_page = headers['X-Per-Page'].to_i
|
28
26
|
@range_start = (@page-1) * @per_page
|
29
27
|
@range_end = @per_page * @page - 1
|
30
28
|
@range = "#{@range_start}-#{@range_end}"
|
31
|
-
|
29
|
+
@total_pages = headers['X-Total-Pages']
|
30
|
+
@next_page = headers['X-Next-Page']
|
31
|
+
@prev_page = headers['X-Prev-Page']
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
data/lib/cortex/version.rb
CHANGED
data/spec/result_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe Cortex::Result do
|
4
|
-
let(:result) { Cortex::Result.new('body', {'X-Total' =>
|
4
|
+
let(:result) { Cortex::Result.new('body', { 'X-Total' => '40', 'X-Page' => "1", 'X-Per-Page' => "10", 'X-Total-Pages' => '4', 'X-Next-Page' => '2', 'X-Prev-Page' => nil }, 200) }
|
5
5
|
let(:failed) { Cortex::Result.new('failed body', {}, 403) }
|
6
6
|
|
7
7
|
it 'should construct' do
|
@@ -31,7 +31,7 @@ RSpec.describe Cortex::Result do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'should expose the headers' do
|
34
|
-
expect(result.raw_headers).to eq({ 'X-Total' =>
|
34
|
+
expect(result.raw_headers).to eq({ 'X-Total' => '40', 'X-Page' => "1", 'X-Per-Page' => "10", 'X-Total-Pages' => '4', 'X-Next-Page' => '2', 'X-Prev-Page' => nil })
|
35
35
|
expect(failed.raw_headers).to eq({})
|
36
36
|
end
|
37
37
|
|
@@ -40,4 +40,28 @@ RSpec.describe Cortex::Result do
|
|
40
40
|
expect(failed.status).to eq 403
|
41
41
|
end
|
42
42
|
|
43
|
+
describe '#total_pages' do
|
44
|
+
it 'returns the value of "X-Total-Pages"' do
|
45
|
+
expect(result.total_pages).to eq '4'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#next_page' do
|
50
|
+
it 'returns_the_value of "X-Next-Page"' do
|
51
|
+
expect(result.next_page).to eq '2'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#prev_page' do
|
56
|
+
it 'returns nil when on the first page' do
|
57
|
+
expect(result.prev_page).to be_nil
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'on the 2nd page' do
|
61
|
+
let(:result) { Cortex::Result.new('body', { 'X-Total' => '40', 'X-Page' => "2", 'X-Per-Page' => "10", 'X-Total-Pages' => '4', 'X-Next-Page' => '3', 'X-Prev-Page' => '1' }, 200) }
|
62
|
+
it 'returns the value if "X-Prev-Page"' do
|
63
|
+
expect(result.prev_page).to eq '1'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
43
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cortex-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CB Content Enablement
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -173,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
173
|
version: '0'
|
174
174
|
requirements: []
|
175
175
|
rubyforge_project:
|
176
|
-
rubygems_version: 2.5.
|
176
|
+
rubygems_version: 2.5.1
|
177
177
|
signing_key:
|
178
178
|
specification_version: 4
|
179
179
|
summary: Cortex API Client
|