footrest 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.
- data/lib/footrest.rb +0 -1
- data/lib/footrest/client.rb +25 -4
- data/lib/footrest/connection.rb +1 -2
- data/lib/footrest/request.rb +1 -11
- data/lib/footrest/version.rb +1 -1
- data/spec/footrest/client_spec.rb +23 -2
- data/spec/footrest/request_spec.rb +1 -19
- metadata +2 -3
- data/lib/footrest/configuration.rb +0 -19
data/lib/footrest.rb
CHANGED
data/lib/footrest/client.rb
CHANGED
@@ -1,17 +1,38 @@
|
|
1
1
|
require 'footrest/connection'
|
2
2
|
require 'footrest/request'
|
3
|
-
require '
|
3
|
+
require 'active_support/configurable'
|
4
4
|
|
5
5
|
module Footrest
|
6
6
|
class Client
|
7
7
|
include Footrest::Connection
|
8
8
|
include Footrest::Request
|
9
|
+
include ActiveSupport::Configurable
|
9
10
|
|
10
|
-
|
11
|
+
config_accessor :token
|
12
|
+
config_accessor :prefix
|
13
|
+
config_accessor :logging
|
11
14
|
|
12
15
|
def initialize(options={}, &block)
|
13
|
-
|
14
|
-
|
16
|
+
self.config.merge!(options)
|
17
|
+
yield self if block_given?
|
18
|
+
set_connection(config)
|
19
|
+
end
|
20
|
+
|
21
|
+
def connection(&block)
|
22
|
+
@connection.tap do |conn|
|
23
|
+
yield conn if block_given?
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def fullpath(path)
|
28
|
+
prefix ? join(prefix, path) : path
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
def join(*parts)
|
33
|
+
joined = parts.map{ |p| p.gsub(%r{^/|/$}, '') }.join('/')
|
34
|
+
joined = '/' + joined if parts.first[0] == '/'
|
35
|
+
joined
|
15
36
|
end
|
16
37
|
end
|
17
38
|
end
|
data/lib/footrest/connection.rb
CHANGED
@@ -7,7 +7,7 @@ module Footrest
|
|
7
7
|
|
8
8
|
attr_reader :connection
|
9
9
|
|
10
|
-
def set_connection(config
|
10
|
+
def set_connection(config)
|
11
11
|
@connection = Faraday.new(url: config[:prefix]) do |faraday|
|
12
12
|
faraday.request :multipart
|
13
13
|
faraday.request :url_encoded
|
@@ -19,7 +19,6 @@ module Footrest
|
|
19
19
|
faraday.headers[:accept] = "application/json"
|
20
20
|
faraday.headers[:authorization] = "Bearer #{config[:token]}" if config[:token]
|
21
21
|
faraday.headers[:user_agent] = "Footrest"
|
22
|
-
yield faraday if block_given?
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
data/lib/footrest/request.rb
CHANGED
@@ -1,18 +1,8 @@
|
|
1
1
|
module Footrest
|
2
2
|
module Request
|
3
3
|
|
4
|
-
def config
|
5
|
-
raise "Config should be overridden"
|
6
|
-
end
|
7
|
-
|
8
|
-
def join(*parts)
|
9
|
-
joined = parts.map{ |p| p.gsub(%r{^/|/$}, '') }.join('/')
|
10
|
-
joined = '/' + joined if parts.first[0] == '/'
|
11
|
-
joined
|
12
|
-
end
|
13
|
-
|
14
4
|
def fullpath(path)
|
15
|
-
|
5
|
+
raise "fullpath should be overridden"
|
16
6
|
end
|
17
7
|
|
18
8
|
def delete(path, options={})
|
data/lib/footrest/version.rb
CHANGED
@@ -3,12 +3,33 @@ require 'helper'
|
|
3
3
|
describe Footrest::Client do
|
4
4
|
it "sets the domain" do
|
5
5
|
client = Footrest::Client.new(prefix: "http://domain.test")
|
6
|
-
expect(client.
|
6
|
+
expect(client.prefix).to eq("http://domain.test")
|
7
7
|
end
|
8
8
|
|
9
9
|
it "sets the authtoken" do
|
10
10
|
client = Footrest::Client.new(token: "test_token")
|
11
|
-
expect(client.
|
11
|
+
expect(client.token).to eq("test_token")
|
12
|
+
end
|
13
|
+
|
14
|
+
context "join" do
|
15
|
+
let(:client) { Footrest::Client.new }
|
16
|
+
|
17
|
+
it "retains initial slash" do
|
18
|
+
expect(client.send(:join, '/test', 'path')).to eq('/test/path')
|
19
|
+
end
|
20
|
+
|
21
|
+
it "combines multiple segments" do
|
22
|
+
expect(client.send(:join, 'test', 'path', 'parts')).to eq('test/path/parts')
|
23
|
+
end
|
24
|
+
|
25
|
+
it "respects http://" do
|
26
|
+
expect(client.send(:join, 'http://', 'path')).to eq('http://path')
|
27
|
+
end
|
28
|
+
|
29
|
+
it "keeps slashes within strings" do
|
30
|
+
expect(client.send(:join, 'http://', 'domain', '/path/to/something')).
|
31
|
+
to eq('http://domain/path/to/something')
|
32
|
+
end
|
12
33
|
end
|
13
34
|
|
14
35
|
context "Request" do
|
@@ -3,23 +3,5 @@ require 'helper'
|
|
3
3
|
class RequestHarness; include Footrest::Request; end
|
4
4
|
|
5
5
|
describe Footrest::Request do
|
6
|
-
let(:request) { RequestHarness.new }
|
7
|
-
context "join" do
|
8
|
-
it "retains initial slash" do
|
9
|
-
expect(request.join('/test', 'path')).to eq('/test/path')
|
10
|
-
end
|
11
|
-
|
12
|
-
it "combines multiple segments" do
|
13
|
-
expect(request.join('test', 'path', 'parts')).to eq('test/path/parts')
|
14
|
-
end
|
15
|
-
|
16
|
-
it "respects http://" do
|
17
|
-
expect(request.join('http://', 'path')).to eq('http://path')
|
18
|
-
end
|
19
|
-
|
20
|
-
it "keeps slashes within strings" do
|
21
|
-
expect(request.join('http://', 'domain', '/path/to/something')).
|
22
|
-
to eq('http://domain/path/to/something')
|
23
|
-
end
|
24
|
-
end
|
6
|
+
# let(:request) { RequestHarness.new }
|
25
7
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: footrest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-09-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
@@ -168,7 +168,6 @@ files:
|
|
168
168
|
- footrest.gemspec
|
169
169
|
- lib/faraday/response/raise_footrest_http_error.rb
|
170
170
|
- lib/footrest/client.rb
|
171
|
-
- lib/footrest/configuration.rb
|
172
171
|
- lib/footrest/connection.rb
|
173
172
|
- lib/footrest/http_error.rb
|
174
173
|
- lib/footrest/request.rb
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
require 'active_support/configurable'
|
3
|
-
|
4
|
-
module Footrest
|
5
|
-
include ActiveSupport::Configurable
|
6
|
-
config_accessor :token
|
7
|
-
config_accessor :prefix
|
8
|
-
config_accessor :logging
|
9
|
-
|
10
|
-
def configure
|
11
|
-
yield self
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
Footrest.configure do |config|
|
16
|
-
config.token = nil
|
17
|
-
config.prefix = nil
|
18
|
-
config.logging = false
|
19
|
-
end
|