onesky-ruby 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -3
- data/README.md +1 -1
- data/lib/onesky.rb +0 -1
- data/lib/onesky/version.rb +1 -1
- data/onesky-ruby.gemspec +4 -2
- data/spec/onesky/helpers/request_spec.rb +11 -11
- data/spec/onesky/resources/locale_spec.rb +2 -2
- data/spec/onesky/resources/project/base_spec.rb +4 -4
- data/spec/onesky/resources/project/file_spec.rb +6 -6
- data/spec/onesky/resources/project/import_task_spec.rb +4 -4
- data/spec/onesky/resources/project/order_spec.rb +6 -6
- data/spec/onesky/resources/project/translation_spec.rb +2 -2
- data/spec/onesky/resources/project_group_spec.rb +10 -10
- data/spec/onesky/resources/project_spec.rb +4 -4
- data/spec/onesky/resources/project_type_spec.rb +2 -2
- metadata +8 -9
- data/lib/onesky/restclient.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64e4ff02d4e28912355f0124620cd881adbc699e
|
4
|
+
data.tar.gz: b7957e8dfb1b8623ff8e46b442bd3adf4625feaf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18f1be2f81c74f1bd1c76f160264ecd3641a1544abc785a260bf6f3e3fe97fe757ff5baa23f40dc9b2fe1f9e9b27486c2bd544e05b334ca100cad4c042292437
|
7
|
+
data.tar.gz: 36fd81e45173e872b938dbf8a3c889c44b963bf00b42fd977ac438963c62a83782beb4f4ba63b44b89f34856c38a42d42ae53a41d05328734720d765bb3be684
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/onesky/onesky-ruby.svg)](https://travis-ci.org/onesky/onesky-ruby)
|
4
4
|
|
5
|
-
Ruby client for [OneSky](http://www.oneskyapp.com) [Platform API](/onesky/api-documentation-platform)
|
5
|
+
Ruby client for [OneSky](http://www.oneskyapp.com) [Platform API](https://github.com/onesky/api-documentation-platform)
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
data/lib/onesky.rb
CHANGED
data/lib/onesky/version.rb
CHANGED
data/onesky-ruby.gemspec
CHANGED
@@ -13,15 +13,17 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = "http://github.com/onesky/onesky-ruby"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
+
spec.required_ruby_version = '>= 2.0.0'
|
17
|
+
|
16
18
|
spec.files = `git ls-files -z`.split("\x0")
|
17
19
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
20
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
21
|
spec.require_paths = ["lib"]
|
20
22
|
|
21
|
-
spec.add_dependency 'rest-client', '~>
|
23
|
+
spec.add_dependency 'rest-client', '~> 2.0'
|
22
24
|
|
23
25
|
spec.add_development_dependency "bundler", "~> 1.5"
|
24
26
|
spec.add_development_dependency "rake", "~> 10.3"
|
25
27
|
spec.add_development_dependency "rspec", "~> 3.1.0"
|
26
|
-
spec.add_development_dependency "webmock", "~>
|
28
|
+
spec.add_development_dependency "webmock", "~> 3.0"
|
27
29
|
end
|
@@ -13,8 +13,8 @@ describe 'Helpers::Request' do
|
|
13
13
|
it 'should initial request with required headers' do
|
14
14
|
stub_request(:get, full_path_with_auth_hash("/locales", api_key, api_secret))
|
15
15
|
.with(headers: http_header)
|
16
|
-
.to_return(body: {})
|
17
|
-
expect(client.list_locale).to be_an_instance_of(
|
16
|
+
.to_return(body: "{}")
|
17
|
+
expect(client.list_locale).to be_an_instance_of(RestClient::Response)
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'should raise error for error response code' do
|
@@ -28,8 +28,8 @@ describe 'Helpers::Request' do
|
|
28
28
|
it 'should initial request with required headers' do
|
29
29
|
stub_request(:post, full_path_with_auth_hash("/project-groups", api_key, api_secret))
|
30
30
|
.with(headers: http_header)
|
31
|
-
.to_return(body: {})
|
32
|
-
expect(client.create_project_group({name: 'TEST'})).to be_an_instance_of(
|
31
|
+
.to_return(body: "{}")
|
32
|
+
expect(client.create_project_group({name: 'TEST'})).to be_an_instance_of(RestClient::Response)
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'should return response on error' do
|
@@ -43,13 +43,13 @@ describe 'Helpers::Request' do
|
|
43
43
|
it 'should initial request with required headers' do
|
44
44
|
stub_request(:post, full_path_with_auth_hash("/projects/#{project_id}/files", api_key, api_secret))
|
45
45
|
.with(headers: {'Onesky-Plugin' => 'ruby-wrapper'})
|
46
|
-
.to_return(body: {})
|
47
|
-
expect(project.upload_file({file: 'spec/fixture/en.yml', file_format: 'RUBY_YAML'})).to be_an_instance_of(
|
46
|
+
.to_return(body: "{}")
|
47
|
+
expect(project.upload_file({file: 'spec/fixture/en.yml', file_format: 'RUBY_YAML'})).to be_an_instance_of(RestClient::Response)
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'should return response on error' do
|
51
51
|
stub_request(:post, full_path_with_auth_hash("/projects/#{project_id}/files", api_key, api_secret))
|
52
|
-
.to_return(status: 400, body: {meta: {code: 400, message: 'error message'}}.to_json)
|
52
|
+
.to_return(status: 400, body: {meta: {code: 400, message: 'error message'}}.to_json.to_s)
|
53
53
|
expect {project.upload_file({file: 'spec/fixture/en.yml', file_format: 'RUBY_YAML'})}.to raise_error(Onesky::Errors::BadRequestError, '400 Bad Request - error message')
|
54
54
|
end
|
55
55
|
end
|
@@ -58,8 +58,8 @@ describe 'Helpers::Request' do
|
|
58
58
|
it 'should initial request with required headers' do
|
59
59
|
stub_request(:put, full_path_with_auth_hash("/projects/#{project_id}", api_key, api_secret))
|
60
60
|
.with(headers: http_header)
|
61
|
-
.to_return(body: {})
|
62
|
-
expect(project.update({name: 'NEW NAME'})).to be_an_instance_of(
|
61
|
+
.to_return(body: "{}")
|
62
|
+
expect(project.update({name: 'NEW NAME'})).to be_an_instance_of(RestClient::Response)
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'should return response on error' do
|
@@ -73,8 +73,8 @@ describe 'Helpers::Request' do
|
|
73
73
|
it 'should initial request with required headers' do
|
74
74
|
stub_request(:delete, full_path_with_auth_hash("/projects/#{project_id}", api_key, api_secret))
|
75
75
|
.with(headers: http_header)
|
76
|
-
.to_return(body: {})
|
77
|
-
expect(project.remove).to be_an_instance_of(
|
76
|
+
.to_return(body: "{}")
|
77
|
+
expect(project.remove).to be_an_instance_of(RestClient::Response)
|
78
78
|
end
|
79
79
|
|
80
80
|
it 'should return response on error' do
|
@@ -9,9 +9,9 @@ describe 'Locale' do
|
|
9
9
|
describe 'list_locale' do
|
10
10
|
it 'should list all available locales' do
|
11
11
|
stub_request(:get, full_path_with_auth_hash('/locales', api_key, api_secret))
|
12
|
-
.to_return(body: {})
|
12
|
+
.to_return(body: "{}")
|
13
13
|
response = client.list_locale
|
14
|
-
expect(response).to be_an_instance_of(
|
14
|
+
expect(response).to be_an_instance_of(RestClient::Response)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -11,9 +11,9 @@ describe 'Project::Base' do
|
|
11
11
|
describe 'show' do
|
12
12
|
it 'should show project information' do
|
13
13
|
stub_request(:get, full_path_with_auth_hash("/projects/#{project_id}", api_key, api_secret))
|
14
|
-
.to_return(body: {})
|
14
|
+
.to_return(body: "{}")
|
15
15
|
response = project.show
|
16
|
-
expect(response).to be_an_instance_of(
|
16
|
+
expect(response).to be_an_instance_of(RestClient::Response)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -40,9 +40,9 @@ describe 'Project::Base' do
|
|
40
40
|
describe 'list_language' do
|
41
41
|
it 'should list languages of project' do
|
42
42
|
stub_request(:get, full_path_with_auth_hash("/projects/#{project_id}/languages", api_key, api_secret))
|
43
|
-
.to_return(body: {})
|
43
|
+
.to_return(body: "{}")
|
44
44
|
response = project.list_language
|
45
|
-
expect(response).to be_an_instance_of(
|
45
|
+
expect(response).to be_an_instance_of(RestClient::Response)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -11,9 +11,9 @@ describe 'Project::File' do
|
|
11
11
|
describe 'list_file' do
|
12
12
|
it 'should list files in project' do
|
13
13
|
stub_request(:get, full_path_with_auth_hash("/projects/#{project_id}/files", api_key, api_secret))
|
14
|
-
.to_return(body: {})
|
14
|
+
.to_return(body: "{}")
|
15
15
|
response = project.list_file
|
16
|
-
expect(response).to be_an_instance_of(
|
16
|
+
expect(response).to be_an_instance_of(RestClient::Response)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -22,9 +22,9 @@ describe 'Project::File' do
|
|
22
22
|
|
23
23
|
it 'should upload file to project' do
|
24
24
|
stub_request(:post, full_path_with_auth_hash("/projects/#{project_id}/files", api_key, api_secret))
|
25
|
-
.to_return(body: {})
|
25
|
+
.to_return(body: "{}")
|
26
26
|
response = project.upload_file(params)
|
27
|
-
expect(response).to be_an_instance_of(
|
27
|
+
expect(response).to be_an_instance_of(RestClient::Response)
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'should raise error when file does not exist' do
|
@@ -38,9 +38,9 @@ describe 'Project::File' do
|
|
38
38
|
|
39
39
|
it 'should delete file from project' do
|
40
40
|
stub_request(:delete, full_path_with_auth_hash("/projects/#{project_id}/files", api_key, api_secret) + params_as_query_string)
|
41
|
-
.to_return(body: {})
|
41
|
+
.to_return(body: "{}")
|
42
42
|
response = project.delete_file(params)
|
43
|
-
expect(response).to be_an_instance_of(
|
43
|
+
expect(response).to be_an_instance_of(RestClient::Response)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -11,9 +11,9 @@ describe 'Project::ImportTask' do
|
|
11
11
|
describe 'list_import_task' do
|
12
12
|
it 'should list import tasks of the project' do
|
13
13
|
stub_request(:get, full_path_with_auth_hash("/projects/#{project_id}/import-tasks", api_key, api_secret))
|
14
|
-
.to_return(body: {})
|
14
|
+
.to_return(body: "{}")
|
15
15
|
response = project.list_import_task
|
16
|
-
expect(response).to be_an_instance_of(
|
16
|
+
expect(response).to be_an_instance_of(RestClient::Response)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -22,9 +22,9 @@ describe 'Project::ImportTask' do
|
|
22
22
|
|
23
23
|
it 'should show an import task details' do
|
24
24
|
stub_request(:get, full_path_with_auth_hash("/projects/#{project_id}/import-tasks/#{import_task_id}", api_key, api_secret))
|
25
|
-
.to_return(body: {})
|
25
|
+
.to_return(body: "{}")
|
26
26
|
response = project.show_import_task(import_task_id)
|
27
|
-
expect(response).to be_an_instance_of(
|
27
|
+
expect(response).to be_an_instance_of(RestClient::Response)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -11,9 +11,9 @@ describe 'Project::Order' do
|
|
11
11
|
describe 'list_order' do
|
12
12
|
it 'should list orders in project' do
|
13
13
|
stub_request(:get, full_path_with_auth_hash("/projects/#{project_id}/orders", api_key, api_secret))
|
14
|
-
.to_return(status: 200, body: {})
|
14
|
+
.to_return(status: 200, body: "{}")
|
15
15
|
response = project.list_order
|
16
|
-
expect(response).to be_an_instance_of(
|
16
|
+
expect(response).to be_an_instance_of(RestClient::Response)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -22,9 +22,9 @@ describe 'Project::Order' do
|
|
22
22
|
|
23
23
|
it 'should show an order details' do
|
24
24
|
stub_request(:get, full_path_with_auth_hash("/projects/#{project_id}/orders/#{order_id}", api_key, api_secret))
|
25
|
-
.to_return(status: 200, body: {})
|
25
|
+
.to_return(status: 200, body: "{}")
|
26
26
|
response = project.show_order(order_id)
|
27
|
-
expect(response).to be_an_instance_of(
|
27
|
+
expect(response).to be_an_instance_of(RestClient::Response)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -36,9 +36,9 @@ describe 'Project::Order' do
|
|
36
36
|
it 'should create an order' do
|
37
37
|
stub_request(:post, full_path_with_auth_hash("/projects/#{project_id}/orders", api_key, api_secret))
|
38
38
|
.with(body: params.to_json, headers: {'Content_Type' => 'application/json'})
|
39
|
-
.to_return(status: 200, body: {})
|
39
|
+
.to_return(status: 200, body: "{}")
|
40
40
|
response = project.create_order(params)
|
41
|
-
expect(response).to be_an_instance_of(
|
41
|
+
expect(response).to be_an_instance_of(RestClient::Response)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -50,9 +50,9 @@ describe 'Project::Translation' do
|
|
50
50
|
|
51
51
|
it 'should show translation status' do
|
52
52
|
stub_request(:get, full_path_with_auth_hash("/projects/#{project_id}/translations/status", api_key, api_secret) + params_as_query_string)
|
53
|
-
.to_return(body: {})
|
53
|
+
.to_return(body: "{}")
|
54
54
|
response = project.get_translation_status(params)
|
55
|
-
expect(response).to be_an_instance_of(
|
55
|
+
expect(response).to be_an_instance_of(RestClient::Response)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -9,9 +9,9 @@ describe 'Project Group' do
|
|
9
9
|
describe 'list_project_group' do
|
10
10
|
it 'should list all available project group' do
|
11
11
|
stub_request(:get, full_path_with_auth_hash('/project-groups', api_key, api_secret))
|
12
|
-
.to_return(body: {})
|
12
|
+
.to_return(body: "{}")
|
13
13
|
response = client.list_project_group
|
14
|
-
expect(response).to be_an_instance_of(
|
14
|
+
expect(response).to be_an_instance_of(RestClient::Response)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -20,9 +20,9 @@ describe 'Project Group' do
|
|
20
20
|
|
21
21
|
it 'should show a project group information' do
|
22
22
|
stub_request(:get, full_path_with_auth_hash("/project-groups/#{project_group_id}", api_key, api_secret))
|
23
|
-
.to_return(body: {})
|
23
|
+
.to_return(body: "{}")
|
24
24
|
response = client.show_project_group(project_group_id)
|
25
|
-
expect(response).to be_an_instance_of(
|
25
|
+
expect(response).to be_an_instance_of(RestClient::Response)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -32,9 +32,9 @@ describe 'Project Group' do
|
|
32
32
|
it 'should create a project group' do
|
33
33
|
stub_request(:post, full_path_with_auth_hash('/project-groups', api_key, api_secret))
|
34
34
|
.with(body: params.to_json, headers: {'Content_Type' => 'application/json'})
|
35
|
-
.to_return(body: {})
|
35
|
+
.to_return(body: "{}")
|
36
36
|
response = client.create_project_group(params)
|
37
|
-
expect(response).to be_an_instance_of(
|
37
|
+
expect(response).to be_an_instance_of(RestClient::Response)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -43,9 +43,9 @@ describe 'Project Group' do
|
|
43
43
|
|
44
44
|
it 'should delete a project group' do
|
45
45
|
stub_request(:delete, full_path_with_auth_hash("/project-groups/#{project_group_id}", api_key, api_secret))
|
46
|
-
.to_return(body: {})
|
46
|
+
.to_return(body: "{}")
|
47
47
|
response = client.delete_project_group(project_group_id)
|
48
|
-
expect(response).to be_an_instance_of(
|
48
|
+
expect(response).to be_an_instance_of(RestClient::Response)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -54,9 +54,9 @@ describe 'Project Group' do
|
|
54
54
|
|
55
55
|
it 'should list languages activated of a project group' do
|
56
56
|
stub_request(:get, full_path_with_auth_hash("/project-groups/#{project_group_id}/languages", api_key, api_secret))
|
57
|
-
.to_return(body: {})
|
57
|
+
.to_return(body: "{}")
|
58
58
|
response = client.list_project_group_languages(project_group_id)
|
59
|
-
expect(response).to be_an_instance_of(
|
59
|
+
expect(response).to be_an_instance_of(RestClient::Response)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
@@ -11,9 +11,9 @@ describe 'Project' do
|
|
11
11
|
|
12
12
|
it 'should list all projects of a project group' do
|
13
13
|
stub_request(:get, full_path_with_auth_hash("/project-groups/#{project_group_id}/projects", api_key, api_secret))
|
14
|
-
.to_return(body: {})
|
14
|
+
.to_return(body: "{}")
|
15
15
|
response = client.list_project(project_group_id)
|
16
|
-
expect(response).to be_an_instance_of(
|
16
|
+
expect(response).to be_an_instance_of(RestClient::Response)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -24,9 +24,9 @@ describe 'Project' do
|
|
24
24
|
it 'should list all projects of a project group' do
|
25
25
|
stub_request(:post, full_path_with_auth_hash("/project-groups/#{project_group_id}/projects", api_key, api_secret))
|
26
26
|
.with(body: params.to_json, headers: {'Content_Type' => 'application/json'})
|
27
|
-
.to_return(body: {})
|
27
|
+
.to_return(body: "{}")
|
28
28
|
response = client.create_project(project_group_id, params)
|
29
|
-
expect(response).to be_an_instance_of(
|
29
|
+
expect(response).to be_an_instance_of(RestClient::Response)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -9,9 +9,9 @@ describe 'Project Type' do
|
|
9
9
|
describe 'list_project_type' do
|
10
10
|
it 'should list all available project type' do
|
11
11
|
stub_request(:get, full_path_with_auth_hash('/project-types', api_key, api_secret))
|
12
|
-
.to_return(body: {})
|
12
|
+
.to_return(body: "{}")
|
13
13
|
response = client.list_project_type
|
14
|
-
expect(response).to be_an_instance_of(
|
14
|
+
expect(response).to be_an_instance_of(RestClient::Response)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onesky-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Lam
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: '3.0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: '3.0'
|
83
83
|
description: Ruby wrapper for OneSky API
|
84
84
|
email:
|
85
85
|
- victorebox@yahoo.com.hk
|
@@ -110,7 +110,6 @@ files:
|
|
110
110
|
- lib/onesky/resources/project/translation.rb
|
111
111
|
- lib/onesky/resources/project_group.rb
|
112
112
|
- lib/onesky/resources/project_type.rb
|
113
|
-
- lib/onesky/restclient.rb
|
114
113
|
- lib/onesky/version.rb
|
115
114
|
- onesky-ruby.gemspec
|
116
115
|
- spec/fixture/en.yml
|
@@ -139,7 +138,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
139
138
|
requirements:
|
140
139
|
- - ">="
|
141
140
|
- !ruby/object:Gem::Version
|
142
|
-
version:
|
141
|
+
version: 2.0.0
|
143
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
143
|
requirements:
|
145
144
|
- - ">="
|
@@ -147,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
146
|
version: '0'
|
148
147
|
requirements: []
|
149
148
|
rubyforge_project:
|
150
|
-
rubygems_version: 2.
|
149
|
+
rubygems_version: 2.6.14
|
151
150
|
signing_key:
|
152
151
|
specification_version: 4
|
153
152
|
summary: To interact with OneSky Platform API
|
data/lib/onesky/restclient.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
# Monkey patching RestClient::Request.process_url_params
|
2
|
-
# To support array in URL params
|
3
|
-
# RestClient.get('http://www.example.com', params: {weekday: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri']})
|
4
|
-
# => GET http://www.example.com?weekday[]=Mon&weekday[]=Tue&weekday[]=Wed&weekday[]=Thu&weekday[]=Fri
|
5
|
-
|
6
|
-
module RestClient
|
7
|
-
class Request
|
8
|
-
|
9
|
-
def process_url_params url, headers
|
10
|
-
url_params = {}
|
11
|
-
headers.delete_if do |key, value|
|
12
|
-
if 'params' == key.to_s.downcase && value.is_a?(Hash)
|
13
|
-
url_params.merge! value
|
14
|
-
true
|
15
|
-
else
|
16
|
-
false
|
17
|
-
end
|
18
|
-
end
|
19
|
-
unless url_params.empty?
|
20
|
-
query_string = url_params.collect { |k, v| build_url_params(k, v) }.join('&')
|
21
|
-
url + "?#{query_string}"
|
22
|
-
else
|
23
|
-
url
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def build_url_params key, value
|
30
|
-
if value.is_a?(Array)
|
31
|
-
value.map { |v| "#{key.to_s}[]=#{CGI::escape(v.to_s)}" }.join('&')
|
32
|
-
else
|
33
|
-
"#{key.to_s}=#{CGI::escape(value.to_s)}"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|