rest_dsl 0.1.5 → 0.1.7
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.
- checksums.yaml +4 -4
- data/README.md +3 -34
- data/lib/rest_dsl/client.rb +1 -1
- data/lib/rest_dsl/dsl.rb +3 -3
- data/lib/rest_dsl/service_base.rb +4 -7
- data/lib/rest_dsl/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00bb98474257dd1c053d322ec536f3aea68100881db224588f9fd7456d44c611
|
4
|
+
data.tar.gz: 63207297bedf1699569e2e36f010e6169f696436548c25b515dfee8ee329aec3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab7eadd3a565e84ca8747fb347bd265ec2737c1751c5c813cb54979743ff9ee2fbc56304933b7c527f10c46fe76883353cf0c1005b7fd6cea2af6bb555e89d43
|
7
|
+
data.tar.gz: 9cba9233525a7e15e171d3c3b332048b6a27c3cad83b7737ff317ff66d7f9640ad7d97b96dd6b5757e037d1b988f9ebc7c147f2b21ce1ea79e138f581b68589b
|
data/README.md
CHANGED
@@ -20,38 +20,7 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
|
24
|
-
```ruby
|
25
|
-
# some_dir/postman_echo.rb
|
26
|
-
class PostmanEcho < RestDSL::ServiceBase
|
27
|
-
self.service_name = '' # Postman echo has no service name in its url
|
28
|
-
|
29
|
-
rest_call(:get, :echo, 'get')
|
30
|
-
rest_call(:post, :echo, 'post')
|
31
|
-
rest_call(:get, :auth, 'basic-auth')
|
32
|
-
end
|
33
|
-
```
|
34
|
-
and an associated yaml file
|
35
|
-
Note: Uses symbolized keys
|
36
|
-
```yml
|
37
|
-
# some_dir/postman_echo.yml
|
38
|
-
:postman_echo_prod: # The name of my environment
|
39
|
-
:credentials:
|
40
|
-
:user: 'some_user_name'
|
41
|
-
:password: 'some_password'
|
42
|
-
:headers:
|
43
|
-
:some_header: 'foo'
|
44
|
-
```
|
45
|
-
|
46
|
-
Make calls to your hearts content
|
47
|
-
```ruby
|
48
|
-
PostmanEcho.environment = :postman_echo_prod
|
49
|
-
PostmanEcho.get_echo(params: {word: 'cow'})
|
50
|
-
```
|
51
|
-
|
52
|
-
All services are defined as singletons, if you truly need more than one instance for any reason,
|
53
|
-
you can always just dup it into a new constant. See the specs for more advanced use until I get a chance to write up
|
54
|
-
more documentation.
|
23
|
+
[Check Out the Wiki](../../wiki)
|
55
24
|
|
56
25
|
## Development
|
57
26
|
|
@@ -61,7 +30,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
61
30
|
|
62
31
|
## Contributing
|
63
32
|
|
64
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/restDSL/rest_dsl_gem. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
65
34
|
|
66
35
|
## License
|
67
36
|
|
@@ -69,4 +38,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
69
38
|
|
70
39
|
## Code of Conduct
|
71
40
|
|
72
|
-
Everyone interacting in the RestDsl project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
41
|
+
Everyone interacting in the RestDsl project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/restDSL/rest_dsl/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/rest_dsl/client.rb
CHANGED
@@ -33,7 +33,7 @@ module RestDSL
|
|
33
33
|
def execute(method, endpoint, headers, payload: nil, **hash_args, &block)
|
34
34
|
url = "#{@base_url}/#{endpoint}"
|
35
35
|
args = { method: method.to_sym, url: url, headers: headers }
|
36
|
-
args.merge!(payload: payload
|
36
|
+
args.merge!(payload: payload) if payload && method_has_payload?(method)
|
37
37
|
args.merge!(hash_args)
|
38
38
|
|
39
39
|
response =
|
data/lib/rest_dsl/dsl.rb
CHANGED
@@ -25,13 +25,13 @@ module RestDSL
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def from_file(file_name)
|
28
|
-
parser = file_parsers.find{|key, _| key.any? {|file_type| file_name.include? file_type}}[1
|
28
|
+
parser = file_parsers.find{|key, _| key.any? {|file_type| file_name.include? file_type}}&.[](1)
|
29
29
|
result = if parser.eql?(Psych)
|
30
30
|
parser.load_file(file_name)
|
31
|
-
|
31
|
+
elsif parser.eql?(JSON)
|
32
32
|
parser.parse(File.read(file_name))
|
33
33
|
end
|
34
|
-
result ||= File.
|
34
|
+
result ||= File.new(file_name)
|
35
35
|
result
|
36
36
|
rescue Errno::ENOENT => e
|
37
37
|
e.message << " relative to directory #{Dir.pwd}"
|
@@ -18,7 +18,7 @@ module RestDSL
|
|
18
18
|
|
19
19
|
class << self
|
20
20
|
attr_reader :environment, :file_name, :client, :config_file, :last_response
|
21
|
-
attr_writer :headers, :authentication
|
21
|
+
attr_writer :headers, :authentication, :service_name
|
22
22
|
|
23
23
|
# Initializes the singleton
|
24
24
|
def environment=(environment)
|
@@ -27,10 +27,6 @@ module RestDSL
|
|
27
27
|
self
|
28
28
|
end
|
29
29
|
|
30
|
-
def service_name=(name)
|
31
|
-
@service_name = name
|
32
|
-
end
|
33
|
-
|
34
30
|
def rest_call(method, name, url_schema)
|
35
31
|
self.class.define_method("#{method}_#{name}") do |*args, headers: nil, payload: nil, params: nil, url_args: nil, **hash_args|
|
36
32
|
execute_request(method, url_schema.dup, *args, **hash_args, headers: headers, payload: payload, params: params, url_args: url_args)
|
@@ -39,12 +35,13 @@ module RestDSL
|
|
39
35
|
|
40
36
|
# The method wrapped by the methods generated by rest_call, these methods all follow this blueprint
|
41
37
|
# Can by wrapped manually to create more complicated logic than what's supported by the default generators
|
42
|
-
def execute_request(method, rest_method_call, *args, headers: nil, payload: nil, params: nil, url_args: nil, **hash_args, &block)
|
38
|
+
def execute_request(method, rest_method_call, *args, headers: nil, payload: nil, params: nil, url_args: nil, form_data: nil, **hash_args, &block)
|
43
39
|
headers ||= self.headers
|
44
40
|
url_args ||= {}
|
45
41
|
service_name = "#{@service_name}/" unless @service_name&.empty?
|
46
42
|
hash_args.merge!(auth)
|
47
|
-
hash_args.merge!(payload: payload) if payload
|
43
|
+
hash_args.merge!(payload: payload.to_json) if payload
|
44
|
+
hash_args.merge!(payload: form_data) if form_data
|
48
45
|
sub_url_args!(url_args, rest_method_call)
|
49
46
|
arg_list = [method, "#{service_name}#{rest_method_call}#{build_params(params)}", headers]
|
50
47
|
response = @client.execute(*arg_list, *args, **hash_args, &block)
|
data/lib/rest_dsl/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest_dsl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luke Ridge
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|