File tree 8 files changed +46
-14
lines changed
8 files changed +46
-14
lines changed Original file line number Diff line number Diff line change
1
+ root = true
2
+
3
+ [* ]
4
+ indent_style = space
5
+ indent_size = 2
6
+ end_of_line = lf
7
+ insert_final_newline = true
8
+ charset = utf-8
9
+ trim_trailing_whitespace = true
Original file line number Diff line number Diff line change @@ -17,8 +17,9 @@ Gem::Specification.new do |s|
17
17
s . add_development_dependency 'rake' , '~> 12.0'
18
18
s . add_development_dependency 'rspec' , '~> 3.5'
19
19
s . add_development_dependency 'mocha' , '~> 1.2'
20
+ s . add_development_dependency 'webmock' , '~> 2.3'
20
21
21
- s . add_dependency 'oauth2' , '~> 1.1.0 '
22
+ s . add_dependency 'oauth2' , '~> 1.1'
22
23
s . add_dependency 'faraday' , '~> 0.9'
23
24
s . add_dependency 'faraday_middleware' , '~> 0.10'
24
25
s . add_dependency 'addressable' , '~> 2.5'
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ class Client
20
20
include Cortex ::Request
21
21
22
22
def initialize ( hasharg )
23
- @base_url = hasharg [ :base_url ] || 'https ://cbcortex.com /api/v1'
23
+ @base_url = hasharg [ :base_url ] || 'http ://cortex.dev /api/v1'
24
24
if hasharg . has_key? :access_token
25
25
@access_token = hasharg [ :access_token ]
26
26
else
Original file line number Diff line number Diff line change 1
1
require 'faraday'
2
2
require 'faraday_middleware'
3
- require 'addressable/uri'
4
3
require 'hashie/mash'
5
4
6
5
require 'cortex/faraday_middleware/response_failures'
6
+ require 'cortex/faraday_middleware/normalize_uri_path'
7
7
8
8
module Cortex
9
9
module Connection
@@ -22,13 +22,13 @@ def connection
22
22
Faraday ::Utils . default_uri_parser = Addressable ::URI
23
23
Faraday . new options do |conn |
24
24
## Request middleware first:
25
- conn . use ::FaradayMiddleware ::OAuth2 , access_token . is_a? ( OAuth2 ::AccessToken ) ? access_token . token : access_token
25
+ conn . use Cortex ::FaradayMiddleware ::NormalizeURIPath
26
+ conn . request :oauth2 , access_token . is_a? ( OAuth2 ::AccessToken ) ? access_token . token : access_token
27
+ conn . request :json
26
28
27
29
## Response middleware second:
28
- conn . use :: FaradayMiddleware :: Mashify
30
+ conn . response :mashify
29
31
conn . use Cortex ::FaradayMiddleware ::ResponseFailures
30
-
31
- conn . request :json
32
32
conn . response :json , :content_type => /\b json$/
33
33
34
34
## Adapter always last:
Original file line number Diff line number Diff line change
1
+ require 'faraday/middleware'
2
+ require 'addressable/uri'
3
+
4
+ module Cortex
5
+ module FaradayMiddleware
6
+ class NormalizeURIPath < Faraday ::Middleware
7
+ def call ( env )
8
+ env [ :url ] . path = Addressable ::URI . normalize_component ( env [ :url ] . path )
9
+
10
+ @app . call env
11
+ end
12
+ end
13
+ end
14
+ end
Original file line number Diff line number Diff line change 1
1
module Cortex
2
- VERSION = '0.10.0 '
2
+ VERSION = '0.10.1 '
3
3
end
Original file line number Diff line number Diff line change 1
1
require 'spec_helper'
2
2
3
3
RSpec . describe Cortex ::Posts do
4
-
5
- # TODO: Stub out Faraday somewhere. See: https://github.com/lostisland/faraday#using-faraday-for-testing
6
4
let ( :client ) { Cortex ::Client . new ( access_token : '123' ) }
7
5
8
6
describe :get do
18
16
expect ( client . posts . get_published ( 1 ) ) . to eq ( 'response' )
19
17
end
20
18
21
- it 'should work with special characters' do
22
- expect { client . posts . get_published ( '1 post' ) } . to_not raise_error ( URI ::InvalidURIError )
19
+ context 'with special characters' do
20
+ let! ( :stubbed_request ) { stub_request ( :get , 'http://cortex.dev/api/v1/posts/feed/1%20post?access_token=123' ) }
21
+
22
+ it 'should correctly make the request' do
23
+ client . posts . get_published ( '1 post' )
24
+ expect ( stubbed_request ) . to have_been_made . once
25
+ end
26
+
27
+ it 'should not be considered an invalid URI' do
28
+ expect { client . posts . get_published ( '1 post' ) } . to_not raise_error ( URI ::InvalidURIError )
29
+ end
23
30
end
24
31
end
25
32
Original file line number Diff line number Diff line change 1
- require 'ostruct'
1
+ require 'webmock/rspec'
2
+
2
3
require_relative '../lib/cortex-client'
3
4
4
5
RSpec . configure do |config |
5
6
config . mock_framework = :mocha
6
- end
7
+ end
You can’t perform that action at this time.
0 commit comments