clientura 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +29 -0
- data/.rspec +2 -0
- data/.rubocop.yml +10 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +10 -0
- data/Gemfile +29 -0
- data/Gemfile.lock +166 -0
- data/LICENSE.txt +20 -0
- data/README.md +71 -0
- data/README.rdoc +19 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/clientura.gemspec +114 -0
- data/lib/clientura/client/endpoint.rb +5 -0
- data/lib/clientura/client/middleware_function_context.rb +21 -0
- data/lib/clientura/client/request.rb +34 -0
- data/lib/clientura/client.rb +143 -0
- data/lib/clientura/version.rb +3 -0
- data/lib/clientura.rb +11 -0
- data/spec/clientura/adequate_spec.rb +204 -0
- data/spec/clientura/client_spec.rb +175 -0
- data/spec/clientura_spec.rb +9 -0
- data/spec/spec_helper.rb +64 -0
- data/spec/support/test_server.rb +123 -0
- metadata +309 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6b7bda8b3a6c0e15f5b3418a3cf6ef76f45d9cd8
|
4
|
+
data.tar.gz: 4554b988da1924debfb11617ae933d055433fa10
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 21d8c32b6ecb382d17c9a595d0dc1581fff329c76e5bbf5423e8609186a97e45a8ffbb30731f1a15fef8365c1524d9327c39a63d0df1b79278b42f9b98b0ea13
|
7
|
+
data.tar.gz: 89f8500ad7c15952200fe4c47554bc4a888082ef429e9ccef12fa656a6224aa11a09cf5b02121db8aa5214d1dcd6186ee1a76df2f2c6a50ac97485a1095e37d3
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
---
|
2
|
+
engines:
|
3
|
+
bundler-audit:
|
4
|
+
enabled: true
|
5
|
+
duplication:
|
6
|
+
enabled: true
|
7
|
+
config:
|
8
|
+
languages:
|
9
|
+
- ruby
|
10
|
+
- javascript
|
11
|
+
- python
|
12
|
+
- php
|
13
|
+
fixme:
|
14
|
+
enabled: true
|
15
|
+
rubocop:
|
16
|
+
enabled: true
|
17
|
+
ratings:
|
18
|
+
paths:
|
19
|
+
- "**.inc"
|
20
|
+
- "**.js"
|
21
|
+
- "**.jsx"
|
22
|
+
- "**.module"
|
23
|
+
- "**.php"
|
24
|
+
- "**.py"
|
25
|
+
- "**.rb"
|
26
|
+
exclude_paths:
|
27
|
+
- spec/
|
28
|
+
- Gemfile*
|
29
|
+
- clientura.gemspec
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
clientura
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.2.3
|
data/.travis.yml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
script: bundle exec rake
|
2
|
+
sudo: false
|
3
|
+
# cache: bundler
|
4
|
+
# before_install:
|
5
|
+
# # - export DISPLAY=:99.0
|
6
|
+
# # - sh -e /etc/init.d/xvfb start
|
7
|
+
# - gem install bundler
|
8
|
+
# # before_script:
|
9
|
+
# # - cp config/database.yml.sample config/database.yml
|
10
|
+
# # - psql -c 'create database project_test' -U postgres
|
data/Gemfile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
|
9
|
+
gem 'http', '~> 1.0'
|
10
|
+
gem 'concurrent-ruby', '~> 1.0'
|
11
|
+
gem 'concurrent-ruby-edge', '~> 0.2'
|
12
|
+
gem 'concurrent-ruby-ext', '~> 1.0'
|
13
|
+
gem 'activesupport', '>= 4.0'
|
14
|
+
|
15
|
+
group :development, :test do
|
16
|
+
gem 'rspec'
|
17
|
+
gem 'rdoc'
|
18
|
+
gem 'bundler'
|
19
|
+
gem 'jeweler'
|
20
|
+
gem 'simplecov'
|
21
|
+
gem 'rubocop'
|
22
|
+
gem 'pry'
|
23
|
+
|
24
|
+
gem 'sinatra'
|
25
|
+
gem 'sinatra-contrib'
|
26
|
+
gem 'rack', require: ['rack', 'rack/handler/webrick']
|
27
|
+
gem 'thin'
|
28
|
+
gem 'codeclimate-test-reporter', require: nil
|
29
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (4.2.5.1)
|
5
|
+
i18n (~> 0.7)
|
6
|
+
json (~> 1.7, >= 1.7.7)
|
7
|
+
minitest (~> 5.1)
|
8
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
9
|
+
tzinfo (~> 1.1)
|
10
|
+
addressable (2.4.0)
|
11
|
+
ast (2.2.0)
|
12
|
+
backports (3.6.8)
|
13
|
+
builder (3.2.2)
|
14
|
+
codeclimate-test-reporter (0.5.0)
|
15
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
16
|
+
coderay (1.1.0)
|
17
|
+
concurrent-ruby (1.0.0)
|
18
|
+
concurrent-ruby-edge (0.2.0)
|
19
|
+
concurrent-ruby (~> 1.0.0)
|
20
|
+
concurrent-ruby-ext (1.0.0)
|
21
|
+
concurrent-ruby (~> 1.0.0)
|
22
|
+
daemons (1.2.3)
|
23
|
+
descendants_tracker (0.0.4)
|
24
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
25
|
+
diff-lcs (1.2.5)
|
26
|
+
docile (1.1.5)
|
27
|
+
domain_name (0.5.20160128)
|
28
|
+
unf (>= 0.0.5, < 1.0.0)
|
29
|
+
eventmachine (1.0.9.1)
|
30
|
+
faraday (0.9.2)
|
31
|
+
multipart-post (>= 1.2, < 3)
|
32
|
+
git (1.2.9.1)
|
33
|
+
github_api (0.13.1)
|
34
|
+
addressable (~> 2.4.0)
|
35
|
+
descendants_tracker (~> 0.0.4)
|
36
|
+
faraday (~> 0.8, < 0.10)
|
37
|
+
hashie (>= 3.4)
|
38
|
+
multi_json (>= 1.7.5, < 2.0)
|
39
|
+
oauth2
|
40
|
+
hashie (3.4.3)
|
41
|
+
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
|
+
i18n (0.7.0)
|
52
|
+
jeweler (2.0.1)
|
53
|
+
builder
|
54
|
+
bundler (>= 1.0)
|
55
|
+
git (>= 1.2.5)
|
56
|
+
github_api
|
57
|
+
highline (>= 1.6.15)
|
58
|
+
nokogiri (>= 1.5.10)
|
59
|
+
rake
|
60
|
+
rdoc
|
61
|
+
json (1.8.3)
|
62
|
+
jwt (1.5.1)
|
63
|
+
method_source (0.8.2)
|
64
|
+
mini_portile2 (2.0.0)
|
65
|
+
minitest (5.8.4)
|
66
|
+
multi_json (1.11.2)
|
67
|
+
multi_xml (0.5.5)
|
68
|
+
multipart-post (2.0.0)
|
69
|
+
nokogiri (1.6.7.2)
|
70
|
+
mini_portile2 (~> 2.0.0.rc2)
|
71
|
+
oauth2 (1.1.0)
|
72
|
+
faraday (>= 0.8, < 0.10)
|
73
|
+
jwt (~> 1.0, < 1.5.2)
|
74
|
+
multi_json (~> 1.3)
|
75
|
+
multi_xml (~> 0.5)
|
76
|
+
rack (>= 1.2, < 3)
|
77
|
+
parser (2.3.0.5)
|
78
|
+
ast (~> 2.2)
|
79
|
+
powerpack (0.1.1)
|
80
|
+
pry (0.10.3)
|
81
|
+
coderay (~> 1.1.0)
|
82
|
+
method_source (~> 0.8.1)
|
83
|
+
slop (~> 3.4)
|
84
|
+
rack (1.6.4)
|
85
|
+
rack-protection (1.5.3)
|
86
|
+
rack
|
87
|
+
rack-test (0.6.3)
|
88
|
+
rack (>= 1.0)
|
89
|
+
rainbow (2.1.0)
|
90
|
+
rake (10.5.0)
|
91
|
+
rdoc (4.2.2)
|
92
|
+
json (~> 1.4)
|
93
|
+
rspec (3.4.0)
|
94
|
+
rspec-core (~> 3.4.0)
|
95
|
+
rspec-expectations (~> 3.4.0)
|
96
|
+
rspec-mocks (~> 3.4.0)
|
97
|
+
rspec-core (3.4.2)
|
98
|
+
rspec-support (~> 3.4.0)
|
99
|
+
rspec-expectations (3.4.0)
|
100
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
101
|
+
rspec-support (~> 3.4.0)
|
102
|
+
rspec-mocks (3.4.1)
|
103
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
104
|
+
rspec-support (~> 3.4.0)
|
105
|
+
rspec-support (3.4.1)
|
106
|
+
rubocop (0.37.2)
|
107
|
+
parser (>= 2.3.0.4, < 3.0)
|
108
|
+
powerpack (~> 0.1)
|
109
|
+
rainbow (>= 1.99.1, < 3.0)
|
110
|
+
ruby-progressbar (~> 1.7)
|
111
|
+
unicode-display_width (~> 0.3)
|
112
|
+
ruby-progressbar (1.7.5)
|
113
|
+
simplecov (0.11.2)
|
114
|
+
docile (~> 1.1.0)
|
115
|
+
json (~> 1.8)
|
116
|
+
simplecov-html (~> 0.10.0)
|
117
|
+
simplecov-html (0.10.0)
|
118
|
+
sinatra (1.4.7)
|
119
|
+
rack (~> 1.5)
|
120
|
+
rack-protection (~> 1.4)
|
121
|
+
tilt (>= 1.3, < 3)
|
122
|
+
sinatra-contrib (1.4.6)
|
123
|
+
backports (>= 2.0)
|
124
|
+
multi_json
|
125
|
+
rack-protection
|
126
|
+
rack-test
|
127
|
+
sinatra (~> 1.4.0)
|
128
|
+
tilt (>= 1.3, < 3)
|
129
|
+
slop (3.6.0)
|
130
|
+
thin (1.6.4)
|
131
|
+
daemons (~> 1.0, >= 1.0.9)
|
132
|
+
eventmachine (~> 1.0, >= 1.0.4)
|
133
|
+
rack (~> 1.0)
|
134
|
+
thread_safe (0.3.5)
|
135
|
+
tilt (2.0.2)
|
136
|
+
tzinfo (1.2.2)
|
137
|
+
thread_safe (~> 0.1)
|
138
|
+
unf (0.1.4)
|
139
|
+
unf_ext
|
140
|
+
unf_ext (0.0.7.2)
|
141
|
+
unicode-display_width (0.3.1)
|
142
|
+
|
143
|
+
PLATFORMS
|
144
|
+
ruby
|
145
|
+
|
146
|
+
DEPENDENCIES
|
147
|
+
activesupport (>= 4.0)
|
148
|
+
bundler
|
149
|
+
codeclimate-test-reporter
|
150
|
+
concurrent-ruby (~> 1.0)
|
151
|
+
concurrent-ruby-edge (~> 0.2)
|
152
|
+
concurrent-ruby-ext (~> 1.0)
|
153
|
+
http (~> 1.0)
|
154
|
+
jeweler
|
155
|
+
pry
|
156
|
+
rack
|
157
|
+
rdoc
|
158
|
+
rspec
|
159
|
+
rubocop
|
160
|
+
simplecov
|
161
|
+
sinatra
|
162
|
+
sinatra-contrib
|
163
|
+
thin
|
164
|
+
|
165
|
+
BUNDLED WITH
|
166
|
+
1.11.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2016 Vlad Shmyhlo
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Clientura [![Build Status](https://travis-ci.org/v-shmyhlo/clientura.svg?branch=master)](https://travis-ci.org/v-shmyhlo/clientura) [![Test Coverage](https://codeclimate.com/github/v-shmyhlo/clientura/badges/coverage.svg)](https://codeclimate.com/github/v-shmyhlo/clientura/coverage) [![Code Climate](https://codeclimate.com/github/v-shmyhlo/clientura/badges/gpa.svg)](https://codeclimate.com/github/v-shmyhlo/clientura) [![Issue Count](https://codeclimate.com/github/v-shmyhlo/clientura/badges/issue_count.svg)](https://codeclimate.com/github/v-shmyhlo/clientura)
|
2
|
+
|
3
|
+
### Basic concepts
|
4
|
+
|
5
|
+
Create client class
|
6
|
+
``` ruby
|
7
|
+
class RandomApiClient
|
8
|
+
include Clientura::Client
|
9
|
+
end
|
10
|
+
```
|
11
|
+
Define middleware (blocks which can be composed to configure your request before it is sent)
|
12
|
+
```ruby
|
13
|
+
class RandomApiClient
|
14
|
+
include Clientura::Client
|
15
|
+
|
16
|
+
middleware :with_token, -> { headers(token: client.config[:token]) }
|
17
|
+
end
|
18
|
+
```
|
19
|
+
Define pipes (blocks which can be composed to process response)
|
20
|
+
```ruby
|
21
|
+
class RandomApiClient
|
22
|
+
include Clientura::Client
|
23
|
+
|
24
|
+
middleware :with_token, -> { headers(token: client.config[:token]) }
|
25
|
+
|
26
|
+
pipe :body_retriever, -> (res) { res.body.to_s }
|
27
|
+
pipe :parser, -> (res, parser) { parser.parse res }
|
28
|
+
pipe :data_retriever, -> (res) { res['data'] }
|
29
|
+
end
|
30
|
+
```
|
31
|
+
Compose this stuff!
|
32
|
+
```ruby
|
33
|
+
class RandomApiClient
|
34
|
+
include Clientura::Client
|
35
|
+
|
36
|
+
middleware :with_token, -> { headers(token: client.config[:token]) }
|
37
|
+
|
38
|
+
pipe :body_retriever, -> (res) { res.body.to_s }
|
39
|
+
pipe :parser, -> (res, parser) { parser.parse res }
|
40
|
+
pipe :data_retriever, -> (res) { res['data'] }
|
41
|
+
|
42
|
+
use_middleware :with_token do
|
43
|
+
pipe_through :body_retriever, [:parser, JSON], :data_retriever do
|
44
|
+
get :comments # implicit path 'comments'
|
45
|
+
get :users, path: 'api/users' # explicit path
|
46
|
+
get :user, path: -> (params) { "api/users/#{params[:id]}"} # dynamic path
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
```
|
51
|
+
Also instance should be created with token which will be used by middleware
|
52
|
+
```ruby
|
53
|
+
# ...
|
54
|
+
def initialize(token:)
|
55
|
+
save_config token: token
|
56
|
+
end
|
57
|
+
# ...
|
58
|
+
```
|
59
|
+
Instantiate and use!
|
60
|
+
```ruby
|
61
|
+
client = RandomApiClient.new(token: 'Moms Birthday')
|
62
|
+
client.comments
|
63
|
+
client.comments_promise # yeap, asyncrony baby, backed by concurrent-ruby
|
64
|
+
client.users_promise.value # just retrieve result from promise
|
65
|
+
client.user(id: 1)
|
66
|
+
client.user_promise(id: 1).then do |data_retrieved_through_pipes|
|
67
|
+
# process it asyncronously ...
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
### See more in [spec/clientura/adequate_spec.rb](spec/clientura/adequate_spec.rb)
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= clientura
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to clientura
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2016 Vlad Shmyhlo. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts 'Run `bundle install` to install missing gems'
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification...
|
17
|
+
# see http://guides.rubygems.org/specification-reference/ for more options
|
18
|
+
gem.name = 'clientura'
|
19
|
+
gem.homepage = 'http://github.com/v-shmyhlo/clientura'
|
20
|
+
gem.license = 'MIT'
|
21
|
+
gem.summary = 'DSL for defining HTTP clients'
|
22
|
+
gem.description = 'DSL for defining HTTP clients'
|
23
|
+
gem.email = 'aion.stu@gmail.com'
|
24
|
+
gem.authors = ['Vlad Shmyhlo']
|
25
|
+
# dependencies defined in Gemfile
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'Code coverage detail'
|
36
|
+
task :simplecov do
|
37
|
+
ENV['COVERAGE'] = 'true'
|
38
|
+
Rake::Task['spec'].execute
|
39
|
+
`google-chrome coverage/index.html`
|
40
|
+
end
|
41
|
+
|
42
|
+
task default: :spec
|
43
|
+
|
44
|
+
require 'rdoc/task'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ''
|
47
|
+
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
49
|
+
rdoc.title = "clientura #{version}"
|
50
|
+
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.6
|
data/clientura.gemspec
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: clientura 0.0.6 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "clientura"
|
9
|
+
s.version = "0.0.6"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.authors = ["Vlad Shmyhlo"]
|
14
|
+
s.date = "2016-03-04"
|
15
|
+
s.description = "DSL for defining HTTP clients"
|
16
|
+
s.email = "aion.stu@gmail.com"
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.md",
|
20
|
+
"README.rdoc"
|
21
|
+
]
|
22
|
+
s.files = [
|
23
|
+
".codeclimate.yml",
|
24
|
+
".rspec",
|
25
|
+
".rubocop.yml",
|
26
|
+
".ruby-gemset",
|
27
|
+
".ruby-version",
|
28
|
+
".travis.yml",
|
29
|
+
"Gemfile",
|
30
|
+
"Gemfile.lock",
|
31
|
+
"LICENSE.txt",
|
32
|
+
"README.md",
|
33
|
+
"README.rdoc",
|
34
|
+
"Rakefile",
|
35
|
+
"VERSION",
|
36
|
+
"clientura.gemspec",
|
37
|
+
"lib/clientura.rb",
|
38
|
+
"lib/clientura/client.rb",
|
39
|
+
"lib/clientura/client/endpoint.rb",
|
40
|
+
"lib/clientura/client/middleware_function_context.rb",
|
41
|
+
"lib/clientura/client/request.rb",
|
42
|
+
"lib/clientura/version.rb",
|
43
|
+
"spec/clientura/adequate_spec.rb",
|
44
|
+
"spec/clientura/client_spec.rb",
|
45
|
+
"spec/clientura_spec.rb",
|
46
|
+
"spec/spec_helper.rb",
|
47
|
+
"spec/support/test_server.rb"
|
48
|
+
]
|
49
|
+
s.homepage = "http://github.com/v-shmyhlo/clientura"
|
50
|
+
s.licenses = ["MIT"]
|
51
|
+
s.rubygems_version = "2.4.8"
|
52
|
+
s.summary = "DSL for defining HTTP clients"
|
53
|
+
|
54
|
+
if s.respond_to? :specification_version then
|
55
|
+
s.specification_version = 4
|
56
|
+
|
57
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
58
|
+
s.add_runtime_dependency(%q<http>, ["~> 1.0"])
|
59
|
+
s.add_runtime_dependency(%q<concurrent-ruby>, ["~> 1.0"])
|
60
|
+
s.add_runtime_dependency(%q<concurrent-ruby-edge>, ["~> 0.2"])
|
61
|
+
s.add_runtime_dependency(%q<concurrent-ruby-ext>, ["~> 1.0"])
|
62
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 4.0"])
|
63
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
64
|
+
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
65
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
66
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
67
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
68
|
+
s.add_development_dependency(%q<rubocop>, [">= 0"])
|
69
|
+
s.add_development_dependency(%q<pry>, [">= 0"])
|
70
|
+
s.add_development_dependency(%q<sinatra>, [">= 0"])
|
71
|
+
s.add_development_dependency(%q<sinatra-contrib>, [">= 0"])
|
72
|
+
s.add_development_dependency(%q<rack>, [">= 0"])
|
73
|
+
s.add_development_dependency(%q<thin>, [">= 0"])
|
74
|
+
s.add_development_dependency(%q<codeclimate-test-reporter>, [">= 0"])
|
75
|
+
else
|
76
|
+
s.add_dependency(%q<http>, ["~> 1.0"])
|
77
|
+
s.add_dependency(%q<concurrent-ruby>, ["~> 1.0"])
|
78
|
+
s.add_dependency(%q<concurrent-ruby-edge>, ["~> 0.2"])
|
79
|
+
s.add_dependency(%q<concurrent-ruby-ext>, ["~> 1.0"])
|
80
|
+
s.add_dependency(%q<activesupport>, [">= 4.0"])
|
81
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
82
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
83
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
84
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
85
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
86
|
+
s.add_dependency(%q<rubocop>, [">= 0"])
|
87
|
+
s.add_dependency(%q<pry>, [">= 0"])
|
88
|
+
s.add_dependency(%q<sinatra>, [">= 0"])
|
89
|
+
s.add_dependency(%q<sinatra-contrib>, [">= 0"])
|
90
|
+
s.add_dependency(%q<rack>, [">= 0"])
|
91
|
+
s.add_dependency(%q<thin>, [">= 0"])
|
92
|
+
s.add_dependency(%q<codeclimate-test-reporter>, [">= 0"])
|
93
|
+
end
|
94
|
+
else
|
95
|
+
s.add_dependency(%q<http>, ["~> 1.0"])
|
96
|
+
s.add_dependency(%q<concurrent-ruby>, ["~> 1.0"])
|
97
|
+
s.add_dependency(%q<concurrent-ruby-edge>, ["~> 0.2"])
|
98
|
+
s.add_dependency(%q<concurrent-ruby-ext>, ["~> 1.0"])
|
99
|
+
s.add_dependency(%q<activesupport>, [">= 4.0"])
|
100
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
101
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
102
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
103
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
104
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
105
|
+
s.add_dependency(%q<rubocop>, [">= 0"])
|
106
|
+
s.add_dependency(%q<pry>, [">= 0"])
|
107
|
+
s.add_dependency(%q<sinatra>, [">= 0"])
|
108
|
+
s.add_dependency(%q<sinatra-contrib>, [">= 0"])
|
109
|
+
s.add_dependency(%q<rack>, [">= 0"])
|
110
|
+
s.add_dependency(%q<thin>, [">= 0"])
|
111
|
+
s.add_dependency(%q<codeclimate-test-reporter>, [">= 0"])
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Clientura
|
2
|
+
module Client
|
3
|
+
class MiddlewareFunctionContext < SimpleDelegator
|
4
|
+
attr_accessor :client, :args
|
5
|
+
|
6
|
+
def initialize(request:, client:, args:, callable:, config:)
|
7
|
+
@request = request
|
8
|
+
@client = client
|
9
|
+
@args = args
|
10
|
+
@callable = callable
|
11
|
+
@config = config
|
12
|
+
|
13
|
+
super @request
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
instance_exec(*@config, &@callable)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Clientura
|
2
|
+
module Client
|
3
|
+
class Request < SimpleDelegator
|
4
|
+
attr_reader :config, :http
|
5
|
+
|
6
|
+
def initialize(http = HTTP.headers({}),
|
7
|
+
config = { uri: '', params: {}, json: nil })
|
8
|
+
super http
|
9
|
+
@http = http
|
10
|
+
@config = config
|
11
|
+
end
|
12
|
+
|
13
|
+
def update(key)
|
14
|
+
Request.new http, config.merge(key => yield(config[key]))
|
15
|
+
end
|
16
|
+
|
17
|
+
[:get, :post, :put, :patch, :delete].each do |verb|
|
18
|
+
define_method verb do |path, **opts|
|
19
|
+
super(*build_request_arguments(path, opts))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def build_request_arguments(path, **opts)
|
24
|
+
opts[:params] = config.fetch(:params) if config[:params].present?
|
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)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|