clientura 0.0.7 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +6 -15
- data/VERSION +1 -1
- data/clientura.gemspec +6 -6
- data/lib/clientura/client/request.rb +13 -19
- data/lib/clientura/client.rb +13 -9
- data/lib/clientura.rb +1 -1
- data/spec/clientura/adequate_spec.rb +4 -4
- 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: be51c881a9b38b3acadcb17ec24e188e6482c2ea
|
4
|
+
data.tar.gz: b67af8babfc9eeef876ca57d7bca2c7631b11951
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a816ec51add374c410513923b9d079d96a04ab16d914e6411ee84beab0c75758d3518dbfdcdc7c79c69f6ad864cfc773a46f1c6f4cfdc66a250e343196f8910
|
7
|
+
data.tar.gz: 80513c9a5c307c6156232766c829a305f057f137bf9c0fae66a5485cc5f8c00cb5dea1d05e60944261aae20230f01de74e2aa9767227fede48b882d669492c18
|
data/Gemfile
CHANGED
@@ -6,7 +6,7 @@ source 'http://rubygems.org'
|
|
6
6
|
# Add dependencies to develop your gem here.
|
7
7
|
# Include everything needed to run rake, tests, features, etc.
|
8
8
|
|
9
|
-
gem '
|
9
|
+
gem 'typhoeus', '~> 1.0'
|
10
10
|
gem 'concurrent-ruby', '~> 1.0'
|
11
11
|
gem 'concurrent-ruby-edge', '~> 0.2'
|
12
12
|
gem 'concurrent-ruby-ext', '~> 1.0'
|
data/Gemfile.lock
CHANGED
@@ -24,11 +24,12 @@ GEM
|
|
24
24
|
thread_safe (~> 0.3, >= 0.3.1)
|
25
25
|
diff-lcs (1.2.5)
|
26
26
|
docile (1.1.5)
|
27
|
-
|
28
|
-
|
27
|
+
ethon (0.8.1)
|
28
|
+
ffi (>= 1.3.0)
|
29
29
|
eventmachine (1.0.9.1)
|
30
30
|
faraday (0.9.2)
|
31
31
|
multipart-post (>= 1.2, < 3)
|
32
|
+
ffi (1.9.10)
|
32
33
|
git (1.2.9.1)
|
33
34
|
github_api (0.13.1)
|
34
35
|
addressable (~> 2.4.0)
|
@@ -39,15 +40,6 @@ GEM
|
|
39
40
|
oauth2
|
40
41
|
hashie (3.4.3)
|
41
42
|
highline (1.7.8)
|
42
|
-
http (1.0.2)
|
43
|
-
addressable (~> 2.3)
|
44
|
-
http-cookie (~> 1.0)
|
45
|
-
http-form_data (~> 1.0.1)
|
46
|
-
http_parser.rb (~> 0.6.0)
|
47
|
-
http-cookie (1.0.2)
|
48
|
-
domain_name (~> 0.5)
|
49
|
-
http-form_data (1.0.1)
|
50
|
-
http_parser.rb (0.6.0)
|
51
43
|
i18n (0.7.0)
|
52
44
|
jeweler (2.0.1)
|
53
45
|
builder
|
@@ -133,11 +125,10 @@ GEM
|
|
133
125
|
rack (~> 1.0)
|
134
126
|
thread_safe (0.3.5)
|
135
127
|
tilt (2.0.2)
|
128
|
+
typhoeus (1.0.1)
|
129
|
+
ethon (>= 0.8.0)
|
136
130
|
tzinfo (1.2.2)
|
137
131
|
thread_safe (~> 0.1)
|
138
|
-
unf (0.1.4)
|
139
|
-
unf_ext
|
140
|
-
unf_ext (0.0.7.2)
|
141
132
|
unicode-display_width (0.3.1)
|
142
133
|
|
143
134
|
PLATFORMS
|
@@ -150,7 +141,6 @@ DEPENDENCIES
|
|
150
141
|
concurrent-ruby (~> 1.0)
|
151
142
|
concurrent-ruby-edge (~> 0.2)
|
152
143
|
concurrent-ruby-ext (~> 1.0)
|
153
|
-
http (~> 1.0)
|
154
144
|
jeweler
|
155
145
|
pry
|
156
146
|
rack
|
@@ -161,6 +151,7 @@ DEPENDENCIES
|
|
161
151
|
sinatra
|
162
152
|
sinatra-contrib
|
163
153
|
thin
|
154
|
+
typhoeus (~> 1.0)
|
164
155
|
|
165
156
|
BUNDLED WITH
|
166
157
|
1.11.2
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/clientura.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: clientura 0.0
|
5
|
+
# stub: clientura 0.1.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "clientura"
|
9
|
-
s.version = "0.0
|
9
|
+
s.version = "0.1.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Vlad Shmyhlo"]
|
14
|
-
s.date = "2016-
|
14
|
+
s.date = "2016-04-02"
|
15
15
|
s.description = "DSL for defining HTTP clients"
|
16
16
|
s.email = "aion.stu@gmail.com"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -55,7 +55,7 @@ Gem::Specification.new do |s|
|
|
55
55
|
s.specification_version = 4
|
56
56
|
|
57
57
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
58
|
-
s.add_runtime_dependency(%q<
|
58
|
+
s.add_runtime_dependency(%q<typhoeus>, ["~> 1.0"])
|
59
59
|
s.add_runtime_dependency(%q<concurrent-ruby>, ["~> 1.0"])
|
60
60
|
s.add_runtime_dependency(%q<concurrent-ruby-edge>, ["~> 0.2"])
|
61
61
|
s.add_runtime_dependency(%q<concurrent-ruby-ext>, ["~> 1.0"])
|
@@ -73,7 +73,7 @@ Gem::Specification.new do |s|
|
|
73
73
|
s.add_development_dependency(%q<thin>, [">= 0"])
|
74
74
|
s.add_development_dependency(%q<codeclimate-test-reporter>, [">= 0"])
|
75
75
|
else
|
76
|
-
s.add_dependency(%q<
|
76
|
+
s.add_dependency(%q<typhoeus>, ["~> 1.0"])
|
77
77
|
s.add_dependency(%q<concurrent-ruby>, ["~> 1.0"])
|
78
78
|
s.add_dependency(%q<concurrent-ruby-edge>, ["~> 0.2"])
|
79
79
|
s.add_dependency(%q<concurrent-ruby-ext>, ["~> 1.0"])
|
@@ -92,7 +92,7 @@ Gem::Specification.new do |s|
|
|
92
92
|
s.add_dependency(%q<codeclimate-test-reporter>, [">= 0"])
|
93
93
|
end
|
94
94
|
else
|
95
|
-
s.add_dependency(%q<
|
95
|
+
s.add_dependency(%q<typhoeus>, ["~> 1.0"])
|
96
96
|
s.add_dependency(%q<concurrent-ruby>, ["~> 1.0"])
|
97
97
|
s.add_dependency(%q<concurrent-ruby-edge>, ["~> 0.2"])
|
98
98
|
s.add_dependency(%q<concurrent-ruby-ext>, ["~> 1.0"])
|
@@ -1,33 +1,27 @@
|
|
1
1
|
module Clientura
|
2
2
|
module Client
|
3
|
-
class Request
|
3
|
+
class Request
|
4
4
|
attr_reader :config, :http
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
|
8
|
-
super http
|
9
|
-
@http = http
|
10
|
-
@config = config
|
6
|
+
def initialize(options = { uri: '', headers: {}, params: {} })
|
7
|
+
@options = options
|
11
8
|
end
|
12
9
|
|
13
10
|
def update(key)
|
14
|
-
Request.new
|
11
|
+
Request.new @options.merge key => yield(@options[key])
|
15
12
|
end
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
def call
|
15
|
+
uri = @options[:uri]
|
16
|
+
path = @options[:path]
|
17
|
+
json = @options[:json]
|
18
|
+
options = @options.slice(*@options.keys - [:uri, :path, :json])
|
19
|
+
options[:body] = JSON.dump(json) if json
|
20
|
+
Typhoeus::Request.new(URI.join(uri, path), options).run
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
24
|
-
|
25
|
-
opts[:json] = config.fetch(:json) if config[:json].present?
|
26
|
-
[URI.join(config.fetch(:uri), path), opts]
|
27
|
-
end
|
28
|
-
|
29
|
-
def headers(*args)
|
30
|
-
Request.new(http.headers(*args), config)
|
23
|
+
def headers(args)
|
24
|
+
update(:headers) { |h| h.merge args }
|
31
25
|
end
|
32
26
|
end
|
33
27
|
end
|
data/lib/clientura/client.rb
CHANGED
@@ -28,9 +28,17 @@ module Clientura
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
+
def normalize_path(path)
|
32
|
+
if path.respond_to?(:call)
|
33
|
+
path
|
34
|
+
else
|
35
|
+
-> (_) { path }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
31
39
|
def register_endpoint(name, verb:, path:)
|
32
40
|
registered_endpoints[name] = Endpoint.new verb,
|
33
|
-
path,
|
41
|
+
normalize_path(path),
|
34
42
|
[*@middleware_context],
|
35
43
|
[*@pipes_context]
|
36
44
|
|
@@ -106,13 +114,7 @@ module Clientura
|
|
106
114
|
end
|
107
115
|
|
108
116
|
def call_endpoint(name_, args)
|
109
|
-
endpoint = registered_endpoints.fetch
|
110
|
-
|
111
|
-
path = if endpoint.path.respond_to?(:call)
|
112
|
-
endpoint.path.call(args)
|
113
|
-
else
|
114
|
-
endpoint.path
|
115
|
-
end
|
117
|
+
endpoint = registered_endpoints.fetch name_
|
116
118
|
|
117
119
|
middlewares = endpoint.middleware.map do |name:, config:|
|
118
120
|
{ callable: registered_middleware.fetch(name), config: config }
|
@@ -128,7 +130,9 @@ module Clientura
|
|
128
130
|
middleware.call
|
129
131
|
end
|
130
132
|
|
131
|
-
|
133
|
+
request = request.update(:method) { endpoint.verb }
|
134
|
+
request = request.update(:path) { endpoint.path.call(args) }
|
135
|
+
response = request.call
|
132
136
|
|
133
137
|
endpoints = endpoint.pipes.map do |name:, config:|
|
134
138
|
-> (res) { registered_pipes.fetch(name).call(res, *config) }
|
data/lib/clientura.rb
CHANGED
@@ -75,7 +75,7 @@ describe 'Ability to use this for solving real world problems' do
|
|
75
75
|
end
|
76
76
|
|
77
77
|
describe 'My wish to see this at least working' do
|
78
|
-
subject { super().root.
|
78
|
+
subject { super().root.code }
|
79
79
|
|
80
80
|
it { should eq 200 }
|
81
81
|
end
|
@@ -125,7 +125,7 @@ describe 'Ability to use this for solving real world problems' do
|
|
125
125
|
it { should be_pending }
|
126
126
|
|
127
127
|
it 'has correct value' do
|
128
|
-
expect(subject.value.
|
128
|
+
expect(subject.value.code).to eq 200
|
129
129
|
end
|
130
130
|
|
131
131
|
context 'when awaited' do
|
@@ -161,7 +161,7 @@ describe 'Ability to use this for solving real world problems' do
|
|
161
161
|
end
|
162
162
|
|
163
163
|
describe 'My desire to pass some token in header' do
|
164
|
-
subject { super().pass_token.
|
164
|
+
subject { super().pass_token.code }
|
165
165
|
|
166
166
|
let(:client_config) { super().merge token: token }
|
167
167
|
|
@@ -197,7 +197,7 @@ describe 'Ability to use this for solving real world problems' do
|
|
197
197
|
end
|
198
198
|
|
199
199
|
describe 'My desire to namespace routes' do
|
200
|
-
subject { super().namespaced.
|
200
|
+
subject { super().namespaced.code }
|
201
201
|
|
202
202
|
it { should eq 200 }
|
203
203
|
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clientura
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vlad Shmyhlo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: typhoeus
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|