Skip to content

Commit c71e8ec

Browse files
committed
service params in Ruby
1 parent 3c41ff0 commit c71e8ec

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

templates/php/src/Services/Service.php.twig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use {{ spec.title | caseUcfirst }}\InputFile;
1010
class {{ service.name | caseUcfirst }} extends Service
1111
{
1212
{% if service.globalParams | length %}
13-
1413
{% for parameter in service.globalParams %}
1514
protected {{ parameter.type | typeName }} ${{ parameter.name | caseCamel | escapeKeyword }};
1615

templates/ruby/lib/container/services/service.rb.twig

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33
module {{spec.title | caseUcfirst}}
44
class {{ service.name | caseUcfirst }} < Service
55

6+
{% if service.globalParams | length %}
7+
{% for parameter in service.globalParams %}
8+
@{{ parameter.name | caseSnake | escapeKeyword }}{% if not parameter.required %}: nil{% endif %}
9+
{% endfor %}
10+
11+
def initialize(client, {% for parameter in service.globalParams %}{{ parameter.name | caseSnake | escapeKeyword }}:{% if not parameter.required %} nil{% endif %}{% if not loop.last %}, {% endif %}{% endfor %})
12+
@client = client
13+
{% for parameter in service.globalParams %}
14+
@{{ parameter.name | caseSnake | escapeKeyword }} = {{ parameter.name | caseSnake | escapeKeyword }}
15+
{% endfor %}
16+
end
17+
{% endif %}
18+
619
{% for method in service.methods %}
720
{{ method.description | rubyComment }}
821
#
@@ -11,23 +24,23 @@ module {{spec.title | caseUcfirst}}
1124
{% endfor %}
1225
#
1326
# @return [{{ method.responseModel | caseUcfirst }}]
14-
def {{ method.name | caseSnake }}({% for parameter in method.parameters.all %}{{ parameter.name | caseSnake | escapeKeyword }}:{% if not parameter.required %} nil{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, on_progress: nil{% endif %})
27+
def {{ method.name | caseSnake }}({% for parameter in method.parameters.all | filter((param) => not param.isGlobal) %}{{ parameter.name | caseSnake | escapeKeyword }}:{% if not parameter.required %} nil{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, on_progress: nil{% endif %})
1528
{% for parameter in method.parameters.all %}
1629
{% if parameter.required %}
17-
if {{ parameter.name | caseSnake | escapeKeyword }}.nil?
30+
if {% if parameter.isGlobal %}@{% endif %}{{ parameter.name | caseSnake | escapeKeyword }}.nil?
1831
raise {{spec.title | caseUcfirst}}::Exception.new('Missing required parameter: "{{ parameter.name | caseCamel | escapeKeyword }}"')
1932
end
2033

2134
{% endif %}
2235
{% endfor %}
2336
path = '{{ method.path }}'
2437
{% for parameter in method.parameters.path %}
25-
.gsub('{{ '{' }}{{ parameter.name }}{{ '}' }}', {{ parameter.name | caseSnake | escapeKeyword }})
38+
.gsub('{{ '{' }}{{ parameter.name }}{{ '}' }}', {% if parameter.isGlobal %}@{% endif %}{{ parameter.name | caseSnake | escapeKeyword }})
2639
{% endfor %}
2740

2841
params = {
2942
{% for parameter in method.parameters.query | merge(method.parameters.body) %}
30-
{{ parameter.name }}: {{ parameter.name | caseSnake | escapeKeyword }},
43+
{{ parameter.name }}: {% if parameter.isGlobal %}@{% endif %}{{ parameter.name | caseSnake | escapeKeyword }},
3144
{% endfor %}
3245
}
3346

tests/languages/ruby/tests.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
client = Appwrite::Client.new
44
client.add_header('Origin', 'http://localhost')
55

6-
foo = Appwrite::Foo.new(client)
6+
foo = Appwrite::Foo.new(client, x: 'string')
77
bar = Appwrite::Bar.new(client)
88
general = Appwrite::General.new(client)
99

@@ -12,19 +12,19 @@
1212

1313
# Foo
1414

15-
response = foo.get(x: 'string', y: 123, z: ['string in array'])
15+
response = foo.get(y: 123, z: ['string in array'])
1616
puts response.result
1717

18-
response = foo.post(x: 'string', y: 123, z: ['string in array'])
18+
response = foo.post(y: 123, z: ['string in array'])
1919
puts response.result
2020

21-
response = foo.put(x: 'string', y: 123, z: ['string in array'])
21+
response = foo.put(y: 123, z: ['string in array'])
2222
puts response.result
2323

24-
response = foo.patch(x: 'string', y: 123, z: ['string in array'])
24+
response = foo.patch(y: 123, z: ['string in array'])
2525
puts response.result
2626

27-
response = foo.delete(x: 'string', y: 123, z: ['string in array'])
27+
response = foo.delete(y: 123, z: ['string in array'])
2828
puts response.result
2929

3030
# Bar

0 commit comments

Comments
 (0)