cortex-client 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +33 -0
- data/LICENSE +21 -0
- data/README.md +24 -0
- data/Rakefile +8 -0
- data/cortex-client.gemspec +21 -0
- data/lib/cortex-client.rb +2 -0
- data/lib/cortex/client.rb +22 -0
- data/lib/cortex/connection.rb +21 -0
- data/lib/cortex/posts.rb +19 -0
- data/lib/cortex/request.rb +59 -0
- data/lib/cortex/resource.rb +10 -0
- data/lib/cortex/users.rb +15 -0
- data/lib/cortex/version.rb +3 -0
- data/spec/client_spec.rb +15 -0
- data/spec/posts_spec.rb +31 -0
- data/spec/request_spec.rb +32 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/users_spec.rb +41 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 41847c330727c0f3a25df922c1292b400db9ce98
|
4
|
+
data.tar.gz: 3b39f6070431624e18073815334687d4c904b602
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4c47e73cac0f6bc9ebc975c87c9b077f07a074cc34107e2a66a88ac625c82ee8dc9d7c03106f143acef9dca84c610bbd212ef4237a1dc8abd0b4c29b91f5eb0f
|
7
|
+
data.tar.gz: c0f4e097b734d8a470ef9fd8d59728ff3743f72365c2a78ca29622bc09beb46b8f796337bdf82f560e618ccc17918c9f1f643401efb977fed478b8d61c51cb25
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
cortex-client (0.0.1)
|
5
|
+
faraday (~> 0.8.9)
|
6
|
+
faraday_middleware (~> 0.9.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
diff-lcs (1.2.5)
|
12
|
+
faraday (0.8.9)
|
13
|
+
multipart-post (~> 1.2.0)
|
14
|
+
faraday_middleware (0.9.0)
|
15
|
+
faraday (>= 0.7.4, < 0.9)
|
16
|
+
multipart-post (1.2.0)
|
17
|
+
rake (10.2.2)
|
18
|
+
rspec (2.14.1)
|
19
|
+
rspec-core (~> 2.14.0)
|
20
|
+
rspec-expectations (~> 2.14.0)
|
21
|
+
rspec-mocks (~> 2.14.0)
|
22
|
+
rspec-core (2.14.8)
|
23
|
+
rspec-expectations (2.14.5)
|
24
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
25
|
+
rspec-mocks (2.14.6)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
cortex-client!
|
32
|
+
rake
|
33
|
+
rspec
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2014 CareerBuilder, LLC
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# cortex-client
|
2
|
+
Ruby client library for [cortex](https://github.com/cb-talent-development/cortex)'s API.
|
3
|
+
|
4
|
+
cortex-client does not handle fetching or refreshing an OAuth access_token. For this use a library such as [OAuth](http://oauth.rubyforge.org/).
|
5
|
+
|
6
|
+
```ruby
|
7
|
+
require 'cortex-client'
|
8
|
+
|
9
|
+
client = Cortex::Client.new(access_token)
|
10
|
+
|
11
|
+
client.posts.query().each do |post|
|
12
|
+
puts post
|
13
|
+
end
|
14
|
+
```
|
15
|
+
|
16
|
+
### Supported Endpoints
|
17
|
+
|
18
|
+
- *Users* - me, get ,save
|
19
|
+
- *Posts* - query, get, save, delete
|
20
|
+
|
21
|
+
### TODO
|
22
|
+
- Handle pagination
|
23
|
+
- Support for search queries
|
24
|
+
- /media
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require './lib/cortex/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'cortex-client'
|
6
|
+
s.version = Cortex::VERSION
|
7
|
+
s.summary = 'Cortex API Client'
|
8
|
+
s.homepage = 'https://github.com/cb-talent-development/cortex-client'
|
9
|
+
s.authors = ['Bennett Goble']
|
10
|
+
s.license = 'MIT'
|
11
|
+
|
12
|
+
s.files = `git ls-files`.split($/).reject { |f| f == '.gitignore' }
|
13
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
14
|
+
s.require_paths = ['lib']
|
15
|
+
|
16
|
+
s.add_development_dependency 'rake'
|
17
|
+
s.add_development_dependency 'rspec'
|
18
|
+
|
19
|
+
s.add_dependency 'faraday', '~> 0.8.9'
|
20
|
+
s.add_dependency 'faraday_middleware', '~> 0.9.0'
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'cortex/connection'
|
2
|
+
require 'cortex/request'
|
3
|
+
require 'cortex/resource'
|
4
|
+
require 'cortex/posts'
|
5
|
+
require 'cortex/users'
|
6
|
+
|
7
|
+
module Cortex
|
8
|
+
class Client
|
9
|
+
attr_reader :posts, :users
|
10
|
+
attr_accessor :access_token, :base_url
|
11
|
+
|
12
|
+
include Cortex::Connection
|
13
|
+
include Cortex::Request
|
14
|
+
|
15
|
+
def initialize(access_token, base_url = 'https://cbcortex.com/api/v1')
|
16
|
+
@access_token = access_token
|
17
|
+
@base_url = base_url
|
18
|
+
@posts = Cortex::Posts.new(self)
|
19
|
+
@users = Cortex::Users.new(self)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
|
4
|
+
module Cortex
|
5
|
+
module Connection
|
6
|
+
def connection
|
7
|
+
options = {
|
8
|
+
:headers => {
|
9
|
+
:user_agent => "cortex-client (Ruby) - #{Cortex::VERSION}"
|
10
|
+
},
|
11
|
+
:url => base_url
|
12
|
+
}
|
13
|
+
Faraday.new options do |conn|
|
14
|
+
conn.request :oauth2, access_token
|
15
|
+
conn.request :json
|
16
|
+
conn.response :json, :content_type => /\bjson$/
|
17
|
+
conn.adapter Faraday.default_adapter
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/cortex/posts.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Cortex
|
2
|
+
class Posts < Cortex::Resource
|
3
|
+
def query
|
4
|
+
client.get('/posts')
|
5
|
+
end
|
6
|
+
|
7
|
+
def get(id)
|
8
|
+
client.get("/posts/#{id}")
|
9
|
+
end
|
10
|
+
|
11
|
+
def save(post)
|
12
|
+
client.save('/posts', post)
|
13
|
+
end
|
14
|
+
|
15
|
+
def delete(id)
|
16
|
+
client.delete("/posts/#{id}")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
module Cortex
|
4
|
+
module Request
|
5
|
+
def get(path, params = {})
|
6
|
+
response = connection.get do |r|
|
7
|
+
r.url base_url + path
|
8
|
+
r.params = params
|
9
|
+
end
|
10
|
+
parse_response(response)
|
11
|
+
end
|
12
|
+
|
13
|
+
def post(path, params = {})
|
14
|
+
response = connection.post do |r|
|
15
|
+
r.url base_url + path
|
16
|
+
r.body = params unless params.empty?
|
17
|
+
end
|
18
|
+
parse_response(response)
|
19
|
+
end
|
20
|
+
|
21
|
+
def put(path, params = {})
|
22
|
+
response = connection.put do |r|
|
23
|
+
r.url base_url + path
|
24
|
+
r.body = params unless params.empty?
|
25
|
+
end
|
26
|
+
parse_response(response)
|
27
|
+
end
|
28
|
+
|
29
|
+
def delete(path)
|
30
|
+
response = connection.delete do |r|
|
31
|
+
r.url base_url + path
|
32
|
+
end
|
33
|
+
response.status < 300
|
34
|
+
end
|
35
|
+
|
36
|
+
def delete!(path)
|
37
|
+
response = connection.delete do |r|
|
38
|
+
r.url base_url + path
|
39
|
+
end
|
40
|
+
if response.status < 300
|
41
|
+
true
|
42
|
+
else
|
43
|
+
raise parse_response(response)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def save(path, model)
|
48
|
+
model[:id] ? put("#{path}/#{model[:id]}", model) : post(path, model)
|
49
|
+
end
|
50
|
+
|
51
|
+
def parse_response(response)
|
52
|
+
if response.status < 300 || (response.body.kind_of?(Hash) && response.body['error'])
|
53
|
+
response.body
|
54
|
+
else
|
55
|
+
OpenStruct.new({:error => response.body, :status => response.status, :original => response})
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/cortex/users.rb
ADDED
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cortex::Client do
|
4
|
+
|
5
|
+
let(:access_token) { '123' }
|
6
|
+
let(:base_url) { 'http://localhost:3000' }
|
7
|
+
let(:client) do
|
8
|
+
Cortex::Client.new(access_token, base_url)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should preserve settings' do
|
12
|
+
client.access_token.should == access_token
|
13
|
+
client.base_url.should == base_url
|
14
|
+
end
|
15
|
+
end
|
data/spec/posts_spec.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cortex::Posts do
|
4
|
+
|
5
|
+
let(:client) { Cortex::Client.new('123') }
|
6
|
+
|
7
|
+
describe :get do
|
8
|
+
it 'should correctly make the request' do
|
9
|
+
client.should_receive(:get).with('/posts/1').and_return('response')
|
10
|
+
client.posts.get(1).should == 'response'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe :save do
|
15
|
+
context 'with an existing post' do
|
16
|
+
it 'should correctly make the request' do
|
17
|
+
post = {:id => 1, :title => 'Post'}
|
18
|
+
client.should_receive(:put).with('/posts/1', post).and_return('response')
|
19
|
+
client.posts.save(post).should == 'response'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'with a new post' do
|
24
|
+
it 'should correctly make the request' do
|
25
|
+
post = {:title => 'Post'}
|
26
|
+
client.should_receive(:post).with('/posts', post).and_return('response')
|
27
|
+
client.posts.save(post).should == 'response'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cortex::Request do
|
4
|
+
let(:client) { Cortex::Client.new('123') }
|
5
|
+
|
6
|
+
context 'with a cortex error response' do
|
7
|
+
it 'should return the error object' do
|
8
|
+
body = {'error' => 'Validation error or something'}
|
9
|
+
response = OpenStruct.new(:status => 422, :body => body)
|
10
|
+
client.parse_response(response).should == body
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'with a non-cortex error response' do
|
15
|
+
it 'should return a wrapped response' do
|
16
|
+
body = 'Catastrophic error'
|
17
|
+
response = OpenStruct.new(:status => 500, :body => body)
|
18
|
+
parsed = client.parse_response(response)
|
19
|
+
parsed.error.should == body
|
20
|
+
parsed.status.should == 500
|
21
|
+
parsed.original.should == response
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'with a successful response' do
|
26
|
+
it 'should return the parsed body' do
|
27
|
+
body = {:id => 1, title: 'A post'}
|
28
|
+
response = OpenStruct.new(:status => 200, :body => body)
|
29
|
+
client.parse_response(response).should == body
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/spec/users_spec.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cortex::Users do
|
4
|
+
|
5
|
+
let(:client) { Cortex::Client.new('123') }
|
6
|
+
|
7
|
+
describe :me do
|
8
|
+
it 'should correctly make the request' do
|
9
|
+
client.should_receive(:get).with('/users/me').and_return('response')
|
10
|
+
response = client.users.me
|
11
|
+
response.should == 'response'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe :get do
|
16
|
+
it 'should correctly make the request' do
|
17
|
+
client.should_receive(:get).with('/users/1').and_return('response')
|
18
|
+
client.users.get(1).should == 'response'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe :save do
|
23
|
+
context 'with an existing user' do
|
24
|
+
it 'should correctly make the request' do
|
25
|
+
user = {:id => 1, :email => 'user@cbcortex.com'}
|
26
|
+
client.should_receive(:put).with('/users/1', user).and_return('response')
|
27
|
+
response = client.users.save(user)
|
28
|
+
response.should == 'response'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'with a new user' do
|
33
|
+
it 'should correctly make the request' do
|
34
|
+
user = {:email => 'user@cbcortex.com'}
|
35
|
+
client.should_receive(:post).with('/users', user).and_return('response')
|
36
|
+
response = client.users.save(user)
|
37
|
+
response.should == 'response'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cortex-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bennett Goble
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.8.9
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.8.9
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: faraday_middleware
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.9.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.9.0
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- Gemfile
|
76
|
+
- Gemfile.lock
|
77
|
+
- LICENSE
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- cortex-client.gemspec
|
81
|
+
- lib/cortex-client.rb
|
82
|
+
- lib/cortex/client.rb
|
83
|
+
- lib/cortex/connection.rb
|
84
|
+
- lib/cortex/posts.rb
|
85
|
+
- lib/cortex/request.rb
|
86
|
+
- lib/cortex/resource.rb
|
87
|
+
- lib/cortex/users.rb
|
88
|
+
- lib/cortex/version.rb
|
89
|
+
- spec/client_spec.rb
|
90
|
+
- spec/posts_spec.rb
|
91
|
+
- spec/request_spec.rb
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
- spec/users_spec.rb
|
94
|
+
homepage: https://github.com/cb-talent-development/cortex-client
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.2.1
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: Cortex API Client
|
118
|
+
test_files:
|
119
|
+
- spec/client_spec.rb
|
120
|
+
- spec/posts_spec.rb
|
121
|
+
- spec/request_spec.rb
|
122
|
+
- spec/spec_helper.rb
|
123
|
+
- spec/users_spec.rb
|