apidiesel 0.1.1 → 0.1.2
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/apidiesel.gemspec +2 -0
- data/lib/apidiesel/action.rb +15 -4
- data/lib/apidiesel/api.rb +1 -1
- data/lib/apidiesel/dsl.rb +28 -0
- data/lib/apidiesel/handlers/http_request_helper.rb +1 -1
- data/lib/apidiesel/request.rb +1 -1
- data/lib/apidiesel/version.rb +1 -1
- data/lib/apidiesel.rb +1 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94c0a261f4ccfcd6025dfde175bc042a418928b3
|
4
|
+
data.tar.gz: f34f072965617508439a5c676dd04f5fc43c3304
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8f8bb9bd49c8b4ce07c0f22c390d32a82119561f9fc437adf24f954b7ea983cb4c802b43c9c5c3c5c55fff7522bd3a5dedcc09d7d12ff6983a1adfa3a70a96f
|
7
|
+
data.tar.gz: bd2b116e023ff02f989f633f3c806b320b12e4716950ac4d529a23011c4c11d5bdd72a380736e3d9329dc468597e1306c115c6f24717bab846541c95b1c447ec
|
data/apidiesel.gemspec
CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.required_ruby_version = '~> 2.0'
|
22
|
+
|
21
23
|
spec.add_runtime_dependency 'activesupport', '>= 4.2.0'
|
22
24
|
spec.add_runtime_dependency 'httpi', '>= 2.4.1'
|
23
25
|
|
data/lib/apidiesel/action.rb
CHANGED
@@ -7,6 +7,7 @@ module Apidiesel
|
|
7
7
|
# accessors for class instance variables
|
8
8
|
# (class-level variables, not shared with subclasses)
|
9
9
|
class << self
|
10
|
+
attr_reader :url_args
|
10
11
|
|
11
12
|
# Hash for storing validation closures. These closures are called with the request
|
12
13
|
# parameters before the request is made and have the opportunity to check and modify them.
|
@@ -49,11 +50,13 @@ module Apidiesel
|
|
49
50
|
# Falls back to the Api setting if blank.
|
50
51
|
#
|
51
52
|
# @param [String] value
|
52
|
-
def url(value = nil)
|
53
|
+
def url(value = nil, **args)
|
54
|
+
return @url unless value || args.any?
|
55
|
+
|
53
56
|
if value
|
54
|
-
@url = value
|
57
|
+
@url = URI.parse(value)
|
55
58
|
else
|
56
|
-
@
|
59
|
+
@url_args = args
|
57
60
|
end
|
58
61
|
end
|
59
62
|
|
@@ -122,7 +125,15 @@ module Apidiesel
|
|
122
125
|
end
|
123
126
|
|
124
127
|
def url
|
125
|
-
self.class.url || @api.class.url
|
128
|
+
url = self.class.url || @api.class.url
|
129
|
+
|
130
|
+
if self.class.url_args
|
131
|
+
self.class.url_args.each do |key, value|
|
132
|
+
url.send("#{key}=", value)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
url
|
126
137
|
end
|
127
138
|
|
128
139
|
def http_method
|
data/lib/apidiesel/api.rb
CHANGED
data/lib/apidiesel/dsl.rb
CHANGED
@@ -63,6 +63,7 @@ module Apidiesel
|
|
63
63
|
# @param [Hash] *args
|
64
64
|
# @option *args [Boolean] :optional (false) defines whether this parameter may be omitted
|
65
65
|
# @option *args [Symbol] :optional_if_present param_name is optional, if the parameter given here is present instead
|
66
|
+
# @option *args [Symbol] :required_if_present param_name is required if param_name is also present
|
66
67
|
# @option *args [Symbol] :submitted_as submit param_name to the API under the name given here
|
67
68
|
# @option *args [Object] :default a default parameter to be set when no value is specified
|
68
69
|
# @option *args [Enumerable] :allowed_values only accept the values in this Enumerable.
|
@@ -101,6 +102,25 @@ module Apidiesel
|
|
101
102
|
validation_builder(:to_s, param_name, *args)
|
102
103
|
end
|
103
104
|
|
105
|
+
# Defines a date, time or datetime parameter.
|
106
|
+
#
|
107
|
+
#
|
108
|
+
# @example
|
109
|
+
# expects do
|
110
|
+
# datetime :starts_at, format: '%d-%m-%Y'
|
111
|
+
# end
|
112
|
+
#
|
113
|
+
# @param (see #string)
|
114
|
+
# @option *args [String] :format strftime format string
|
115
|
+
# @option (see #string)
|
116
|
+
def datetime(param_name, **args)
|
117
|
+
if args[:format]
|
118
|
+
args[:processor] = ->(value) { value.try(:strftime, args[:format]) }
|
119
|
+
end
|
120
|
+
|
121
|
+
validation_builder(:strftime, param_name, **args)
|
122
|
+
end
|
123
|
+
|
104
124
|
protected
|
105
125
|
|
106
126
|
def validation_builder(duck_typing_check, param_name, *args)
|
@@ -115,6 +135,10 @@ module Apidiesel
|
|
115
135
|
options[:optional] = true unless given_params[ options[:optional_if_present] ].blank?
|
116
136
|
end
|
117
137
|
|
138
|
+
if options.has_key?(:required_if_present)
|
139
|
+
options[:optional] = given_params[ options[:required_if_present] ].present? ? false : true
|
140
|
+
end
|
141
|
+
|
118
142
|
unless options.has_key?(:optional) && options[:optional] == true
|
119
143
|
raise Apidiesel::InputError, "missing arg: #{param_name} - options: #{options.inspect}" unless given_params.has_key?(param_name) && !given_params[param_name].blank?
|
120
144
|
raise Apidiesel::InputError, "invalid arg #{param_name}: must respond to #{duck_typing_check}" unless given_params[param_name].respond_to?(duck_typing_check)
|
@@ -130,6 +154,10 @@ module Apidiesel
|
|
130
154
|
end
|
131
155
|
end
|
132
156
|
|
157
|
+
if options[:processor]
|
158
|
+
given_params[param_name] = options[:processor].call(given_params[param_name])
|
159
|
+
end
|
160
|
+
|
133
161
|
if options[:submitted_as]
|
134
162
|
processed_params[ options[:submitted_as] ] = given_params[param_name]
|
135
163
|
else
|
@@ -11,7 +11,7 @@ module Apidiesel
|
|
11
11
|
# instance, as given to the handlers #run method
|
12
12
|
#
|
13
13
|
def execute_request(request:, payload:, api_config:)
|
14
|
-
http_request = HTTPI::Request.new(request.action.url)
|
14
|
+
http_request = HTTPI::Request.new(request.action.url.try(:to_s))
|
15
15
|
http_request.body = payload
|
16
16
|
|
17
17
|
http_request.auth.ssl.verify_mode = api_config[:ssl_verify_mode] || :peer
|
data/lib/apidiesel/request.rb
CHANGED
data/lib/apidiesel/version.rb
CHANGED
data/lib/apidiesel.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apidiesel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan-Christian Foeh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -103,9 +103,9 @@ require_paths:
|
|
103
103
|
- lib
|
104
104
|
required_ruby_version: !ruby/object:Gem::Requirement
|
105
105
|
requirements:
|
106
|
-
- - "
|
106
|
+
- - "~>"
|
107
107
|
- !ruby/object:Gem::Version
|
108
|
-
version: '0'
|
108
|
+
version: '2.0'
|
109
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
110
|
requirements:
|
111
111
|
- - ">="
|