crowdin-api 1.13.0 → 1.14.0
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/Gemfile.lock +1 -1
- data/README.md +23 -1
- data/lib/crowdin-api/api_resources/applications.rb +5 -5
- data/lib/crowdin-api/client/client.rb +3 -8
- data/lib/crowdin-api/client/version.rb +1 -1
- data/lib/crowdin-api/core/graphql_extensions.rb +22 -0
- data/lib/crowdin-api.rb +1 -0
- data/spec/unit/client_spec.rb +47 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 98a60b3487c1824a37ef3519089f1e48e7de773f35734a54a981365707bbd80a
|
|
4
|
+
data.tar.gz: 0e5642b1b3446d55602f34ec4820b82e5d686e4002df0158371031141480bde1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a6ee9691d7ce60578c6438bf58874262edaa4dc8100723a2c9ad56b70828c97367a332401a47b9f098408d48dec4324714d83e5a1f73f3a2d683c829f3dc792f
|
|
7
|
+
data.tar.gz: cc3e2fbdc50836e014496c9990be79492817c878a8758b35044e5cecedf670eeed33390fb42ab1d32e5d52b9873344ee88a3fc11942e4a7513a1e3adf66269d5
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -35,7 +35,7 @@ Crowdin API is a full-featured RESTful API that helps you to integrate localizat
|
|
|
35
35
|
Add this line to your application's Gemfile:
|
|
36
36
|
|
|
37
37
|
```gemfile
|
|
38
|
-
gem 'crowdin-api', '~> 1.
|
|
38
|
+
gem 'crowdin-api', '~> 1.14.0'
|
|
39
39
|
```
|
|
40
40
|
|
|
41
41
|
And then execute:
|
|
@@ -134,6 +134,28 @@ file_revisions = crowdin.list_file_revisions(your_file_id, { limit: 10 }, your_p
|
|
|
134
134
|
# Note: more examples you can find in spec folder
|
|
135
135
|
```
|
|
136
136
|
|
|
137
|
+
### GraphQL API
|
|
138
|
+
|
|
139
|
+
The client can send GraphQL requests to Crowdin's default API host or to an Enterprise organization endpoint.
|
|
140
|
+
|
|
141
|
+
```ruby
|
|
142
|
+
query = <<~GRAPHQL
|
|
143
|
+
query Viewer {
|
|
144
|
+
viewer {
|
|
145
|
+
id
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
GRAPHQL
|
|
149
|
+
|
|
150
|
+
response = crowdin.graphql({ query: query })
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
You can also provide a custom endpoint URL for testing.
|
|
154
|
+
|
|
155
|
+
```ruby
|
|
156
|
+
crowdin.graphql({ query: query }, url: 'http://localhost:3000/api/graphql')
|
|
157
|
+
```
|
|
158
|
+
|
|
137
159
|
### Fetch all records
|
|
138
160
|
|
|
139
161
|
There is a possibility to fetch all records from paginatable methods using `fetch_all` method.
|
|
@@ -7,7 +7,7 @@ module Crowdin
|
|
|
7
7
|
# * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.applications.api.get API Documentation}
|
|
8
8
|
def get_application_data(application_identifier = nil, path = nil)
|
|
9
9
|
application_identifier || raise_parameter_is_required_error(:application_identifier)
|
|
10
|
-
|
|
10
|
+
path || raise_parameter_is_required_error(:path)
|
|
11
11
|
|
|
12
12
|
request = Web::Request.new(
|
|
13
13
|
connection,
|
|
@@ -21,7 +21,7 @@ module Crowdin
|
|
|
21
21
|
# * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.applications.api.put API Documentation}
|
|
22
22
|
def update_or_restore_application_data(query = {}, application_identifier = nil, path = nil)
|
|
23
23
|
application_identifier || raise_parameter_is_required_error(:application_identifier)
|
|
24
|
-
|
|
24
|
+
path || raise_parameter_is_required_error(:path)
|
|
25
25
|
|
|
26
26
|
request = Web::Request.new(
|
|
27
27
|
connection,
|
|
@@ -36,7 +36,7 @@ module Crowdin
|
|
|
36
36
|
# * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.applications.api.put API Documentation}
|
|
37
37
|
def add_application_data(query = {}, application_identifier = nil, path = nil)
|
|
38
38
|
application_identifier || raise_parameter_is_required_error(:application_identifier)
|
|
39
|
-
|
|
39
|
+
path || raise_parameter_is_required_error(:path)
|
|
40
40
|
|
|
41
41
|
request = Web::Request.new(
|
|
42
42
|
connection,
|
|
@@ -51,7 +51,7 @@ module Crowdin
|
|
|
51
51
|
# * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.applications.api.delete API Documentation}
|
|
52
52
|
def delete_application_data(query = {}, application_identifier = nil, path = nil)
|
|
53
53
|
application_identifier || raise_parameter_is_required_error(:application_identifier)
|
|
54
|
-
|
|
54
|
+
path || raise_parameter_is_required_error(:path)
|
|
55
55
|
|
|
56
56
|
request = Web::Request.new(
|
|
57
57
|
connection,
|
|
@@ -66,7 +66,7 @@ module Crowdin
|
|
|
66
66
|
# * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.applications.api.patch API Documentation}
|
|
67
67
|
def edit_application_data(query = {}, application_identifier = nil, path = nil)
|
|
68
68
|
application_identifier || raise_parameter_is_required_error(:application_identifier)
|
|
69
|
-
|
|
69
|
+
path || raise_parameter_is_required_error(:path)
|
|
70
70
|
|
|
71
71
|
request = Web::Request.new(
|
|
72
72
|
connection,
|
|
@@ -31,15 +31,10 @@ module Crowdin
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
include Web::FetchAllExtensions
|
|
34
|
+
include Web::GraphqlExtensions
|
|
34
35
|
|
|
35
|
-
#
|
|
36
|
-
attr_reader :config
|
|
37
|
-
# Instance with established connection through RestClient to the Crowdin API
|
|
38
|
-
attr_reader :connection
|
|
39
|
-
# Instance with options and headers for RestClient connection
|
|
40
|
-
attr_reader :options
|
|
41
|
-
# Logger instance
|
|
42
|
-
attr_reader :logger
|
|
36
|
+
# Client configuration, connection, request options, and logger instances
|
|
37
|
+
attr_reader :config, :connection, :options, :logger
|
|
43
38
|
|
|
44
39
|
def initialize(&block)
|
|
45
40
|
build_configuration(&block)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Crowdin
|
|
4
|
+
module Web
|
|
5
|
+
module GraphqlExtensions
|
|
6
|
+
def graphql(query = nil, **request_options)
|
|
7
|
+
url = request_options.delete(:url)
|
|
8
|
+
graphql_query = query || request_options
|
|
9
|
+
|
|
10
|
+
response = ::RestClient::Request.execute(
|
|
11
|
+
{
|
|
12
|
+
method: :post,
|
|
13
|
+
url: url || "#{config.base_url}/api/graphql",
|
|
14
|
+
payload: graphql_query.to_json
|
|
15
|
+
}.merge(options)
|
|
16
|
+
) { |res, _, _| res }
|
|
17
|
+
|
|
18
|
+
response.body.empty? ? response.code : JSON.parse(response.body)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
data/lib/crowdin-api.rb
CHANGED
|
@@ -23,6 +23,7 @@ require 'crowdin-api/core/errors_raisers'
|
|
|
23
23
|
require 'crowdin-api/core/request'
|
|
24
24
|
require 'crowdin-api/core/send_request'
|
|
25
25
|
require 'crowdin-api/core/fetch_all_extensions'
|
|
26
|
+
require 'crowdin-api/core/graphql_extensions'
|
|
26
27
|
|
|
27
28
|
# API modules
|
|
28
29
|
Crowdin::API_RESOURCES_MODULES.each do |api_resource|
|
data/spec/unit/client_spec.rb
CHANGED
|
@@ -98,6 +98,53 @@ describe 'Crowdin Client' do
|
|
|
98
98
|
end
|
|
99
99
|
end
|
|
100
100
|
|
|
101
|
+
describe 'Crowdin Client graphql' do
|
|
102
|
+
let(:graphql_request) do
|
|
103
|
+
{
|
|
104
|
+
query: 'query Viewer { viewer { id } }',
|
|
105
|
+
operationName: 'Viewer',
|
|
106
|
+
variables: { projectId: 1, emptyValue: nil }
|
|
107
|
+
}
|
|
108
|
+
end
|
|
109
|
+
let(:graphql_response) { { 'data' => { 'viewer' => { 'id' => 1 } } } }
|
|
110
|
+
|
|
111
|
+
it 'posts to the default GraphQL endpoint', :default do
|
|
112
|
+
stub_request(:post, 'https://api.crowdin.com/api/graphql')
|
|
113
|
+
.with(body: graphql_request.to_json)
|
|
114
|
+
.to_return(body: graphql_response.to_json)
|
|
115
|
+
|
|
116
|
+
expect(@crowdin.graphql(graphql_request)).to eq(graphql_response)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
it 'posts to the Enterprise GraphQL endpoint', :enterprise do
|
|
120
|
+
stub_request(:post, 'https://domain.api.crowdin.com/api/graphql')
|
|
121
|
+
.with(body: graphql_request.to_json)
|
|
122
|
+
.to_return(body: graphql_response.to_json)
|
|
123
|
+
|
|
124
|
+
expect(@crowdin.graphql(graphql_request)).to eq(graphql_response)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
it 'supports a custom GraphQL endpoint URL', :default do
|
|
128
|
+
custom_url = 'http://localhost:3000/api/graphql'
|
|
129
|
+
|
|
130
|
+
stub_request(:post, custom_url)
|
|
131
|
+
.with(body: graphql_request.to_json)
|
|
132
|
+
.to_return(body: graphql_response.to_json)
|
|
133
|
+
|
|
134
|
+
expect(@crowdin.graphql(graphql_request, url: custom_url)).to eq(graphql_response)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it 'returns parsed GraphQL error responses', :default do
|
|
138
|
+
graphql_error_response = { 'errors' => [{ 'message' => 'Invalid query' }] }
|
|
139
|
+
|
|
140
|
+
stub_request(:post, 'https://api.crowdin.com/api/graphql')
|
|
141
|
+
.with(body: graphql_request.to_json)
|
|
142
|
+
.to_return(status: 400, body: graphql_error_response.to_json)
|
|
143
|
+
|
|
144
|
+
expect(@crowdin.graphql(graphql_request)).to eq(graphql_error_response)
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
101
148
|
describe 'connection' do
|
|
102
149
|
subject(:connection) { crowdin_client.connection }
|
|
103
150
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: crowdin-api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.14.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Crowdin
|
|
@@ -237,6 +237,7 @@ files:
|
|
|
237
237
|
- lib/crowdin-api/core/errors.rb
|
|
238
238
|
- lib/crowdin-api/core/errors_raisers.rb
|
|
239
239
|
- lib/crowdin-api/core/fetch_all_extensions.rb
|
|
240
|
+
- lib/crowdin-api/core/graphql_extensions.rb
|
|
240
241
|
- lib/crowdin-api/core/request.rb
|
|
241
242
|
- lib/crowdin-api/core/send_request.rb
|
|
242
243
|
- spec/api_resources/applications_spec.rb
|