rest_dsl 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f39a5eba524c66c73ddfb7050bab857d4f37913fd5f10d4367b27a3f4141f87
4
- data.tar.gz: c21b310943a34d6aaa9b8ef7a59faccdc9368ea8315d36a0c019278072de1662
3
+ metadata.gz: 065d9784032984b8e45ec01e90b36b210c43fa389c480ac1374a5c9eae0ec46d
4
+ data.tar.gz: 2abc894bf2552ac5f4f24776c41aa3fc00368d2b15f23f17714d440a3dba92ab
5
5
  SHA512:
6
- metadata.gz: c041761b8b59888857aa450c69b051d97c3f44021c9ca00bbeb90a45cecd199f06789e65129b97923668440531e3cfa3884dcdc50eb3df51735c696c0ca70113
7
- data.tar.gz: 3446e2643304cd1152612e7695821a4c26765134a8463aae77539a0d07580360f3c71b7495a12d727949d69ce29056ace5db1555572d2a204f831e07644ad586
6
+ metadata.gz: 8dea12da4cedebbb131c12940b00749f0bbaeae85a333de4fe3cf09687e2019faf5f3a1d57dbbdc1440577e62392d02d1cacc66df0ab766c1661030ce9e34d56
7
+ data.tar.gz: 327df61aabf9f0a680243cb0870a9df97f2be3b25d4b64a3ede13308c13f2e2a465818f63157c3b53f3c4e92f9c6f802bfcf157feb5264131cae313d82fe6e6a
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # RestDsl
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rest_dsl`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ A simple dsl for defining rest service consumers in applications. Mostly intended for test framework use.
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,7 +20,38 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ Create a service class
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.
26
55
 
27
56
  ## Development
28
57
 
@@ -32,7 +61,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
61
 
33
62
  ## Contributing
34
63
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rest_dsl. 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.
64
+ Bug reports and pull requests are welcome on GitHub at https://github.com/castone22/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.
36
65
 
37
66
  ## License
38
67
 
@@ -0,0 +1,53 @@
1
+ require 'json'
2
+ require 'psych'
3
+
4
+ module RestDSL
5
+
6
+ ##
7
+ # A collection of DSL extensions for use with various worlds to allow the use of some simpler
8
+ # dsl language in them.
9
+ #
10
+ # For rspec, in spec helper add config.extend RestDSL::DSLExtensions::<<extension>>
11
+ # In cucumber World(RestDSL::DSLExtensions::<<extension>>)
12
+ # Each extension can also be extended onto a class like normal to use it in that class
13
+ module DSLExtensions
14
+
15
+ ##
16
+ # Adds a DSL method for parsing information from a file, parser list can be overridden by setting
17
+ # @file_parsers. If no parser is designed, for the file extension, loads the file as plain text
18
+ module FromFile
19
+
20
+ def self.extended(clazz)
21
+ clazz.instance_eval do
22
+ @file_parsers = {
23
+ %w[.json] => JSON,
24
+ %w[.yml .yaml] => Psych
25
+ }
26
+ end
27
+ end
28
+
29
+ def self.included(clazz)
30
+ clazz.instance_eval do
31
+ @file_parsers = {
32
+ %w[.json] => JSON,
33
+ %w[.yml .yaml] => Psych
34
+ }
35
+ end
36
+ end
37
+
38
+ def from_file(file_name)
39
+ parser = @file_parsers.find{|key, _| key.any? {|file_type| file_name.include? file_type}}[1]
40
+ result = if parser.eql?(Psych)
41
+ parser.load_file(file_name)
42
+ else # Most non-yaml parsers in ruby work like the json one so lets make it be the default.
43
+ parser.parse(File.read(file_name))
44
+ end
45
+ result ||= File.read(file_name)
46
+ result
47
+ rescue Errno::ENOENT => e
48
+ e.message << " relative to directory #{Dir.pwd}"
49
+ raise e
50
+ end
51
+ end
52
+ end
53
+ end
@@ -1,3 +1,3 @@
1
1
  module RestDSL
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
data/lib/rest_dsl.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require_relative 'rest_dsl/version'
2
2
  require_relative 'rest_dsl/errors'
3
+ require_relative 'rest_dsl/dsl'
3
4
  require 'psych'
4
5
  require 'json'
5
6
 
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.0
4
+ version: 0.1.1
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-07-31 00:00:00.000000000 Z
11
+ date: 2019-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -85,6 +85,7 @@ files:
85
85
  - bin/setup
86
86
  - lib/rest_dsl.rb
87
87
  - lib/rest_dsl/client.rb
88
+ - lib/rest_dsl/dsl.rb
88
89
  - lib/rest_dsl/errors.rb
89
90
  - lib/rest_dsl/service_base.rb
90
91
  - lib/rest_dsl/version.rb