cortex-client 0.1.3 → 0.2.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 +4 -4
- data/lib/cortex/posts.rb +8 -4
- data/lib/cortex/request.rb +1 -1
- data/lib/cortex/version.rb +1 -1
- data/spec/posts_spec.rb +1 -1
- data/spec/request_spec.rb +5 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6805c6198532fcdecc61d871214291b3c3f39fde
|
4
|
+
data.tar.gz: 44d36a2e77e4209d9e13781a91a0e21c01999c40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51aa66d9bf0284a96513c6107e76f720bc5a6aba36217aefe24fe942a44226ba4297eaeeeb293a3b1113cb2428a4b1bd265be4bdcc87cd6f4416824df62ec18e
|
7
|
+
data.tar.gz: 5bd75cfa5bf7c91c1777471e43db74575776193a30ebe68162d0f48e46c344e09a1a3c95744c5901a2153f759b75617afb851f98470d87dfd8637bd45df2a7d3
|
data/lib/cortex/posts.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Cortex
|
2
2
|
class Posts < Cortex::Resource
|
3
|
-
def query
|
4
|
-
client.get('/posts')
|
3
|
+
def query(params = nil)
|
4
|
+
client.get('/posts', params)
|
5
5
|
end
|
6
6
|
|
7
7
|
def feed(params = nil)
|
@@ -24,8 +24,12 @@ module Cortex
|
|
24
24
|
client.get('/posts/filters')
|
25
25
|
end
|
26
26
|
|
27
|
-
def related(id)
|
28
|
-
client.get("/posts/feed/#{id}/related")
|
27
|
+
def related(id, params = nil)
|
28
|
+
client.get("/posts/feed/#{id}/related", params)
|
29
|
+
end
|
30
|
+
|
31
|
+
def authors
|
32
|
+
client.get('/posts/feed/authors')
|
29
33
|
end
|
30
34
|
end
|
31
35
|
end
|
data/lib/cortex/request.rb
CHANGED
@@ -50,7 +50,7 @@ module Cortex
|
|
50
50
|
|
51
51
|
def parse_response(response)
|
52
52
|
if response.status < 300 || (response.body.kind_of?(Hash) && response.body['error'])
|
53
|
-
response.body
|
53
|
+
OpenStruct.new({body: response.body, headers: response.headers.select { |k| ["Content-Range", "X-Total-Items"].include? k } })
|
54
54
|
else
|
55
55
|
OpenStruct.new({:error => response.body, :status => response.status, :original => response})
|
56
56
|
end
|
data/lib/cortex/version.rb
CHANGED
data/spec/posts_spec.rb
CHANGED
@@ -50,7 +50,7 @@ describe Cortex::Posts do
|
|
50
50
|
|
51
51
|
describe :related do
|
52
52
|
it 'should correctly make the request' do
|
53
|
-
client.should_receive(:get).with('/posts/feed/1/related').and_return('success')
|
53
|
+
client.should_receive(:get).with('/posts/feed/1/related', nil).and_return('success')
|
54
54
|
client.posts.related(1).should == 'success'
|
55
55
|
end
|
56
56
|
end
|
data/spec/request_spec.rb
CHANGED
@@ -6,15 +6,15 @@ describe Cortex::Request do
|
|
6
6
|
context 'with a cortex error response' do
|
7
7
|
it 'should return the error object' do
|
8
8
|
body = {'error' => 'Validation error or something'}
|
9
|
-
response = OpenStruct.new(:status => 422, :body => body)
|
10
|
-
client.parse_response(response).should == body
|
9
|
+
response = OpenStruct.new(:status => 422, :body => body, :headers => { :whatever => "Whatever"})
|
10
|
+
client.parse_response(response).to_h.should == { :body => body, :headers => {}}
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
context 'with a non-cortex error response' do
|
15
15
|
it 'should return a wrapped response' do
|
16
16
|
body = 'Catastrophic error'
|
17
|
-
response = OpenStruct.new(:status => 500, :body => body)
|
17
|
+
response = OpenStruct.new(:status => 500, :body => body, :headers => { :whatever => "Whatever" })
|
18
18
|
parsed = client.parse_response(response)
|
19
19
|
parsed.error.should == body
|
20
20
|
parsed.status.should == 500
|
@@ -25,8 +25,8 @@ describe Cortex::Request do
|
|
25
25
|
context 'with a successful response' do
|
26
26
|
it 'should return the parsed body' do
|
27
27
|
body = {:id => 1, title: 'A post'}
|
28
|
-
response = OpenStruct.new(:status => 200, :body => body)
|
29
|
-
client.parse_response(response).should == body
|
28
|
+
response = OpenStruct.new(:status => 200, :body => body, :headers => { :whatever => "Whatever" })
|
29
|
+
client.parse_response(response).to_h.should == { :body => body, :headers => {}}
|
30
30
|
end
|
31
31
|
end
|
32
32
|
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.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bennett Goble
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|